Changeset 447
- Timestamp:
- May 19, 2022, 10:39:34 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 82 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 -
trunk/AI/StdAI/Barbarina.pas
r442 r447 25 25 type 26 26 TColonyShipPlan = array[0..nShipPart - 1] of record 27 cixProducing: integer;28 LocResource: array[0..maxModern - 1] of integer;29 nLocResource: integer;30 LocFoundCity: array[0..maxModern - 1] of integer;31 nLocFoundCity: integer;27 cixProducing: Integer; 28 LocResource: array[0..maxModern - 1] of Integer; 29 nLocResource: Integer; 30 LocFoundCity: array[0..maxModern - 1] of Integer; 31 nLocFoundCity: Integer; 32 32 end; 33 33 34 34 TBarbarina = class(TToolAI) 35 constructor Create(Nation: integer); override;35 constructor Create(Nation: Integer); override; 36 36 37 37 protected 38 38 ColonyShipPlan: TColonyShipPlan; 39 function Barbarina_GoHidden: boolean; // whether we should prepare for barbarina mode40 function Barbarina_Go: boolean; // whether we should switch to barbarina mode now39 function Barbarina_GoHidden: Boolean; // whether we should prepare for barbarina mode 40 function Barbarina_Go: Boolean; // whether we should switch to barbarina mode now 41 41 procedure Barbarina_DoTurn; 42 42 procedure Barbarina_SetCityProduction; 43 function Barbarina_ChooseResearchAdvance: integer;44 function Barbarina_WantCheckNegotiation(Nation: integer): boolean;43 function Barbarina_ChooseResearchAdvance: Integer; 44 function Barbarina_WantCheckNegotiation(Nation: Integer): Boolean; 45 45 procedure Barbarina_DoCheckNegotiation; 46 function Barbarina_WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;46 function Barbarina_WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 47 47 procedure Barbarina_DoNegotiation; 48 48 procedure MakeColonyShipPlan; 49 49 50 50 private 51 TurnOfMapAnalysis, Neighbours: integer;52 ContinentPresence: array[0..maxCOD - 1] of integer;53 OceanPresence: array[0..maxCOD - 1] of integer;54 ContinentSize: array[0..maxCOD - 1] of integer;55 OceanSize: array[0..maxCOD - 1] of integer;56 mixBest: array[0..nModelCategory - 1] of integer;51 TurnOfMapAnalysis, Neighbours: Integer; 52 ContinentPresence: array[0..maxCOD - 1] of Integer; 53 OceanPresence: array[0..maxCOD - 1] of Integer; 54 ContinentSize: array[0..maxCOD - 1] of Integer; 55 OceanSize: array[0..maxCOD - 1] of Integer; 56 mixBest: array[0..nModelCategory - 1] of Integer; 57 57 NegoCause: (CancelTreaty); 58 function IsModelAvailable(rmix: integer): boolean;58 function IsModelAvailable(rmix: Integer): Boolean; 59 59 procedure FindBestModels; 60 60 procedure AnalyzeMap; 61 procedure RateAttack(uix: integer);62 function DoAttack(uix, AttackLoc: integer): boolean;63 function ProcessMove(uix: integer): boolean;61 procedure RateAttack(uix: Integer); 62 function DoAttack(uix, AttackLoc: Integer): Boolean; 63 function ProcessMove(uix: Integer): Boolean; 64 64 procedure AttackAndPatrol; 65 65 end; … … 73 73 type 74 74 TResearchModel = record 75 Category, Domain, Weight, adStop, FutMStrength: integer;76 Upgrades: cardinal;77 Cap: array [0..nFeature - 1] of integer;75 Category, Domain, Weight, adStop, FutMStrength: Integer; 76 Upgrades: Cardinal; 77 Cap: array [0..nFeature - 1] of Integer; 78 78 end; 79 79 … … 93 93 94 94 nResearchOrder = 40; 95 ResearchOrder: array[0..nResearchOrder - 1] of integer =95 ResearchOrder: array[0..nResearchOrder - 1] of Integer = 96 96 (adBronzeWorking, -adMapMaking, adChivalry, adMonotheism, adIronWorking, 97 97 adGunPowder, adTheology, adConstruction, adCodeOfLaws, -adEngineering, … … 171 171 172 172 var 173 Moved: array[0..numax - 1] of boolean;174 UnitPresence: array[0..lxmax * lymax - 1] of byte;173 Moved: array[0..numax - 1] of Boolean; 174 UnitPresence: array[0..lxmax * lymax - 1] of Byte; 175 175 euixMap: array[0..lxmax * lymax - 1] of smallint; 176 176 uixAttack: array[0..neumax - 1] of smallint; 177 AttackScore: array[0..neumax - 1] of integer;178 179 constructor TBarbarina.Create(Nation: integer);177 AttackScore: array[0..neumax - 1] of Integer; 178 179 constructor TBarbarina.Create(Nation: Integer); 180 180 begin 181 181 inherited; … … 184 184 185 185 // whether one of the existing models matches a specific research model 186 function TBarbarina.IsModelAvailable(rmix: integer): boolean;186 function TBarbarina.IsModelAvailable(rmix: Integer): Boolean; 187 187 var 188 i, mix, MStrength: integer;188 I, mix, MStrength: Integer; 189 189 begin 190 190 Result := False; … … 199 199 Result := MStrength < (MyModel[mix].MStrength * 3) div 2; 200 200 // for future techs: don't count model available if 50% stronger possible 201 for i:= 0 to nFeature - 1 do202 if MyModel[mix].Cap[ i] < Cap[i] then201 for I := 0 to nFeature - 1 do 202 if MyModel[mix].Cap[I] < Cap[I] then 203 203 begin 204 204 Result := False; 205 break;205 Break; 206 206 end; 207 207 if Result then 208 break;208 Break; 209 209 end; 210 210 end; 211 211 end; 212 212 213 function TBarbarina.Barbarina_GoHidden: boolean;213 function TBarbarina.Barbarina_GoHidden: Boolean; 214 214 var 215 V21, Loc1, cix: integer;215 V21, Loc1, cix: Integer; 216 216 Radius: TVicinity21Loc; 217 217 begin … … 238 238 end; 239 239 240 function TBarbarina.Barbarina_Go: boolean;240 function TBarbarina.Barbarina_Go: Boolean; 241 241 begin 242 242 if IsResearched(adMassProduction) then … … 249 249 Result := (RO.nCity >= 3) and IsResearched(adMapMaking) and 250 250 IsModelAvailable(EntryModel_Base); 251 exit;251 Exit; 252 252 end; 253 253 Result := Result and ((RO.nUn >= RO.nCity * 3) or 254 (RO.Wonder[woZeus].EffectiveOwner = me));254 (RO.Wonder[woZeus].EffectiveOwner = Me)); 255 255 end; 256 256 257 257 procedure TBarbarina.AnalyzeMap; 258 258 var 259 Loc, Loc1, V8, f1, p1, cix: integer;259 Loc, Loc1, V8, f1, p1, cix: Integer; 260 260 Adjacent: TVicinity8Loc; 261 261 begin 262 262 if TurnOfMapAnalysis = RO.Turn then 263 exit;263 Exit; 264 264 265 265 // inherited; 266 266 267 267 // collect nation presence information for continents and oceans 268 fillchar(ContinentPresence, sizeof(ContinentPresence), 0);269 fillchar(OceanPresence, sizeof(OceanPresence), 0);270 fillchar(ContinentSize, sizeof(ContinentSize), 0);271 fillchar(OceanSize, sizeof(OceanSize), 0);268 FillChar(ContinentPresence, SizeOf(ContinentPresence), 0); 269 FillChar(OceanPresence, SizeOf(OceanPresence), 0); 270 FillChar(ContinentSize, SizeOf(ContinentSize), 0); 271 FillChar(OceanSize, SizeOf(OceanSize), 0); 272 272 for Loc := 0 to MapSize - 1 do 273 273 begin … … 339 339 procedure TBarbarina.FindBestModels; 340 340 var 341 i, mix, rmix, cat: integer;341 I, mix, rmix, cat: Integer; 342 342 begin 343 for i:= 0 to nModelCategory - 1 do344 mixBest[ i] := -1;343 for I := 0 to nModelCategory - 1 do 344 mixBest[I] := -1; 345 345 for rmix := nResearchModel - 1 downto 0 do 346 346 with ResearchModel[rmix] do … … 351 351 begin 352 352 mixBest[Category] := mix; 353 for i:= 0 to nFeature - 1 do354 if MyModel[mix].Cap[ i] < Cap[i] then353 for I := 0 to nFeature - 1 do 354 if MyModel[mix].Cap[I] < Cap[I] then 355 355 begin 356 356 mixBest[Category] := -1; 357 break;357 Break; 358 358 end; 359 359 if mixBest[Category] >= 0 then 360 break;360 Break; 361 361 end; 362 362 for mix := 3 to RO.nModel - 1 do … … 387 387 begin 388 388 mixBest[ctSeaTrans] := mix; 389 break;389 Break; 390 390 end; 391 391 end; … … 406 406 407 407 // find one unit to destroy each known enemy unit, result in uixAttack 408 procedure TBarbarina.RateAttack(uix: integer);408 procedure TBarbarina.RateAttack(uix: Integer); 409 409 var 410 410 MoveStyle, TestLoc, TestTime, NextLoc, NextTime, V8, RemHealth, 411 RecoverTurns, Score, BestScore, euixBest, uixOld: integer;412 NextTile: cardinal;411 RecoverTurns, Score, BestScore, euixBest, uixOld: Integer; 412 NextTile: Cardinal; 413 413 Adjacent: TVicinity8Loc; 414 414 Defense: ^TUnitInfo; 415 Reached: array[0..lxmax * lymax - 1] of boolean;415 Reached: array[0..lxmax * lymax - 1] of Boolean; 416 416 begin 417 417 with MyUnit[uix] do … … 419 419 begin 420 420 BestScore := 0; 421 fillchar(Reached, MapSize, False);421 FillChar(Reached, MapSize, False); 422 422 MoveStyle := GetMyMoveStyle(mix, Health); 423 423 Pile.Create(MapSize); … … 494 494 end; 495 495 496 function TBarbarina.DoAttack(uix, AttackLoc: integer): boolean;496 function TBarbarina.DoAttack(uix, AttackLoc: Integer): Boolean; 497 497 // AttackLoc=maNextCity means bombard only 498 498 var 499 499 MoveResult, Kind, Temp, MoveStyle, TestLoc, TestTime, NextLoc, 500 NextTime, V8, RecoverTurns, ecix: integer;501 NextTile: cardinal;502 AttackPositionReached, IsBombardment: boolean;500 NextTime, V8, RecoverTurns, ecix: Integer; 501 NextTile: Cardinal; 502 AttackPositionReached, IsBombardment: Boolean; 503 503 Adjacent: TVicinity8Loc; 504 PreLoc: array[0..lxmax * lymax - 1] of word;505 Reached: array[0..lxmax * lymax - 1] of boolean;504 PreLoc: array[0..lxmax * lymax - 1] of Word; 505 Reached: array[0..lxmax * lymax - 1] of Boolean; 506 506 begin 507 507 Result := False; … … 516 516 else 517 517 Kind := 0; 518 fillchar(Reached, MapSize, False);518 FillChar(Reached, MapSize, False); 519 519 AttackPositionReached := False; 520 520 MoveStyle := GetMyMoveStyle(mix, Health); … … 524 524 begin 525 525 if (TestTime >= $800) or (AttackLoc = maNextCity) and (TestTime > $800 - 100) then 526 break;526 Break; 527 527 Reached[TestLoc] := True; 528 528 V8_to_Loc(TestLoc, Adjacent); … … 537 537 begin 538 538 City_FindEnemyCity(NextLoc, ecix); 539 assert(ecix >= 0);539 Assert(ecix >= 0); 540 540 with RO.EnemyCity[ecix] do 541 541 if (Size > 2) and (Flags and ciCoastalFort = 0) then … … 547 547 begin 548 548 AttackPositionReached := True; 549 break;549 Break; 550 550 end 551 551 else if not Reached[NextLoc] then … … 572 572 begin 573 573 PreLoc[NextLoc] := TestLoc; 574 break;574 Break; 575 575 end; 576 576 end; 577 577 Pile.Free; 578 578 if not AttackPositionReached then 579 exit;579 Exit; 580 580 581 581 TestLoc := AttackLoc; … … 601 601 begin 602 602 City_FindEnemyCity(AttackLoc, ecix); 603 assert(ecix >= 0);603 Assert(ecix >= 0); 604 604 while (Movement >= 100) and (RO.EnemyCity[ecix].Size > 2) do 605 605 Unit_Step(uix, AttackLoc); … … 611 611 end; 612 612 613 function TBarbarina.ProcessMove(uix: integer): boolean;613 function TBarbarina.ProcessMove(uix: Integer): Boolean; 614 614 // return true if no new enemy spotted 615 615 const … … 618 618 PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8, 619 619 TestScore, MoveResult, MoveStyle, NextTime, TerrOwner, Kind, Temp, 620 RecoverTurns, MaxScore: integer;621 Tile, NextTile: cardinal;622 CaptureOnly, PeaceBorder, done, NextToEnemyCity: boolean;620 RecoverTurns, MaxScore: Integer; 621 Tile, NextTile: Cardinal; 622 CaptureOnly, PeaceBorder, done, NextToEnemyCity: Boolean; 623 623 Adjacent: TVicinity8Loc; 624 AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;625 PreLoc: array[0..lxmax * lymax - 1] of word;626 MoreTurn: array[0..lxmax * lymax - 1] of byte;624 AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt; 625 PreLoc: array[0..lxmax * lymax - 1] of Word; 626 MoreTurn: array[0..lxmax * lymax - 1] of Byte; 627 627 628 628 begin … … 637 637 if Map[Loc] and fCity = 0 then 638 638 Unit_MoveEx(uix, maNextCity); 639 exit;639 Exit; 640 640 end; 641 641 … … 666 666 // assume a score of $400 is the best achievable 667 667 or CaptureOnly and (TestTime >= $1000) then 668 break;668 Break; 669 669 670 670 TestScore := 0; 671 671 Tile := Map[TestLoc]; 672 assert(Tile and (fUnit or fOwned) <> fUnit);672 Assert(Tile and (fUnit or fOwned) <> fUnit); 673 673 TerrOwner := RO.Territory[TestLoc]; 674 674 AdjacentUnknown[TestLoc] := 0; … … 743 743 TestScore := $400 - 14 744 744 else if AdjacentUnknown[TestLoc] > 0 then 745 if PeaceBorder or (TerrOwner >= 0) and (TerrOwner <> me) and745 if PeaceBorder or (TerrOwner >= 0) and (TerrOwner <> Me) and 746 746 (RO.Treaty[TerrOwner] < trPeace) then 747 747 TestScore := $400 - 32 + AdjacentUnknown[TestLoc] … … 790 790 end; 791 791 if PatrolLoc = Loc then 792 exit;792 Exit; 793 793 TestLoc := PatrolLoc; 794 794 NextLoc := PreLoc[TestLoc]; … … 814 814 Result := MoveResult and rEnemySpotted = 0; 815 815 done := True; 816 break;817 end; 818 assert(Loc = NextLoc);816 Break; 817 end; 818 Assert(Loc = NextLoc); 819 819 end; 820 820 if Loc >= 0 then … … 839 839 procedure SetCityDefenders; 840 840 var 841 uix, cix, V8, Loc1, Best, uixBest, det: integer;841 uix, cix, V8, Loc1, Best, uixBest, det: Integer; 842 842 Adjacent: TVicinity8Loc; 843 IsPort: boolean;843 IsPort: Boolean; 844 844 begin 845 845 for cix := 0 to RO.nCity - 1 do … … 887 887 procedure ProcessSeaTransport; 888 888 var 889 i, f, uix, Loc1, a, b: integer;890 ready, go: boolean;889 I, F, uix, Loc1, A, B: Integer; 890 ready, go: Boolean; 891 891 TransportPlan: TGroupTransportPlan; 892 892 begin 893 893 go := False; 894 for f:= 0 to maxCOD - 1 do895 if ( f < nContinent) and (ContinentPresence[f] and not896 (1 shl me or PresenceUnknown) <> 0) then894 for F := 0 to maxCOD - 1 do 895 if (F < nContinent) and (ContinentPresence[F] and not 896 (1 shl Me or PresenceUnknown) <> 0) then 897 897 go := True; // any enemy island known? 898 898 if not go then 899 exit;899 Exit; 900 900 901 901 SeaTransport_BeginInitialize; … … 907 907 (MyModel[mix].Attack > 0) and (Map[Loc] and fTerrain >= fGrass) then 908 908 begin 909 f:= Formation[Loc];910 if ( f >= 0) and (f < maxCOD) and (ContinentPresence[f] and911 not (1 shl me) = 0) then909 F := Formation[Loc]; 910 if (F >= 0) and (F < maxCOD) and (ContinentPresence[F] and 911 not (1 shl Me) = 0) then 912 912 begin 913 913 go := True; … … 932 932 if Map[Loc1] and fTerrain >= fGrass then 933 933 begin 934 f:= Formation[Loc1];935 if ( f >= 0) and (f < maxCOD) and (ContinentPresence[f] and936 not (1 shl me or PresenceUnknown) <> 0) then934 F := Formation[Loc1]; 935 if (F >= 0) and (F < maxCOD) and (ContinentPresence[F] and 936 not (1 shl Me or PresenceUnknown) <> 0) then 937 937 SeaTransport_AddDestination(Loc1); 938 938 end; … … 948 948 end; 949 949 if ready then 950 for i:= 0 to TransportPlan.nLoad - 1 do950 for I := 0 to TransportPlan.nLoad - 1 do 951 951 begin 952 952 Loc_to_ab(TransportPlan.LoadLoc, 953 MyUnit[TransportPlan.uixLoad[ i]].Loc, a, b);954 ready := ready and (abs( a) <= 1) and (abs(b) <= 1);953 MyUnit[TransportPlan.uixLoad[I]].Loc, A, B); 954 ready := ready and (abs(A) <= 1) and (abs(B) <= 1); 955 955 end; 956 956 if ready then 957 957 begin 958 for i:= 0 to TransportPlan.nLoad - 1 do959 begin 960 Unit_Step(TransportPlan.uixLoad[ i], TransportPlan.LoadLoc);961 Moved[TransportPlan.uixLoad[ i]] := True;958 for I := 0 to TransportPlan.nLoad - 1 do 959 begin 960 Unit_Step(TransportPlan.uixLoad[I], TransportPlan.LoadLoc); 961 Moved[TransportPlan.uixLoad[I]] := True; 962 962 end; 963 963 end 964 964 else 965 965 begin 966 for i:= 0 to TransportPlan.nLoad - 1 do967 begin 968 Unit_MoveEx(TransportPlan.uixLoad[ i], TransportPlan.LoadLoc, mxAdjacent);969 Moved[TransportPlan.uixLoad[ i]] := True;966 for I := 0 to TransportPlan.nLoad - 1 do 967 begin 968 Unit_MoveEx(TransportPlan.uixLoad[I], TransportPlan.LoadLoc, mxAdjacent); 969 Moved[TransportPlan.uixLoad[I]] := True; 970 970 end; 971 971 end; … … 973 973 end; 974 974 975 procedure ProcessUnload(uix: integer);976 977 procedure Unload(Kind, ToLoc: integer);975 procedure ProcessUnload(uix: Integer); 976 977 procedure Unload(Kind, ToLoc: Integer); 978 978 var 979 uix1: integer;979 uix1: Integer; 980 980 begin 981 981 for uix1 := 0 to RO.nUn - 1 do … … 987 987 Unit_Step(uix1, ToLoc); 988 988 UnitPresence[ToLoc] := UnitPresence[ToLoc] or Kind; 989 break;989 Break; 990 990 end; 991 991 end; … … 993 993 var 994 994 uix1, MoveStyle, TestLoc, TestTime, NextLoc, NextTime, V8, 995 RecoverTurns, nSlow, nFast, SlowUnloadLoc, FastUnloadLoc, EndLoc, f: integer;996 NextTile: cardinal;995 RecoverTurns, nSlow, nFast, SlowUnloadLoc, FastUnloadLoc, EndLoc, F: Integer; 996 NextTile: Cardinal; 997 997 Adjacent: TVicinity8Loc; 998 Reached: array[0..lxmax * lymax - 1] of boolean;998 Reached: array[0..lxmax * lymax - 1] of Boolean; 999 999 begin 1000 1000 // inventory … … 1017 1017 FastUnloadLoc := -1; 1018 1018 EndLoc := -1; 1019 fillchar(Reached, MapSize, False);1019 FillChar(Reached, MapSize, False); 1020 1020 Pile.Create(MapSize); 1021 1021 Pile.Put(Loc, $800 - Movement); … … 1034 1034 else if NextTile and fTerrain >= fGrass then 1035 1035 begin 1036 f:= Formation[NextLoc];1037 if ( f >= 0) and (f< maxCOD) and1038 (ContinentPresence[ f] and not (1 shl me or PresenceUnknown) <> 0) and1036 F := Formation[NextLoc]; 1037 if (F >= 0) and (F < maxCOD) and 1038 (ContinentPresence[F] and not (1 shl Me or PresenceUnknown) <> 0) and 1039 1039 (NextTile and (fUnit or fOwned) <> fUnit) then 1040 1040 begin … … 1074 1074 1075 1075 if EndLoc < 0 then 1076 exit;1076 Exit; 1077 1077 if Loc <> EndLoc then 1078 1078 Unit_MoveEx(uix, EndLoc); 1079 1079 if Loc <> EndLoc then 1080 exit;1080 Exit; 1081 1081 if SlowUnloadLoc >= 0 then 1082 1082 begin … … 1092 1092 begin 1093 1093 Moved[uix] := False; 1094 exit;1094 Exit; 1095 1095 end 1096 1096 until False; … … 1099 1099 1100 1100 var 1101 uix, euix, Kind, euixBest, AttackLoc: integer;1102 OldTile: cardinal;1103 BackToStart, FirstLoop: boolean;1101 uix, euix, Kind, euixBest, AttackLoc: Integer; 1102 OldTile: Cardinal; 1103 BackToStart, FirstLoop: Boolean; 1104 1104 begin 1105 fillchar(UnitPresence, MapSize, 0);1105 FillChar(UnitPresence, MapSize, 0); 1106 1106 for uix := 0 to RO.nUn - 1 do 1107 1107 with MyUnit[uix] do … … 1116 1116 end; 1117 1117 1118 fillchar(Moved, RO.nUn, False);1118 FillChar(Moved, RO.nUn, False); 1119 1119 for uix := 0 to RO.nUn - 1 do 1120 1120 if (MyUnit[uix].Master >= 0) or (MyUnit[uix].TroopLoad > 0) then … … 1128 1128 if RO.nEnemyUn > 0 then 1129 1129 begin 1130 fillchar(euixMap, MapSize * 2, $FF);1131 fillchar(AttackScore, RO.nEnemyUn * 4, 0);1130 FillChar(euixMap, MapSize * 2, $FF); 1131 FillChar(AttackScore, RO.nEnemyUn * 4, 0); 1132 1132 for euix := 0 to RO.nEnemyUn - 1 do 1133 1133 with RO.EnemyUn[euix] do … … 1140 1140 end; 1141 1141 if not BackToStart then 1142 break;1142 Break; 1143 1143 1144 1144 for uix := 0 to RO.nUn - 1 do … … 1155 1155 euixBest := euix; 1156 1156 if euixBest < 0 then 1157 break;1157 Break; 1158 1158 uix := uixAttack[euixBest]; 1159 1159 AttackLoc := RO.EnemyUn[euixBest].Loc; … … 1202 1202 begin 1203 1203 BackToStart := True; 1204 break;1204 Break; 1205 1205 end 1206 1206 until not BackToStart; … … 1214 1214 1 shl woMagellan + 1 shl woEiffel + 1 shl woLiberty + 1 shl woShinkansen; 1215 1215 1216 function LowPriority(cix: integer): boolean;1216 function LowPriority(cix: Integer): Boolean; 1217 1217 var 1218 part, cixHighPriority, TestDistance: integer;1218 part, cixHighPriority, TestDistance: Integer; 1219 1219 begin 1220 1220 Result := False; … … 1228 1228 begin 1229 1229 Result := True; 1230 exit;1230 Exit; 1231 1231 end; 1232 1232 end; … … 1234 1234 end; 1235 1235 1236 function ChooseWonderToBuild(WonderAvailable: integer; AllowCoastal: boolean): integer;1236 function ChooseWonderToBuild(WonderAvailable: Integer; AllowCoastal: Boolean): Integer; 1237 1237 var 1238 Count, iix: integer;1238 Count, iix: Integer; 1239 1239 begin 1240 1240 if (WonderAvailable and PrimeWonder > 0) and (AllowCoastal or … … 1267 1267 begin 1268 1268 Result := iix; 1269 exit;1269 Exit; 1270 1270 end; 1271 1271 end; … … 1273 1273 1274 1274 var 1275 i, iix, cix, mix, uix, mixProduce, mixShip, V8, V21, Loc1, TotalPop,1276 AlonePop, f, f1, nTownGuard, ShipPart, ProduceShipPart, TestDistance,1277 part, WonderAvailable, WonderInWork, cixNewCapital, Center, Score, BestScore: integer;1278 mixCount: array[0..nmmax - 1] of integer;1275 I, iix, cix, mix, uix, mixProduce, mixShip, V8, V21, Loc1, TotalPop, 1276 AlonePop, F, f1, nTownGuard, ShipPart, ProduceShipPart, TestDistance, 1277 part, WonderAvailable, WonderInWork, cixNewCapital, Center, Score, BestScore: Integer; 1278 mixCount: array[0..nmmax - 1] of Integer; 1279 1279 //RareLoc: array[0..5] of integer; 1280 1280 Adjacent: TVicinity8Loc; 1281 1281 IsCoastal, IsPort, IsUnitProjectObsolete, HasSettler, SpezializeShipProduction, 1282 1282 AlgaeAvailable, ProjectComplete, DoLowPriority, WillProduceColonyShip, 1283 ImportantCity: boolean;1283 ImportantCity: Boolean; 1284 1284 Radius: TVicinity21Loc; 1285 1285 Report: TCityReportNew; … … 1289 1289 FindBestModels; 1290 1290 1291 fillchar(mixCount, RO.nModel * 4, 0);1291 FillChar(mixCount, RO.nModel * 4, 0); 1292 1292 for uix := 0 to RO.nUn - 1 do 1293 1293 with MyUnit[uix] do … … 1317 1317 begin 1318 1318 Inc(TotalPop, Size); 1319 f:= Formation[Loc];1320 if ( f < 0) or (f >= maxCOD) or (ContinentPresence[f] = 1 shl me) then1319 F := Formation[Loc]; 1320 if (F < 0) or (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me) then 1321 1321 Inc(AlonePop, Size); 1322 1322 end; … … 1358 1358 if (f1 >= 0) and (f1 < maxCOD) and 1359 1359 ((OceanSize[f1] >= 8) or (OceanPresence[f1] and not 1360 (1 shl me) <> 0)) then1360 (1 shl Me) <> 0)) then 1361 1361 begin // prefer non-coastal cities 1362 1362 Dec(Score, 18); 1363 break;1363 Break; 1364 1364 end; 1365 1365 end; … … 1390 1390 (LowPriority(cix) = DoLowPriority) then 1391 1391 begin 1392 f:= Formation[Loc];1392 F := Formation[Loc]; 1393 1393 IsCoastal := False; 1394 1394 IsPort := False; … … 1402 1402 f1 := Formation[Loc1]; 1403 1403 if (f1 >= 0) and (f1 < maxCOD) and (OceanSize[f1] >= 8) and 1404 (OceanPresence[f1] and not (1 shl me) <> 0) then1404 (OceanPresence[f1] and not (1 shl Me) <> 0) then 1405 1405 begin 1406 1406 IsPort := True; 1407 break;1407 Break; 1408 1408 end; 1409 1409 end; … … 1412 1412 (RO.Model[City_CurrentUnitProject(cix)].Kind <> mkSettler) then 1413 1413 begin 1414 i:= nModelCategory - 1;1415 while ( i >= 0) and (City_CurrentUnitProject(cix) <> mixBest[i]) do1416 Dec( i);1417 IsUnitProjectObsolete := i< 0;1414 I := nModelCategory - 1; 1415 while (I >= 0) and (City_CurrentUnitProject(cix) <> mixBest[I]) do 1416 Dec(I); 1417 IsUnitProjectObsolete := I < 0; 1418 1418 end 1419 1419 else … … 1581 1581 City_StartImprovement(cix,imMissileBat)} 1582 1582 else if IsPort and (not SpezializeShipProduction or 1583 ( f < 0) or (f >= maxCOD) or (ContinentPresence[f] = 1 shl me)) and1583 (F < 0) or (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me)) and 1584 1584 (Built[imDockyard] = 0) and City_Improvable(cix, imDockyard) then 1585 1585 City_StartImprovement(cix, imDockyard) 1586 1586 else if IsPort and (mixShip >= 0) and 1587 (not SpezializeShipProduction or ( f< 0) or1588 ( f >= maxCOD) or (ContinentPresence[f] = 1 shl me)) then1587 (not SpezializeShipProduction or (F < 0) or 1588 (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me)) then 1589 1589 City_StartUnitProduction(cix, mixShip) 1590 1590 else if (Built[imBarracks] + Built[imMilAcademy] = 0) and … … 1600 1600 if (City_CurrentImprovementProject(cix) = imCourt) and 1601 1601 (Built[imTownHall] > 0) and (prod >= imp[imCourt].cost * 1602 BuildCostMod[G.Difficulty[ me]] div 12 -1603 (imp[imTownHall].cost * BuildCostMod[G.Difficulty[ me]] div 12) *1602 BuildCostMod[G.Difficulty[Me]] div 12 - 1603 (imp[imTownHall].cost * BuildCostMod[G.Difficulty[Me]] div 12) * 1604 1604 2 div 3) then 1605 1605 City_RebuildImprovement(cix, imTownHall) … … 1614 1614 if City_RebuildImprovement(cix, iix) < rExecuted then 1615 1615 City_SellImprovement(cix, iix); 1616 break;1616 Break; 1617 1617 end; 1618 1618 end; 1619 1619 end; 1620 1620 1621 function TBarbarina.Barbarina_ChooseResearchAdvance: integer;1621 function TBarbarina.Barbarina_ChooseResearchAdvance: Integer; 1622 1622 var 1623 nPreq, rmix, rmixChosen, i, MaxWeight, MaxDefense, ChosenPreq: integer;1624 NeedSeaUnits, ready: boolean;1623 nPreq, rmix, rmixChosen, I, MaxWeight, MaxDefense, ChosenPreq: Integer; 1624 NeedSeaUnits, ready: Boolean; 1625 1625 ModelExists: set of 0..nModelCategory - 1; 1626 known: array[0..nAdv - 1] of integer;1627 1628 procedure ChoosePreq(ad: integer);1626 known: array[0..nAdv - 1] of Integer; 1627 1628 procedure ChoosePreq(ad: Integer); 1629 1629 var 1630 i: integer;1631 PreqOk: boolean;1630 I: Integer; 1631 PreqOk: Boolean; 1632 1632 begin 1633 assert(RO.Tech[ad] < tsApplicable);1633 Assert(RO.Tech[ad] < tsApplicable); 1634 1634 if known[ad] = 0 then 1635 1635 begin … … 1637 1637 PreqOk := True; 1638 1638 if not (ad in [adScience, adMassProduction]) and (RO.Tech[ad] < tsSeen) then 1639 for i:= 0 to 1 do1640 if (AdvPreq[ad, i] >= 0) and (RO.Tech[AdvPreq[ad, i]] < tsApplicable) then1639 for I := 0 to 1 do 1640 if (AdvPreq[ad, I] >= 0) and (RO.Tech[AdvPreq[ad, I]] < tsApplicable) then 1641 1641 begin 1642 1642 PreqOk := False; 1643 ChoosePreq(AdvPreq[ad, i]);1643 ChoosePreq(AdvPreq[ad, I]); 1644 1644 end; 1645 1645 if PreqOk then … … 1697 1697 ready := (MaxWeight >= Weight) and (MaxDefense >= Cap[mcDefense]); 1698 1698 if ready then 1699 for i:= 0 to nFeature - 1 do1700 if (Cap[ i] > 0) and (Feature[i].Preq <> preNone) and1701 ((Feature[ i].Preq < 0) or not IsResearched(Feature[i].Preq)) then1699 for I := 0 to nFeature - 1 do 1700 if (Cap[I] > 0) and (Feature[I].Preq <> preNone) and 1701 ((Feature[I].Preq < 0) or not IsResearched(Feature[I].Preq)) then 1702 1702 ready := False; 1703 1703 if ready then 1704 1704 begin 1705 for i:= 0 to nUpgrade - 1 do1706 if (Upgrades and (1 shl i) <> 0) and not1707 IsResearched(Upgrade[Domain, i].Preq) then1705 for I := 0 to nUpgrade - 1 do 1706 if (Upgrades and (1 shl I) <> 0) and not 1707 IsResearched(Upgrade[Domain, I].Preq) then 1708 1708 ready := False; 1709 1709 end; 1710 1710 if ready then 1711 1711 begin 1712 include(ModelExists, Category);1712 Include(ModelExists, Category); 1713 1713 if not IsModelAvailable(rmix) then 1714 1714 rmixChosen := rmix; … … 1719 1719 begin 1720 1720 PrepareNewModel(Domain); 1721 for i:= 0 to nFeature - 1 do1722 if ( i < 2) or (Cap[i] > 0) then1723 SetNewModelFeature( i, Cap[i]);1724 if RO.Wonder[woSun].EffectiveOwner = me then1721 for I := 0 to nFeature - 1 do 1722 if (I < 2) or (Cap[I] > 0) then 1723 SetNewModelFeature(I, Cap[I]); 1724 if RO.Wonder[woSun].EffectiveOwner = Me then 1725 1725 begin 1726 1726 //if Cap[mcWeapons]>=2*Cap[mcArmor] then … … 1730 1730 end; 1731 1731 Result := adMilitary; 1732 exit;1732 Exit; 1733 1733 end; 1734 1734 1735 1735 NeedSeaUnits := True; 1736 i:= 0;1737 while ( i < nResearchOrder) and (not NeedSeaUnits and (ResearchOrder[i] < 0) or1738 IsResearched(abs(ResearchOrder[ i]))) do1739 Inc( i);1740 if i>= nResearchOrder then // list done, continue with future tech1736 I := 0; 1737 while (I < nResearchOrder) and (not NeedSeaUnits and (ResearchOrder[I] < 0) or 1738 IsResearched(abs(ResearchOrder[I]))) do 1739 Inc(I); 1740 if I >= nResearchOrder then // list done, continue with future tech 1741 1741 begin 1742 1742 if random(2) = 1 then … … 1750 1750 nPreq := 0; 1751 1751 ChosenPreq := -1; 1752 ChoosePreq(abs(ResearchOrder[ i]));1753 assert(nPreq > 0);1752 ChoosePreq(abs(ResearchOrder[I])); 1753 Assert(nPreq > 0); 1754 1754 Result := ChosenPreq; 1755 1755 end; 1756 1756 end; 1757 1757 1758 function TBarbarina.Barbarina_WantCheckNegotiation(Nation: integer): boolean;1758 function TBarbarina.Barbarina_WantCheckNegotiation(Nation: Integer): Boolean; 1759 1759 begin 1760 1760 if (RO.Tech[adTheRepublic] < tsSeen) and (RO.Tech[adTheology] >= tsApplicable) and … … 1769 1769 begin 1770 1770 if RO.Tech[adTheRepublic] >= tsSeen then 1771 exit; // default reaction1771 Exit; // default reaction 1772 1772 if MyLastAction = scContact then 1773 1773 begin … … 1797 1797 end; 1798 1798 1799 function TBarbarina.Barbarina_WantNegotiation(Nation: integer;1800 NegoTime: TNegoTime): boolean;1799 function TBarbarina.Barbarina_WantNegotiation(Nation: Integer; 1800 NegoTime: TNegoTime): Boolean; 1801 1801 var 1802 uix, TestLoc, V8: integer;1802 uix, TestLoc, V8: Integer; 1803 1803 Adjacent: TVicinity8Loc; 1804 1804 begin … … 1812 1812 if RO.Turn >= RO.LastCancelTreaty[Nation] + CancelTreatyTurns then 1813 1813 begin 1814 if (RO.Turn and 3 = (Nation + $F - me) and 3) and1814 if (RO.Turn and 3 = (Nation + $F - Me) and 3) and 1815 1815 (RO.Treaty[Nation] > trPeace) then 1816 1816 begin … … 1838 1838 NegoCause := CancelTreaty; 1839 1839 Result := True; 1840 exit;1840 Exit; 1841 1841 end; 1842 1842 end; … … 1858 1858 procedure TBarbarina.MakeColonyShipPlan; 1859 1859 var 1860 i, V21, V21C, CityLoc, Loc1, part, cix, BestValue, TestValue, FoodCount,1861 ProdCount, ProdExtra, Score, BestScore: integer;1862 Tile: cardinal;1863 ok, check: boolean;1860 I, V21, V21C, CityLoc, Loc1, part, cix, BestValue, TestValue, FoodCount, 1861 ProdCount, ProdExtra, Score, BestScore: Integer; 1862 Tile: Cardinal; 1863 ok, check: Boolean; 1864 1864 Radius, RadiusC: TVicinity21Loc; 1865 1865 begin … … 1887 1887 begin 1888 1888 part := (Tile and fModern) shr 25 - 1; 1889 if RO.Ship[ me].Parts[part] < ShipNeed[part] then1889 if RO.Ship[Me].Parts[part] < ShipNeed[part] then 1890 1890 // not enough of this kind already 1891 1891 begin … … 1893 1893 if ColonyShipPlan[part].cixProducing >= 0 then 1894 1894 begin // another city is already assigned to this ship part, choose one of the two 1895 TestValue := (ID and $FFF) shl 4 + ((ID shr 12) + 15 - me) and $F;1895 TestValue := (ID and $FFF) shl 4 + ((ID shr 12) + 15 - Me) and $F; 1896 1896 BestValue := 1897 1897 (MyCity[ColonyShipPlan[part].cixProducing].ID and $FFF) shl 1898 1898 4 + ((MyCity[ColonyShipPlan[part].cixProducing].ID shr 12) + 1899 15 - me) and $F;1899 15 - Me) and $F; 1900 1900 if TestValue <= BestValue then 1901 1901 ok := False; … … 1912 1912 check := False; 1913 1913 for part := 0 to nShipPart - 1 do 1914 if (RO.Ship[ me].Parts[part] < ShipNeed[part]) // not enough of this kind already1914 if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already 1915 1915 and (ColonyShipPlan[part].cixProducing < 0) then // no city to produce 1916 1916 check := True; … … 1931 1931 end; 1932 1932 for part := 0 to nShipPart - 1 do 1933 if (RO.Ship[ me].Parts[part] < ShipNeed[part]) // not enough of this kind already1933 if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already 1934 1934 and (ColonyShipPlan[part].cixProducing < 0) // no city to produce 1935 1935 and (ColonyShipPlan[part].nLocResource > 0) then // resource is known 1936 1936 begin 1937 for i:= 0 to ColonyShipPlan[part].nLocResource - 1 do1937 for I := 0 to ColonyShipPlan[part].nLocResource - 1 do 1938 1938 begin 1939 1939 BestScore := 0; 1940 V21_to_Loc(ColonyShipPlan[part].LocResource[ i], Radius);1940 V21_to_Loc(ColonyShipPlan[part].LocResource[I], Radius); 1941 1941 for V21 := 1 to 26 do 1942 1942 begin // check all potential cities in range … … 1984 1984 Dec(ProdCount, 5 - FoodCount); 1985 1985 Score := ProdCount * 4 + ProdExtra * 8 + FoodCount; 1986 Score := Score shl 8 + ((CityLoc xor me) * 4567) mod 251;1986 Score := Score shl 8 + ((CityLoc xor Me) * 4567) mod 251; 1987 1987 // some unexactness, random but always the same for this tile 1988 1988 end; -
trunk/AI/StdAI/CustomAI.pas
r289 r447 13 13 TCustomAI = class 14 14 public 15 procedure Process(Command: integer; var Data);15 procedure Process(Command: Integer; var Data); 16 16 17 17 // overridables 18 constructor Create(Nation: integer); virtual;18 constructor Create(Nation: Integer); virtual; 19 19 destructor Destroy; override; 20 20 procedure SetDataDefaults; virtual; 21 21 procedure SetDataRandom; virtual; 22 22 procedure OnBeforeEnemyAttack(UnitInfo: TUnitInfo; 23 ToLoc, EndHealth, EndHealthDef: integer); virtual;24 procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer); virtual;23 ToLoc, EndHealth, EndHealthDef: Integer); virtual; 24 procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); virtual; 25 25 procedure OnAfterEnemyAttack; virtual; 26 26 procedure OnAfterEnemyCapture; virtual; 27 27 28 28 protected 29 me: integer; // index of the controlled nation29 Me: Integer; // index of the controlled nation 30 30 RO: ^TPlayerContext; 31 31 Map: ^TTileList; … … 34 34 MyModel: ^TModelList; 35 35 36 cixStateImp: array[imPalace..imSpacePort] of integer;36 cixStateImp: array[imPalace..imSpacePort] of Integer; 37 37 38 38 // negotiation 39 Opponent: integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode40 MyAction, MyLastAction, OppoAction: integer;39 Opponent: Integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode 40 MyAction, MyLastAction, OppoAction: Integer; 41 41 MyOffer, MyLastOffer, OppoOffer: TOffer; 42 42 … … 44 44 procedure DoTurn; virtual; 45 45 procedure DoNegotiation; virtual; 46 function ChooseResearchAdvance: integer; virtual;47 function ChooseStealAdvance: integer; virtual;48 function ChooseGovernment: integer; virtual;49 function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; virtual;50 function OnNegoRejected_CancelTreaty: boolean; virtual;46 function ChooseResearchAdvance: Integer; virtual; 47 function ChooseStealAdvance: Integer; virtual; 48 function ChooseGovernment: Integer; virtual; 49 function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; virtual; 50 function OnNegoRejected_CancelTreaty: Boolean; virtual; 51 51 52 52 // general functions 53 function IsResearched(Advance: integer): boolean;54 function ResearchCost: integer;55 function ChangeAttitude(Nation, Attitude: integer): integer;56 function Revolution: integer;57 function ChangeRates(Tax, Lux: integer): integer;58 function PrepareNewModel(Domain: integer): integer;59 function SetNewModelFeature(F, Count: integer): integer;60 function AdvanceResearchable(Advance: integer): boolean;61 function AdvanceStealable(Advance: integer): boolean;62 function GetJobProgress(Loc: integer; var JobProgress: TJobProgressData): boolean;63 function DebugMessage(Level: integer; Text: string): boolean;64 function SetDebugMap(var DebugMap): boolean;53 function IsResearched(Advance: Integer): Boolean; 54 function ResearchCost: Integer; 55 function ChangeAttitude(Nation, Attitude: Integer): Integer; 56 function Revolution: Integer; 57 function ChangeRates(Tax, Lux: Integer): Integer; 58 function PrepareNewModel(Domain: Integer): Integer; 59 function SetNewModelFeature(F, Count: Integer): Integer; 60 function AdvanceResearchable(Advance: Integer): Boolean; 61 function AdvanceStealable(Advance: Integer): Boolean; 62 function GetJobProgress(Loc: Integer; var JobProgress: TJobProgressData): Boolean; 63 function DebugMessage(Level: Integer; Text: string): Boolean; 64 function SetDebugMap(var DebugMap): Boolean; 65 65 66 66 // unit functions 67 procedure Unit_FindMyDefender(Loc: integer; var uix: integer);68 procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);69 function Unit_Move(uix, ToLoc: integer): integer;70 function Unit_Step(uix, ToLoc: integer): integer;71 function Unit_Attack(uix, ToLoc: integer): integer;72 function Unit_DoMission(uix, MissionType, ToLoc: integer): integer;73 function Unit_MoveForecast(uix, ToLoc: integer;74 var RemainingMovement: integer): boolean;75 function Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;76 var RemainingHealth: integer): boolean;77 function Unit_DefenseForecast(euix, ToLoc: integer;78 var RemainingHealth: integer): boolean;79 function Unit_Disband(uix: integer): integer;80 function Unit_StartJob(uix, NewJob: integer): integer;81 function Unit_SetHomeHere(uix: integer): integer;82 function Unit_Load(uix: integer): integer;83 function Unit_Unload(uix: integer): integer;84 function Unit_SelectTransport(uix: integer): integer;85 function Unit_AddToCity(uix: integer): integer;67 procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer); 68 procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer); 69 function Unit_Move(uix, ToLoc: Integer): Integer; 70 function Unit_Step(uix, ToLoc: Integer): Integer; 71 function Unit_Attack(uix, ToLoc: Integer): Integer; 72 function Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer; 73 function Unit_MoveForecast(uix, ToLoc: Integer; 74 var RemainingMovement: Integer): Boolean; 75 function Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer; 76 var RemainingHealth: Integer): Boolean; 77 function Unit_DefenseForecast(euix, ToLoc: Integer; 78 var RemainingHealth: Integer): Boolean; 79 function Unit_Disband(uix: Integer): Integer; 80 function Unit_StartJob(uix, NewJob: Integer): Integer; 81 function Unit_SetHomeHere(uix: Integer): Integer; 82 function Unit_Load(uix: Integer): Integer; 83 function Unit_Unload(uix: Integer): Integer; 84 function Unit_SelectTransport(uix: Integer): Integer; 85 function Unit_AddToCity(uix: Integer): Integer; 86 86 87 87 // city functions 88 procedure City_FindMyCity(Loc: integer; var cix: integer);89 procedure City_FindEnemyCity(Loc: integer; var ecix: integer);90 function City_HasProject(cix: integer): boolean;91 function City_CurrentImprovementProject(cix: integer): integer;92 function City_CurrentUnitProject(cix: integer): integer;93 function City_GetTileInfo(cix, TileLoc: integer; var TileInfo: TTileInfo): integer;94 function City_GetReport(cix: integer; var Report: TCityReport): integer;95 function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;96 var Report: TCityReport): integer;97 function City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;98 function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: integer;99 var Report: TCityReportNew): integer;100 function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;101 function City_StartUnitProduction(cix, mix: integer): integer;102 function City_StartEmigration(cix, mix: integer;103 AllowDisbandCity, AsConscripts: boolean): integer;104 function City_StartImprovement(cix, iix: integer): integer;105 function City_Improvable(cix, iix: integer): boolean;106 function City_StopProduction(cix: integer): integer;107 function City_BuyProject(cix: integer): integer;108 function City_SellImprovement(cix, iix: integer): integer;109 function City_RebuildImprovement(cix, iix: integer): integer;110 function City_SetTiles(cix, NewTiles: integer): integer;111 procedure City_OptimizeTiles(cix: integer; ResourceWeights: cardinal = rwMaxGrowth);88 procedure City_FindMyCity(Loc: Integer; var cix: Integer); 89 procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer); 90 function City_HasProject(cix: Integer): Boolean; 91 function City_CurrentImprovementProject(cix: Integer): Integer; 92 function City_CurrentUnitProject(cix: Integer): Integer; 93 function City_GetTileInfo(cix, TileLoc: Integer; var TileInfo: TTileInfo): Integer; 94 function City_GetReport(cix: Integer; var Report: TCityReport): Integer; 95 function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; 96 var Report: TCityReport): Integer; 97 function City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer; 98 function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: Integer; 99 var Report: TCityReportNew): Integer; 100 function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer; 101 function City_StartUnitProduction(cix, mix: Integer): Integer; 102 function City_StartEmigration(cix, mix: Integer; 103 AllowDisbandCity, AsConscripts: Boolean): Integer; 104 function City_StartImprovement(cix, iix: Integer): Integer; 105 function City_Improvable(cix, iix: Integer): Boolean; 106 function City_StopProduction(cix: Integer): Integer; 107 function City_BuyProject(cix: Integer): Integer; 108 function City_SellImprovement(cix, iix: Integer): Integer; 109 function City_RebuildImprovement(cix, iix: Integer): Integer; 110 function City_SetTiles(cix, NewTiles: Integer): Integer; 111 procedure City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal = rwMaxGrowth); 112 112 113 113 // negotiation 114 function Nego_CheckMyAction: integer;114 function Nego_CheckMyAction: Integer; 115 115 116 116 private 117 HaveTurned: boolean;117 HaveTurned: Boolean; 118 118 UnwantedNego: set of 0..nPl - 1; 119 119 Contacted: set of 0..nPl - 1; … … 125 125 Server: TServerCall; 126 126 G: TNewGameData; 127 RWDataSize, MapSize: integer;128 decompose24: cardinal;129 nodata: pointer;127 RWDataSize, MapSize: Integer; 128 decompose24: Cardinal; 129 nodata: Pointer; 130 130 131 131 const … … 139 139 140 140 type 141 TVicinity8Loc = array[0..7] of integer;142 TVicinity21Loc = array[0..27] of integer;141 TVicinity8Loc = array[0..7] of Integer; 142 TVicinity21Loc = array[0..27] of Integer; 143 143 144 144 145 145 procedure Init(NewGameData: TNewGameData); 146 146 147 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);148 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);149 procedure ab_to_V8( a, b: integer; var V8: integer);150 procedure V8_to_ab(V8: integer; var a, b: integer);151 procedure ab_to_V21( a, b: integer; var V21: integer);152 procedure V21_to_ab(V21: integer; var a, b: integer);153 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);154 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);155 function Distance(Loc0, Loc1: integer): integer;147 procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer); 148 procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer); 149 procedure ab_to_V8(A, B: Integer; var V8: Integer); 150 procedure V8_to_ab(V8: Integer; var A, B: Integer); 151 procedure ab_to_V21(A, B: Integer; var V21: Integer); 152 procedure V21_to_ab(V21: Integer; var A, B: Integer); 153 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 154 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 155 function Distance(Loc0, Loc1: Integer): Integer; 156 156 157 157 … … 159 159 160 160 const 161 ab_v8: array[-4..4] of integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);162 v8_a: array[0..7] of integer = (1, 1, 0, -1, -1, -1, 0, 1);163 v8_b: array[0..7] of integer = (0, 1, 1, 1, 0, -1, -1, -1);164 165 166 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);161 ab_v8: array[-4..4] of Integer = (5, 6, 7, 4, -1, 0, 3, 2, 1); 162 v8_a: array[0..7] of Integer = (1, 1, 0, -1, -1, -1, 0, 1); 163 v8_b: array[0..7] of Integer = (0, 1, 1, 1, 0, -1, -1, -1); 164 165 166 procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer); 167 167 {relative location from Loc0} 168 168 var 169 y0: integer;170 begin 171 assert((Loc0 >= 0) and (Loc0 < MapSize) and (a - b+ G.lx >= 0));172 y0 := cardinal(Loc0) * decompose24 shr 24;173 Loc := (Loc0 + ( a - b + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + a + b);169 y0: Integer; 170 begin 171 Assert((Loc0 >= 0) and (Loc0 < MapSize) and (A - B + G.lx >= 0)); 172 y0 := Cardinal(Loc0) * decompose24 shr 24; 173 Loc := (Loc0 + (A - B + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + A + B); 174 174 if Loc >= MapSize then 175 175 Loc := -$1000; 176 176 end; 177 177 178 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);178 procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer); 179 179 {$IFDEF FPC}// freepascal 180 180 var 181 dx, dy: integer;181 dx, dy: Integer; 182 182 begin 183 183 dx := ((Loc mod G.lx * 2 + Loc div G.lx and 1) - (Loc0 mod G.lx * 2 + Loc0 div 184 184 G.lx and 1) + 3 * G.lx) mod (2 * G.lx) - G.lx; 185 185 dy := Loc div G.lx - Loc0 div G.lx; 186 a:= (dx + dy) div 2;187 b:= (dy - dx) div 2;186 A := (dx + dy) div 2; 187 B := (dy - dx) div 2; 188 188 end; 189 189 … … 195 195 // calculate 196 196 push ecx 197 div byte ptr [G]197 div Byte ptr [G] 198 198 xor ebx,ebx 199 199 mov bl,ah // ebx:=Loc0 mod G.lx … … 201 201 and ecx,$000000FF // ecx:=Loc0 div G.lx 202 202 mov eax,edx 203 div byte ptr [G]203 div Byte ptr [G] 204 204 xor edx,edx 205 205 mov dl,ah // edx:=Loc mod G.lx … … 218 218 mov edx,dword ptr [G] 219 219 cmp eax,edx 220 jl @ a220 jl @A 221 221 sub eax,edx 222 222 sub eax,edx 223 223 jmp @ok 224 @ a:224 @A: 225 225 neg edx 226 226 cmp eax,edx … … 235 235 add eax,ebx 236 236 sar edx,1 // edx:=b 237 mov ebx,[ b]237 mov ebx,[B] 238 238 mov [ebx],edx 239 239 sar eax,1 // eax:=a 240 mov [ a],eax240 mov [A],eax 241 241 242 242 pop ebx … … 244 244 {$ENDIF} 245 245 246 procedure ab_to_V8( a, b: integer; var V8: integer);247 begin 248 assert((abs(a) <= 1) and (abs(b) <= 1) and ((a <> 0) or (b<> 0)));249 V8 := ab_v8[2 * b + b + a];250 end; 251 252 procedure V8_to_ab(V8: integer; var a, b: integer);253 begin 254 a:= v8_a[V8];255 b:= V8_b[V8];256 end; 257 258 procedure ab_to_V21( a, b: integer; var V21: integer);259 begin 260 V21 := ( a + b + 3) shl 2 + (a - b+ 3) shr 1;261 end; 262 263 procedure V21_to_ab(V21: integer; var a, b: integer);264 var 265 dx, dy: integer;246 procedure ab_to_V8(A, B: Integer; var V8: Integer); 247 begin 248 Assert((abs(A) <= 1) and (abs(B) <= 1) and ((A <> 0) or (B <> 0))); 249 V8 := ab_v8[2 * B + B + A]; 250 end; 251 252 procedure V8_to_ab(V8: Integer; var A, B: Integer); 253 begin 254 A := v8_a[V8]; 255 B := V8_b[V8]; 256 end; 257 258 procedure ab_to_V21(A, B: Integer; var V21: Integer); 259 begin 260 V21 := (A + B + 3) shl 2 + (A - B + 3) shr 1; 261 end; 262 263 procedure V21_to_ab(V21: Integer; var A, B: Integer); 264 var 265 dx, dy: Integer; 266 266 begin 267 267 dy := V21 shr 2 - 3; 268 268 dx := V21 and 3 shl 1 - 3 + (dy + 3) and 1; 269 a:= (dx + dy) div 2;270 b:= (dy - dx) div 2;271 end; 272 273 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);274 var 275 x0, y0, lx: integer;269 A := (dx + dy) div 2; 270 B := (dy - dx) div 2; 271 end; 272 273 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 274 var 275 x0, y0, lx: Integer; 276 276 begin 277 277 lx := G.lx; 278 y0 := cardinal(Loc0) * decompose24 shr 24;278 y0 := Cardinal(Loc0) * decompose24 shr 24; 279 279 x0 := Loc0 - y0 * lx; // Loc0 mod lx; 280 280 VicinityLoc[1] := Loc0 + lx * 2; … … 323 323 end; 324 324 325 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);326 var 327 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;328 dst: ^ integer;329 begin 330 y0 := cardinal(Loc0) * decompose24 shr 24;325 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 326 var 327 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer; 328 dst: ^Integer; 329 begin 330 y0 := Cardinal(Loc0) * decompose24 shr 24; 331 331 xComp0 := Loc0 - y0 * G.lx - 1; // Loc0 mod G.lx -1 332 332 xCompSwitch := xComp0 - 1 + y0 and 1; … … 368 368 end; 369 369 370 function Distance(Loc0, Loc1: integer): integer;371 var 372 a, b, dx, dy: integer;373 begin 374 Loc_to_ab(Loc0, Loc1, a, b);375 dx := abs( a - b);376 dy := abs( a + b);370 function Distance(Loc0, Loc1: Integer): Integer; 371 var 372 A, B, dx, dy: Integer; 373 begin 374 Loc_to_ab(Loc0, Loc1, A, B); 375 dx := abs(A - B); 376 dy := abs(A + B); 377 377 Result := dx + dy + abs(dx - dy) shr 1; 378 378 end; … … 381 381 procedure Init(NewGameData: TNewGameData); 382 382 {$IFDEF DEBUG}var 383 Loc: integer;383 Loc: Integer; 384 384 {$ENDIF} 385 385 begin … … 389 389 {$IFDEF DEBUG} 390 390 for Loc := 0 to MapSize - 1 do 391 assert(cardinal(Loc) * decompose24 shr 24 = cardinal(Loc div G.lx));391 Assert(Cardinal(Loc) * decompose24 shr 24 = Cardinal(Loc div G.lx)); 392 392 {$ENDIF} 393 393 end; 394 394 395 395 396 constructor TCustomAI.Create(Nation: integer);396 constructor TCustomAI.Create(Nation: Integer); 397 397 begin 398 398 inherited Create; 399 me := Nation;400 RO := pointer(G.RO[Nation]);401 Map := pointer(RO.Map);402 MyUnit := pointer(RO.Un);403 MyCity := pointer(RO.City);404 MyModel := pointer(RO.Model);399 Me := Nation; 400 RO := Pointer(G.RO[Nation]); 401 Map := Pointer(RO.Map); 402 MyUnit := Pointer(RO.Un); 403 MyCity := Pointer(RO.City); 404 MyModel := Pointer(RO.Model); 405 405 Opponent := -1; 406 406 end; … … 408 408 destructor TCustomAI.Destroy; 409 409 begin 410 Server(sSetDebugMap, me, 0, nodata^);411 end; 412 413 414 procedure TCustomAI.Process(Command: integer; var Data);415 var 416 Nation, NewResearch, NewGov, Count, ad, cix, iix: integer;410 Server(sSetDebugMap, Me, 0, nodata^); 411 end; 412 413 414 procedure TCustomAI.Process(Command: Integer; var Data); 415 var 416 Nation, NewResearch, NewGov, Count, ad, cix, iix: Integer; 417 417 NegoTime: TNegoTime; 418 418 begin … … 420 420 cTurn, cContinue: 421 421 begin 422 if RO.Alive and (1 shl me) = 0 then422 if RO.Alive and (1 shl Me) = 0 then 423 423 begin // I'm dead, huhu 424 Server(sTurn, me, 0, nodata^);425 exit;424 Server(sTurn, Me, 0, nodata^); 425 Exit; 426 426 end; 427 427 if Command = cTurn then 428 428 begin 429 fillchar(cixStateImp, sizeof(cixStateImp), $FF);429 FillChar(cixStateImp, SizeOf(cixStateImp), $FF); 430 430 for cix := 0 to RO.nCity - 1 do 431 431 if MyCity[cix].Loc >= 0 then … … 437 437 NewGov := ChooseGovernment; 438 438 if NewGov > gAnarchy then 439 Server(sSetGovernment, me, NewGov, nodata^);439 Server(sSetGovernment, Me, NewGov, nodata^); 440 440 end; 441 441 HaveTurned := False; … … 446 446 if OnNegoRejected_CancelTreaty then 447 447 if RO.Treaty[Opponent] >= trPeace then 448 if Server(sCancelTreaty, me, 0, nodata^) < rExecuted then449 assert(False);448 if Server(sCancelTreaty, Me, 0, nodata^) < rExecuted then 449 Assert(False); 450 450 end 451 451 else … … 459 459 if RO.Government <> gAnarchy then 460 460 for Nation := 0 to nPl - 1 do 461 if (Nation <> me) and (1 shl Nation and RO.Alive <> 0) and461 if (Nation <> Me) and (1 shl Nation and RO.Alive <> 0) and 462 462 (RO.Treaty[Nation] >= trNone) and not (Nation in Contacted) and not 463 463 (Nation in UnwantedNego) and 464 (Server(scContact - sExecute + Nation shl 4, me, 0, nodata^) >= rExecuted) then464 (Server(scContact - sExecute + Nation shl 4, Me, 0, nodata^) >= rExecuted) then 465 465 if WantNegotiation(Nation, NegoTime) then 466 466 begin 467 if Server(scContact + Nation shl 4, me, 0, nodata^) >= rExecuted then467 if Server(scContact + Nation shl 4, Me, 0, nodata^) >= rExecuted then 468 468 begin 469 include(Contacted, Nation);469 Include(Contacted, Nation); 470 470 Opponent := Nation; 471 471 MyAction := scContact; 472 exit;472 Exit; 473 473 end; 474 474 end 475 475 else 476 include(UnwantedNego, Nation);476 Include(UnwantedNego, Nation); 477 477 if NegoTime = BeginOfTurn then 478 478 begin … … 483 483 end 484 484 else 485 break;485 Break; 486 486 until False; 487 487 if RO.Happened and phTech <> 0 then … … 499 499 end; 500 500 end; 501 Server(sSetResearch, me, NewResearch, nodata^);501 Server(sSetResearch, Me, NewResearch, nodata^); 502 502 end; 503 if Server(sTurn, me, 0, nodata^) < rExecuted then504 assert(False);503 if Server(sTurn, Me, 0, nodata^) < rExecuted then 504 Assert(False); 505 505 end; 506 506 scContact: 507 if WantNegotiation( integer(Data), EnemyCalled) then507 if WantNegotiation(Integer(Data), EnemyCalled) then 508 508 begin 509 if Server(scDipStart, me, 0, nodata^) < rExecuted then510 assert(False);511 Opponent := integer(Data);509 if Server(scDipStart, Me, 0, nodata^) < rExecuted then 510 Assert(False); 511 Opponent := Integer(Data); 512 512 MyAction := scDipStart; 513 513 end 514 514 else 515 515 begin 516 if Server(scReject, me, 0, nodata^) < rExecuted then517 assert(False);516 if Server(scReject, Me, 0, nodata^) < rExecuted then 517 Assert(False); 518 518 end; 519 519 scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak: … … 538 538 end; 539 539 DoNegotiation; 540 assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or540 Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or 541 541 (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak)); 542 542 if MyAction = scDipOffer then 543 Server(MyAction, me, 0, MyOffer)543 Server(MyAction, Me, 0, MyOffer) 544 544 else 545 Server(MyAction, me, 0, nodata^);545 Server(MyAction, Me, 0, nodata^); 546 546 end; 547 547 cShowEndContact: … … 568 568 569 569 procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo; 570 ToLoc, EndHealth, EndHealthDef: integer);571 begin 572 end; 573 574 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);570 ToLoc, EndHealth, EndHealthDef: Integer); 571 begin 572 end; 573 574 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); 575 575 begin 576 576 end; … … 584 584 end; 585 585 586 function TCustomAI.ChooseResearchAdvance: integer;586 function TCustomAI.ChooseResearchAdvance: Integer; 587 587 begin 588 588 Result := -1; 589 589 end; 590 590 591 function TCustomAI.ChooseStealAdvance: integer;591 function TCustomAI.ChooseStealAdvance: Integer; 592 592 begin 593 593 Result := -1; 594 594 end; 595 595 596 function TCustomAI.ChooseGovernment: integer;596 function TCustomAI.ChooseGovernment: Integer; 597 597 begin 598 598 Result := gDespotism; 599 599 end; 600 600 601 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;601 function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 602 602 begin 603 603 Result := False; 604 604 end; 605 605 606 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;606 function TCustomAI.OnNegoRejected_CancelTreaty: Boolean; 607 607 begin 608 608 Result := False; … … 613 613 procedure TCustomAI.StealAdvance; 614 614 var 615 Steal, ad, Count: integer;615 Steal, ad, Count: Integer; 616 616 begin 617 617 Steal := ChooseStealAdvance; … … 628 628 end; 629 629 if Steal >= 0 then 630 Server(sStealTech, me, Steal, nodata^);630 Server(sStealTech, Me, Steal, nodata^); 631 631 RO.Happened := RO.Happened and not phStealTech; 632 632 end; 633 633 634 function TCustomAI.IsResearched(Advance: integer): boolean;634 function TCustomAI.IsResearched(Advance: Integer): Boolean; 635 635 begin 636 636 Result := (Advance = preNone) or (Advance <> preNA) and (RO.Tech[Advance] >= tsApplicable); 637 637 end; 638 638 639 function TCustomAI.ResearchCost: integer;640 begin 641 Server(sGetTechCost, me, 0, Result);642 end; 643 644 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;645 begin 646 Result := Server(sSetAttitude + Nation shl 4, me, Attitude, nodata^);647 end; 648 649 function TCustomAI.Revolution: integer;650 begin 651 Result := Server(sRevolution, me, 0, nodata^);652 end; 653 654 function TCustomAI.ChangeRates(Tax, Lux: integer): integer;655 begin 656 Result := Server(sSetRates, me, Tax div 10 and $f + Lux div 10 and $fshl 4, nodata^);657 end; 658 659 function TCustomAI.PrepareNewModel(Domain: integer): integer;660 begin 661 Result := Server(sCreateDevModel, me, Domain, nodata^);662 end; 663 664 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;665 begin 666 Result := Server(sSetDevModelCap + Count shl 4, me, F, nodata^);667 end; 668 669 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;670 begin 671 Result := Server(sSetResearch - sExecute, me, Advance, nodata^) >= rExecuted;672 end; 673 674 function TCustomAI.AdvanceStealable(Advance: integer): boolean;675 begin 676 Result := Server(sStealTech - sExecute, me, Advance, nodata^) >= rExecuted;677 end; 678 679 function TCustomAI.GetJobProgress(Loc: integer;680 var JobProgress: TJobProgressData): boolean;681 begin 682 Result := Server(sGetJobProgress, me, Loc, JobProgress) >= rExecuted;683 end; 684 685 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;686 begin 687 Text := copy('P' + char(48 + me) + ' ' + Text, 1, 254);688 Server(sMessage, me, Level, PChar(Text)^);639 function TCustomAI.ResearchCost: Integer; 640 begin 641 Server(sGetTechCost, Me, 0, Result); 642 end; 643 644 function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer; 645 begin 646 Result := Server(sSetAttitude + Nation shl 4, Me, Attitude, nodata^); 647 end; 648 649 function TCustomAI.Revolution: Integer; 650 begin 651 Result := Server(sRevolution, Me, 0, nodata^); 652 end; 653 654 function TCustomAI.ChangeRates(Tax, Lux: Integer): Integer; 655 begin 656 Result := Server(sSetRates, Me, Tax div 10 and $F + Lux div 10 and $F shl 4, nodata^); 657 end; 658 659 function TCustomAI.PrepareNewModel(Domain: Integer): Integer; 660 begin 661 Result := Server(sCreateDevModel, Me, Domain, nodata^); 662 end; 663 664 function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer; 665 begin 666 Result := Server(sSetDevModelCap + Count shl 4, Me, F, nodata^); 667 end; 668 669 function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean; 670 begin 671 Result := Server(sSetResearch - sExecute, Me, Advance, nodata^) >= rExecuted; 672 end; 673 674 function TCustomAI.AdvanceStealable(Advance: Integer): Boolean; 675 begin 676 Result := Server(sStealTech - sExecute, Me, Advance, nodata^) >= rExecuted; 677 end; 678 679 function TCustomAI.GetJobProgress(Loc: Integer; 680 var JobProgress: TJobProgressData): Boolean; 681 begin 682 Result := Server(sGetJobProgress, Me, Loc, JobProgress) >= rExecuted; 683 end; 684 685 function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean; 686 begin 687 Text := Copy('P' + char(48 + Me) + ' ' + Text, 1, 254); 688 Server(sMessage, Me, Level, PChar(Text)^); 689 689 690 690 Result := True; … … 693 693 end; 694 694 695 function TCustomAI.SetDebugMap(var DebugMap): boolean;696 begin 697 Server(sSetDebugMap, me, 0, DebugMap);695 function TCustomAI.SetDebugMap(var DebugMap): Boolean; 696 begin 697 Server(sSetDebugMap, Me, 0, DebugMap); 698 698 699 699 Result := True; … … 702 702 end; 703 703 704 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);705 begin 706 if Server(sGetDefender, me, Loc, uix) < rExecuted then704 procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer); 705 begin 706 if Server(sGetDefender, Me, Loc, uix) < rExecuted then 707 707 uix := -1; 708 708 end; 709 709 710 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);710 procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer); 711 711 begin 712 712 euix := RO.nEnemyUn - 1; … … 715 715 end; 716 716 717 function TCustomAI.Unit_Move(uix, ToLoc: integer): integer;718 var 719 Step: integer;720 DestinationReached: boolean;717 function TCustomAI.Unit_Move(uix, ToLoc: Integer): Integer; 718 var 719 Step: Integer; 720 DestinationReached: Boolean; 721 721 Advice: TMoveAdviceData; 722 722 begin 723 assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit723 Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit 724 724 {Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b); 725 assert((a<>0) or (b<>0));726 if ( a>=-1) and (a<=1) and (b>=-1) and (b<=1) then725 Assert((A<>0) or (B<>0)); 726 if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then 727 727 begin // move to adjacent tile 728 !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)728 !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay) 729 729 Advice.nStep:=1; 730 Advice.dx[0]:= a-b;731 Advice.dy[0]:= a+b;730 Advice.dx[0]:=A-B; 731 Advice.dy[0]:=A+B; 732 732 Advice.MoreTurns:=0; 733 733 Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement; 734 result:=eOK;734 Result:=eOK; 735 735 end 736 736 else} … … 739 739 Advice.MoreTurns := 9999; 740 740 Advice.MaxHostile_MovementLeft := 100; 741 Result := Server(sGetMoveAdvice, me, uix, Advice);741 Result := Server(sGetMoveAdvice, Me, uix, Advice); 742 742 end; 743 743 if Result = eOk then … … 755 755 begin 756 756 DestinationReached := True; 757 break;757 Break; 758 758 end // stop next to destination 759 759 else if Step = Advice.nStep then … … 761 761 762 762 if (Step = Advice.nStep) or (Result <> eOK) and (Result <> eLoaded) then 763 break;763 Break; 764 764 765 765 Result := Server(sMoveUnit + (Advice.dx[Step] and 7) shl 4 + 766 (Advice.dy[Step] and 7) shl 7, me, uix, nodata^);766 (Advice.dy[Step] and 7) shl 7, Me, uix, nodata^); 767 767 Inc(Step); 768 768 if RO.Happened and phStealTech <> 0 then … … 779 779 end; 780 780 781 function TCustomAI.Unit_Step(uix, ToLoc: integer): integer;782 var 783 a, b: integer;784 begin 785 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);786 assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b<= 1));787 Result := Server(sMoveUnit + (( a - b) and 7) shl 4 + ((a + b) and 7) shl 7, me, uix, nodata^);781 function TCustomAI.Unit_Step(uix, ToLoc: Integer): Integer; 782 var 783 A, B: Integer; 784 begin 785 Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B); 786 Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1)); 787 Result := Server(sMoveUnit + ((A - B) and 7) shl 4 + ((A + B) and 7) shl 7, Me, uix, nodata^); 788 788 if RO.Happened and phStealTech <> 0 then 789 789 StealAdvance; 790 790 end; 791 791 792 function TCustomAI.Unit_Attack(uix, ToLoc: integer): integer;793 var 794 a, b: integer;795 begin 796 assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit792 function TCustomAI.Unit_Attack(uix, ToLoc: Integer): Integer; 793 var 794 A, B: Integer; 795 begin 796 Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit 797 797 and ((Map[ToLoc] and (fUnit or fOwned) = fUnit) // is an attack 798 798 or (Map[ToLoc] and (fCity or fOwned) = fCity) and 799 799 (MyModel[MyUnit[uix].mix].Domain <> dGround))); // is a bombardment 800 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);801 assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b<= 1));800 Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B); 801 Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1)); 802 802 // attack to adjacent tile 803 Result := Server(sMoveUnit + ( a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);804 end; 805 806 function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: integer): integer;807 var 808 a, b: integer;809 begin 810 Result := Server(sSetSpyMission + MissionType shl 4, me, 0, nodata^);803 Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^); 804 end; 805 806 function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer; 807 var 808 A, B: Integer; 809 begin 810 Result := Server(sSetSpyMission + MissionType shl 4, Me, 0, nodata^); 811 811 if Result >= rExecuted then 812 812 begin 813 assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit813 Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit 814 814 and (MyModel[MyUnit[uix].mix].Kind = mkDiplomat)); // is a commando 815 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);816 assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b<= 1));815 Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B); 816 Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1)); 817 817 // city must be adjacent 818 Result := Server(sMoveUnit - sExecute + ( a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);818 Result := Server(sMoveUnit - sExecute + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^); 819 819 if Result = eMissionDone then 820 Result := Server(sMoveUnit + ( a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^)820 Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^) 821 821 else if (Result <> eNoTime_Move) and (Result <> eTreaty) and (Result <> eNoTurn) then 822 822 Result := eInvalid; // not a special commando mission! … … 824 824 end; 825 825 826 function TCustomAI.Unit_MoveForecast(uix, ToLoc: integer;827 var RemainingMovement: integer): boolean;826 function TCustomAI.Unit_MoveForecast(uix, ToLoc: Integer; 827 var RemainingMovement: Integer): Boolean; 828 828 var 829 829 Advice: TMoveAdviceData; 830 830 begin 831 assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit831 Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit 832 832 Advice.ToLoc := ToLoc; 833 833 Advice.MoreTurns := 0; 834 834 Advice.MaxHostile_MovementLeft := 100; 835 if Server(sGetMoveAdvice, me, uix, Advice) = eOk then835 if Server(sGetMoveAdvice, Me, uix, Advice) = eOk then 836 836 begin 837 837 RemainingMovement := Advice.MaxHostile_MovementLeft; … … 846 846 847 847 // negative RemainingHealth is remaining helth of defender if lost 848 function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;849 var RemainingHealth: integer): boolean;848 function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer; 849 var RemainingHealth: Integer): Boolean; 850 850 var 851 851 BattleForecast: TBattleForecast; 852 852 begin 853 assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit853 Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit 854 854 and (Map[ToLoc] and (fUnit or fOwned) = fUnit)); // is an attack 855 855 RemainingHealth := -$100; … … 858 858 with MyUnit[uix] do 859 859 begin 860 BattleForecast.pAtt := me;860 BattleForecast.pAtt := Me; 861 861 BattleForecast.mixAtt := mix; 862 862 BattleForecast.HealthAtt := Health; … … 864 864 BattleForecast.FlagsAtt := Flags; 865 865 BattleForecast.Movement := AttackMovement; 866 if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then866 if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then 867 867 begin 868 868 if BattleForecast.EndHealthAtt > 0 then … … 875 875 end; 876 876 877 function TCustomAI.Unit_DefenseForecast(euix, ToLoc: integer;878 var RemainingHealth: integer): boolean;877 function TCustomAI.Unit_DefenseForecast(euix, ToLoc: Integer; 878 var RemainingHealth: Integer): Boolean; 879 879 var 880 880 BattleForecast: TBattleForecast; 881 881 begin 882 assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit882 Assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit 883 883 and (Map[ToLoc] and (fUnit or fOwned) = (fUnit or fOwned))); // is an attack 884 884 RemainingHealth := $100; … … 892 892 BattleForecast.FlagsAtt := Flags; 893 893 BattleForecast.Movement := 100; 894 if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then894 if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then 895 895 begin 896 896 if BattleForecast.EndHealthDef > 0 then … … 903 903 end; 904 904 905 function TCustomAI.Unit_Disband(uix: integer): integer;906 begin 907 Result := Server(sRemoveUnit, me, uix, nodata^);908 end; 909 910 function TCustomAI.Unit_StartJob(uix, NewJob: integer): integer;911 begin 912 Result := Server(sStartJob + NewJob shl 4, me, uix, nodata^);913 end; 914 915 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;916 begin 917 Result := Server(sSetUnitHome, me, uix, nodata^);918 end; 919 920 function TCustomAI.Unit_Load(uix: integer): integer;921 begin 922 Result := Server(sLoadUnit, me, uix, nodata^);923 end; 924 925 function TCustomAI.Unit_Unload(uix: integer): integer;926 begin 927 Result := Server(sUnloadUnit, me, uix, nodata^);928 end; 929 930 function TCustomAI.Unit_AddToCity(uix: integer): integer;931 begin 932 Result := Server(sAddToCity, me, uix, nodata^);933 end; 934 935 function TCustomAI.Unit_SelectTransport(uix: integer): integer;936 begin 937 Result := Server(sSelectTransport, me, uix, nodata^);938 end; 939 940 941 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);905 function TCustomAI.Unit_Disband(uix: Integer): Integer; 906 begin 907 Result := Server(sRemoveUnit, Me, uix, nodata^); 908 end; 909 910 function TCustomAI.Unit_StartJob(uix, NewJob: Integer): Integer; 911 begin 912 Result := Server(sStartJob + NewJob shl 4, Me, uix, nodata^); 913 end; 914 915 function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer; 916 begin 917 Result := Server(sSetUnitHome, Me, uix, nodata^); 918 end; 919 920 function TCustomAI.Unit_Load(uix: Integer): Integer; 921 begin 922 Result := Server(sLoadUnit, Me, uix, nodata^); 923 end; 924 925 function TCustomAI.Unit_Unload(uix: Integer): Integer; 926 begin 927 Result := Server(sUnloadUnit, Me, uix, nodata^); 928 end; 929 930 function TCustomAI.Unit_AddToCity(uix: Integer): Integer; 931 begin 932 Result := Server(sAddToCity, Me, uix, nodata^); 933 end; 934 935 function TCustomAI.Unit_SelectTransport(uix: Integer): Integer; 936 begin 937 Result := Server(sSelectTransport, Me, uix, nodata^); 938 end; 939 940 941 procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer); 942 942 begin 943 943 if Map[Loc] and (fCity or fOwned) <> fCity or fOwned then … … 951 951 end; 952 952 953 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);953 procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer); 954 954 begin 955 955 if Map[Loc] and (fCity or fOwned) <> fCity then … … 963 963 end; 964 964 965 function TCustomAI.City_HasProject(cix: integer): boolean;965 function TCustomAI.City_HasProject(cix: Integer): Boolean; 966 966 begin 967 967 Result := MyCity[cix].Project and (cpImp + cpIndex) <> cpImp + imTrGoods; 968 968 end; 969 969 970 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;970 function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer; 971 971 begin 972 972 if MyCity[cix].Project and cpImp = 0 then … … 980 980 end; 981 981 982 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;982 function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer; 983 983 begin 984 984 if MyCity[cix].Project and cpImp <> 0 then … … 988 988 end; 989 989 990 function TCustomAI.City_GetTileInfo(cix, TileLoc: integer;991 var TileInfo: TTileInfo): integer;990 function TCustomAI.City_GetTileInfo(cix, TileLoc: Integer; 991 var TileInfo: TTileInfo): Integer; 992 992 begin 993 993 TileInfo.ExplCity := cix; 994 Result := Server(sGetHypoCityTileInfo, me, TileLoc, TileInfo);995 end; 996 997 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;994 Result := Server(sGetHypoCityTileInfo, Me, TileLoc, TileInfo); 995 end; 996 997 function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer; 998 998 begin 999 999 Report.HypoTiles := -1; 1000 1000 Report.HypoTax := -1; 1001 1001 Report.HypoLux := -1; 1002 Result := Server(sGetCityReport, me, cix, Report);1003 end; 1004 1005 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;1006 var Report: TCityReport): integer;1002 Result := Server(sGetCityReport, Me, cix, Report); 1003 end; 1004 1005 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; 1006 var Report: TCityReport): Integer; 1007 1007 begin 1008 1008 Report.HypoTiles := HypoTiles; 1009 1009 Report.HypoTax := HypoTax; 1010 1010 Report.HypoLux := HypoLux; 1011 Result := Server(sGetCityReport, me, cix, Report);1012 end; 1013 1014 function TCustomAI.City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;1011 Result := Server(sGetCityReport, Me, cix, Report); 1012 end; 1013 1014 function TCustomAI.City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer; 1015 1015 begin 1016 1016 Report.HypoTiles := -1; 1017 1017 Report.HypoTaxRate := -1; 1018 1018 Report.HypoLuxuryRate := -1; 1019 Result := Server(sGetCityReportNew, me, cix, Report);1019 Result := Server(sGetCityReportNew, Me, cix, Report); 1020 1020 end; 1021 1021 1022 1022 function TCustomAI.City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, 1023 HypoLuxuryRate: integer; var Report: TCityReportNew): integer;1023 HypoLuxuryRate: Integer; var Report: TCityReportNew): Integer; 1024 1024 begin 1025 1025 Report.HypoTiles := HypoTiles; 1026 1026 Report.HypoTaxRate := HypoTaxRate; 1027 1027 Report.HypoLuxuryRate := HypoLuxuryRate; 1028 Result := Server(sGetCityReportNew, me, cix, Report);1029 end; 1030 1031 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;1032 begin 1033 Result := Server(sGetCityAreaInfo, me, cix, AreaInfo);1034 end; 1035 1036 function TCustomAI.City_StartUnitProduction(cix, mix: integer): integer;1028 Result := Server(sGetCityReportNew, Me, cix, Report); 1029 end; 1030 1031 function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer; 1032 begin 1033 Result := Server(sGetCityAreaInfo, Me, cix, AreaInfo); 1034 end; 1035 1036 function TCustomAI.City_StartUnitProduction(cix, mix: Integer): Integer; 1037 1037 begin 1038 1038 if (MyCity[cix].Project and (cpImp + cpIndex) <> mix) then 1039 1039 // not already producing that 1040 Result := Server(sSetCityProject, me, cix, mix);1041 end; 1042 1043 function TCustomAI.City_StartEmigration(cix, mix: integer;1044 AllowDisbandCity, AsConscripts: boolean): integer;1045 var 1046 NewProject: integer;1040 Result := Server(sSetCityProject, Me, cix, mix); 1041 end; 1042 1043 function TCustomAI.City_StartEmigration(cix, mix: Integer; 1044 AllowDisbandCity, AsConscripts: Boolean): Integer; 1045 var 1046 NewProject: Integer; 1047 1047 begin 1048 1048 NewProject := mix; … … 1051 1051 if AsConscripts then 1052 1052 NewProject := NewProject or cpConscripts; 1053 Result := Server(sSetCityProject, me, cix, NewProject);1054 end; 1055 1056 function TCustomAI.City_StartImprovement(cix, iix: integer): integer;1057 var 1058 NewProject: integer;1053 Result := Server(sSetCityProject, Me, cix, NewProject); 1054 end; 1055 1056 function TCustomAI.City_StartImprovement(cix, iix: Integer): Integer; 1057 var 1058 NewProject: Integer; 1059 1059 begin 1060 1060 NewProject := iix + cpImp; 1061 1061 if (MyCity[cix].Project and (cpImp + cpIndex) <> NewProject) then 1062 1062 // not already producing that 1063 Result := Server(sSetCityProject, me, cix, NewProject);1064 end; 1065 1066 function TCustomAI.City_Improvable(cix, iix: integer): boolean;1067 var 1068 NewProject: integer;1063 Result := Server(sSetCityProject, Me, cix, NewProject); 1064 end; 1065 1066 function TCustomAI.City_Improvable(cix, iix: Integer): Boolean; 1067 var 1068 NewProject: Integer; 1069 1069 begin 1070 1070 NewProject := iix + cpImp; 1071 Result := Server(sSetCityProject - sExecute, me, cix, NewProject) >= rExecuted;1072 end; 1073 1074 function TCustomAI.City_StopProduction(cix: integer): integer;1075 var 1076 NewProject: integer;1071 Result := Server(sSetCityProject - sExecute, Me, cix, NewProject) >= rExecuted; 1072 end; 1073 1074 function TCustomAI.City_StopProduction(cix: Integer): Integer; 1075 var 1076 NewProject: Integer; 1077 1077 begin 1078 1078 NewProject := imTrGoods + cpImp; 1079 Result := Server(sSetCityProject, me, cix, NewProject);1080 end; 1081 1082 function TCustomAI.City_BuyProject(cix: integer): integer;1083 begin 1084 Result := Server(sBuyCityProject, me, cix, nodata^);1085 end; 1086 1087 function TCustomAI.City_SellImprovement(cix, iix: integer): integer;1088 begin 1089 Result := Server(sSellCityImprovement, me, cix, iix);1090 end; 1091 1092 function TCustomAI.City_RebuildImprovement(cix, iix: integer): integer;1093 begin 1094 Result := Server(sRebuildCityImprovement, me, cix, iix);1095 end; 1096 1097 function TCustomAI.City_SetTiles(cix, NewTiles: integer): integer;1098 begin 1099 Result := Server(sSetCityTiles, me, cix, NewTiles);1100 end; 1101 1102 procedure TCustomAI.City_OptimizeTiles(cix: integer; ResourceWeights: cardinal);1079 Result := Server(sSetCityProject, Me, cix, NewProject); 1080 end; 1081 1082 function TCustomAI.City_BuyProject(cix: Integer): Integer; 1083 begin 1084 Result := Server(sBuyCityProject, Me, cix, nodata^); 1085 end; 1086 1087 function TCustomAI.City_SellImprovement(cix, iix: Integer): Integer; 1088 begin 1089 Result := Server(sSellCityImprovement, Me, cix, iix); 1090 end; 1091 1092 function TCustomAI.City_RebuildImprovement(cix, iix: Integer): Integer; 1093 begin 1094 Result := Server(sRebuildCityImprovement, Me, cix, iix); 1095 end; 1096 1097 function TCustomAI.City_SetTiles(cix, NewTiles: Integer): Integer; 1098 begin 1099 Result := Server(sSetCityTiles, Me, cix, NewTiles); 1100 end; 1101 1102 procedure TCustomAI.City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal); 1103 1103 var 1104 1104 Advice: TCityTileAdviceData; 1105 1105 begin 1106 1106 Advice.ResourceWeights := ResourceWeights; 1107 Server(sGetCityTileAdvice, me, cix, Advice);1107 Server(sGetCityTileAdvice, Me, cix, Advice); 1108 1108 City_SetTiles(cix, Advice.Tiles); 1109 1109 end; … … 1111 1111 1112 1112 // negotiation 1113 function TCustomAI.Nego_CheckMyAction: integer;1114 begin 1115 assert(Opponent >= 0); // only allowed in negotiation mode1116 assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or1113 function TCustomAI.Nego_CheckMyAction: Integer; 1114 begin 1115 Assert(Opponent >= 0); // only allowed in negotiation mode 1116 Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or 1117 1117 (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak)); 1118 1118 if MyAction = scDipOffer then 1119 Result := Server(MyAction - sExecute, me, 0, MyOffer)1119 Result := Server(MyAction - sExecute, Me, 0, MyOffer) 1120 1120 else 1121 Result := Server(MyAction - sExecute, me, 0, nodata^);1121 Result := Server(MyAction - sExecute, Me, 0, nodata^); 1122 1122 end; 1123 1123 1124 1124 1125 1125 initialization 1126 nodata := pointer(0);1126 nodata := Pointer(0); 1127 1127 RWDataSize := 0; 1128 1128 -
trunk/AI/StdAI/CustomAI_Reload.pas
r160 r447 13 13 TCustomAI=class 14 14 public 15 procedure Process(Command: integer; var Data);15 procedure Process(Command: Integer; var Data); 16 16 17 17 // overridables 18 constructor Create(Nation: integer); virtual;18 constructor Create(Nation: Integer); virtual; 19 19 destructor Destroy; override; 20 20 procedure SetDataDefaults; virtual; 21 21 procedure SetDataRandom; virtual; 22 22 procedure OnBeforeEnemyAttack(UnitInfo: TUnitInfo; 23 ToLoc, EndHealth, EndHealthDef: integer); virtual;24 procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer); virtual;23 ToLoc, EndHealth, EndHealthDef: Integer); virtual; 24 procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); virtual; 25 25 procedure OnAfterEnemyAttack; virtual; 26 26 procedure OnAfterEnemyCapture; virtual; 27 27 28 28 protected 29 me: integer; // index of the controlled nation29 Me: Integer; // index of the controlled nation 30 30 RO: ^TPlayerContext; 31 31 Map: ^TTileList; … … 34 34 MyModel: ^TModelList; 35 35 36 cixStateImp: array[imPalace..imSpacePort] of integer;36 cixStateImp: array[imPalace..imSpacePort] of Integer; 37 37 38 38 // negotiation 39 Opponent: integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode40 MyAction, MyLastAction, OppoAction: integer;39 Opponent: Integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode 40 MyAction, MyLastAction, OppoAction: Integer; 41 41 MyOffer, MyLastOffer, OppoOffer: TOffer; 42 42 … … 44 44 procedure DoTurn; virtual; 45 45 procedure DoNegotiation; virtual; 46 function ChooseResearchAdvance: integer; virtual;47 function ChooseStealAdvance: integer; virtual;48 function ChooseGovernment: integer; virtual;49 function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; virtual;50 function OnNegoRejected_CancelTreaty: boolean; virtual;46 function ChooseResearchAdvance: Integer; virtual; 47 function ChooseStealAdvance: Integer; virtual; 48 function ChooseGovernment: Integer; virtual; 49 function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; virtual; 50 function OnNegoRejected_CancelTreaty: Boolean; virtual; 51 51 52 52 // general functions 53 function IsResearched(Advance: integer): boolean;54 function ResearchCost: integer;55 function ChangeAttitude(Nation, Attitude: integer): integer;56 function Revolution: integer;57 function ChangeRates(Tax,Lux: integer): integer;58 function PrepareNewModel(Domain: integer): integer;59 function SetNewModelFeature(F, Count: integer): integer;60 function AdvanceResearchable(Advance: integer): boolean;61 function AdvanceStealable(Advance: integer): boolean;62 function DebugMessage(Level: integer; Text: string): boolean;63 function SetDebugMap(var DebugMap): boolean;53 function IsResearched(Advance: Integer): Boolean; 54 function ResearchCost: Integer; 55 function ChangeAttitude(Nation, Attitude: Integer): Integer; 56 function Revolution: Integer; 57 function ChangeRates(Tax,Lux: Integer): Integer; 58 function PrepareNewModel(Domain: Integer): Integer; 59 function SetNewModelFeature(F, Count: Integer): Integer; 60 function AdvanceResearchable(Advance: Integer): Boolean; 61 function AdvanceStealable(Advance: Integer): Boolean; 62 function DebugMessage(Level: Integer; Text: string): Boolean; 63 function SetDebugMap(var DebugMap): Boolean; 64 64 65 65 // unit functions 66 procedure Unit_FindMyDefender(Loc: integer; var uix: integer);67 procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);68 function Unit_Move(uix,ToLoc: integer): integer;69 function Unit_Step(uix,ToLoc: integer): integer;70 function Unit_Attack(uix,ToLoc: integer): integer;71 function Unit_DoMission(uix,MissionType,ToLoc: integer): integer;72 function Unit_MoveForecast(uix,ToLoc: integer; var RemainingMovement: integer): boolean;73 function Unit_AttackForecast(uix,ToLoc,AttackMovement: integer; var RemainingHealth: integer): boolean;74 function Unit_DefenseForecast(euix,ToLoc: integer; var RemainingHealth: integer): boolean;75 function Unit_Disband(uix: integer): integer;76 function Unit_StartJob(uix,NewJob: integer): integer;77 function Unit_SetHomeHere(uix: integer): integer;78 function Unit_Load(uix: integer): integer;79 function Unit_Unload(uix: integer): integer;80 function Unit_AddToCity(uix: integer): integer;66 procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer); 67 procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer); 68 function Unit_Move(uix,ToLoc: Integer): Integer; 69 function Unit_Step(uix,ToLoc: Integer): Integer; 70 function Unit_Attack(uix,ToLoc: Integer): Integer; 71 function Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer; 72 function Unit_MoveForecast(uix,ToLoc: Integer; var RemainingMovement: Integer): Boolean; 73 function Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer; var RemainingHealth: Integer): Boolean; 74 function Unit_DefenseForecast(euix,ToLoc: Integer; var RemainingHealth: Integer): Boolean; 75 function Unit_Disband(uix: Integer): Integer; 76 function Unit_StartJob(uix,NewJob: Integer): Integer; 77 function Unit_SetHomeHere(uix: Integer): Integer; 78 function Unit_Load(uix: Integer): Integer; 79 function Unit_Unload(uix: Integer): Integer; 80 function Unit_AddToCity(uix: Integer): Integer; 81 81 82 82 // city functions 83 procedure City_FindMyCity(Loc: integer; var cix: integer);84 procedure City_FindEnemyCity(Loc: integer; var ecix: integer);85 function City_HasProject(cix: integer): boolean;86 function City_CurrentImprovementProject(cix: integer): integer;87 function City_CurrentUnitProject(cix: integer): integer;88 function City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;89 function City_GetReport(cix: integer; var Report: TCityReport): integer;90 function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer; var Report: TCityReport): integer;91 function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;92 function City_StartUnitProduction(cix,mix: integer): integer;93 function City_StartEmigration(cix,mix: integer; AllowDisbandCity, AsConscripts: boolean): integer;94 function City_StartImprovement(cix,iix: integer): integer;95 function City_Improvable(cix,iix: integer): boolean;96 function City_StopProduction(cix: integer): integer;97 function City_BuyProject(cix: integer): integer;98 function City_SellImprovement(cix,iix: integer): integer;99 function City_RebuildImprovement(cix,iix: integer): integer;100 function City_SetTiles(cix,NewTiles: integer): integer;83 procedure City_FindMyCity(Loc: Integer; var cix: Integer); 84 procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer); 85 function City_HasProject(cix: Integer): Boolean; 86 function City_CurrentImprovementProject(cix: Integer): Integer; 87 function City_CurrentUnitProject(cix: Integer): Integer; 88 function City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer; 89 function City_GetReport(cix: Integer; var Report: TCityReport): Integer; 90 function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; var Report: TCityReport): Integer; 91 function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer; 92 function City_StartUnitProduction(cix,mix: Integer): Integer; 93 function City_StartEmigration(cix,mix: Integer; AllowDisbandCity, AsConscripts: Boolean): Integer; 94 function City_StartImprovement(cix,iix: Integer): Integer; 95 function City_Improvable(cix,iix: Integer): Boolean; 96 function City_StopProduction(cix: Integer): Integer; 97 function City_BuyProject(cix: Integer): Integer; 98 function City_SellImprovement(cix,iix: Integer): Integer; 99 function City_RebuildImprovement(cix,iix: Integer): Integer; 100 function City_SetTiles(cix,NewTiles: Integer): Integer; 101 101 102 102 // negotiation 103 function Nego_CheckMyAction: integer;103 function Nego_CheckMyAction: Integer; 104 104 105 105 private 106 HaveTurned: boolean;106 HaveTurned: Boolean; 107 107 UnwantedNego: set of 0..nPl-1; 108 108 Contacted: set of 0..nPl-1; … … 114 114 Server: TServerCall; 115 115 G: TNewGameData; 116 RWDataSize, MapSize: integer;117 decompose24: cardinal;118 nodata: pointer;116 RWDataSize, MapSize: Integer; 117 decompose24: Cardinal; 118 nodata: Pointer; 119 119 120 120 const … … 126 126 127 127 type 128 TVicinity8Loc=array[0..7] of integer;129 TVicinity21Loc=array[0..27] of integer;128 TVicinity8Loc=array[0..7] of Integer; 129 TVicinity21Loc=array[0..27] of Integer; 130 130 131 131 132 132 procedure Init(NewGameData: TNewGameData); 133 133 134 procedure ab_to_Loc(Loc0, a,b: integer; var Loc: integer);135 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);136 procedure ab_to_V8( a,b: integer; var V8: integer);137 procedure V8_to_ab(V8: integer; var a,b: integer);138 procedure ab_to_V21( a,b: integer; var V21: integer);139 procedure V21_to_ab(V21: integer; var a,b: integer);140 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);141 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);134 procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer); 135 procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer); 136 procedure ab_to_V8(A,B: Integer; var V8: Integer); 137 procedure V8_to_ab(V8: Integer; var A,B: Integer); 138 procedure ab_to_V21(A,B: Integer; var V21: Integer); 139 procedure V21_to_ab(V21: Integer; var A,B: Integer); 140 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 141 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 142 142 143 143 … … 145 145 146 146 const 147 ab_v8: array[-4..4] of integer = (5,6,7,4,-1,0,3,2,1);148 v8_a: array[0..7] of integer = (1,1,0,-1,-1,-1,0,1);149 v8_b: array[0..7] of integer = (0,1,1,1,0,-1,-1,-1);150 151 152 procedure ab_to_Loc(Loc0, a,b: integer; var Loc: integer);147 ab_v8: array[-4..4] of Integer = (5,6,7,4,-1,0,3,2,1); 148 v8_a: array[0..7] of Integer = (1,1,0,-1,-1,-1,0,1); 149 v8_b: array[0..7] of Integer = (0,1,1,1,0,-1,-1,-1); 150 151 152 procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer); 153 153 {relative location from Loc0} 154 154 var 155 y0: integer;156 begin 157 assert((Loc0>=0) and (Loc0<MapSize) and (a-b+G.lx>=0));158 y0:= cardinal(Loc0)*decompose24 shr 24;159 Loc:=(Loc0+( a-b+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+a+b);155 y0: Integer; 156 begin 157 Assert((Loc0>=0) and (Loc0<MapSize) and (A-B+G.lx>=0)); 158 y0:=Cardinal(Loc0)*decompose24 shr 24; 159 Loc:=(Loc0+(A-B+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+A+B); 160 160 if Loc>=MapSize then Loc:=-$1000 161 161 end; 162 162 163 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);163 procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer); 164 164 {$IFDEF FPC} // freepascal 165 165 var 166 dx,dy: integer;166 dx,dy: Integer; 167 167 begin 168 168 dx:=((Loc mod G.lx *2 +Loc div G.lx and 1) 169 169 -(Loc0 mod G.lx *2 +Loc0 div G.lx and 1)+3*G.lx) mod (2*G.lx) -G.lx; 170 170 dy:=Loc div G.lx-Loc0 div G.lx; 171 a:=(dx+dy) div 2;172 b:=(dy-dx) div 2;171 A:=(dx+dy) div 2; 172 B:=(dy-dx) div 2; 173 173 end; 174 174 {$ELSE} // delphi … … 179 179 // calculate 180 180 push ecx 181 div byte ptr [G]181 div Byte ptr [G] 182 182 xor ebx,ebx 183 183 mov bl,ah // ebx:=Loc0 mod G.lx … … 185 185 and ecx,$000000FF // ecx:=Loc0 div G.lx 186 186 mov eax,edx 187 div byte ptr [G]187 div Byte ptr [G] 188 188 xor edx,edx 189 189 mov dl,ah // edx:=Loc mod G.lx … … 202 202 mov edx,dword ptr [G] 203 203 cmp eax,edx 204 jl @ a204 jl @A 205 205 sub eax,edx 206 206 sub eax,edx 207 207 jmp @ok 208 @ a:208 @A: 209 209 neg edx 210 210 cmp eax,edx … … 219 219 add eax,ebx 220 220 sar edx,1 // edx:=b 221 mov ebx,[ b]221 mov ebx,[B] 222 222 mov [ebx],edx 223 223 sar eax,1 // eax:=a 224 mov [ a],eax224 mov [A],eax 225 225 226 226 pop ebx … … 228 228 {$ENDIF} 229 229 230 procedure ab_to_V8( a,b: integer; var V8: integer);231 begin 232 assert((abs(a)<=1) and (abs(b)<=1) and ((a<>0) or (b<>0)));233 V8:=ab_v8[2* b+b+a];234 end; 235 236 procedure V8_to_ab(V8: integer; var a,b: integer);237 begin 238 a:=v8_a[V8]; b:=V8_b[V8];239 end; 240 241 procedure ab_to_V21( a,b: integer; var V21: integer);242 begin 243 V21:=( a+b+3) shl 2+(a-b+3) shr 1;244 end; 245 246 procedure V21_to_ab(V21: integer; var a,b: integer);247 var 248 dx,dy: integer;230 procedure ab_to_V8(A,B: Integer; var V8: Integer); 231 begin 232 Assert((abs(A)<=1) and (abs(B)<=1) and ((A<>0) or (B<>0))); 233 V8:=ab_v8[2*B+B+A]; 234 end; 235 236 procedure V8_to_ab(V8: Integer; var A,B: Integer); 237 begin 238 A:=v8_a[V8]; B:=V8_b[V8]; 239 end; 240 241 procedure ab_to_V21(A,B: Integer; var V21: Integer); 242 begin 243 V21:=(A+B+3) shl 2+(A-B+3) shr 1; 244 end; 245 246 procedure V21_to_ab(V21: Integer; var A,B: Integer); 247 var 248 dx,dy: Integer; 249 249 begin 250 250 dy:=V21 shr 2-3; 251 251 dx:=V21 and 3 shl 1 -3 + (dy+3) and 1; 252 a:=(dx+dy) div 2;253 b:=(dy-dx) div 2;254 end; 255 256 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);257 var 258 x0,y0,lx: integer;252 A:=(dx+dy) div 2; 253 B:=(dy-dx) div 2; 254 end; 255 256 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 257 var 258 x0,y0,lx: Integer; 259 259 begin 260 260 lx:=G.lx; 261 y0:= cardinal(Loc0)*decompose24 shr 24;261 y0:=Cardinal(Loc0)*decompose24 shr 24; 262 262 x0:=Loc0-y0*lx; // Loc0 mod lx; 263 263 VicinityLoc[1]:=Loc0+lx*2; … … 265 265 VicinityLoc[5]:=Loc0-lx*2; 266 266 VicinityLoc[7]:=Loc0+1; 267 inc(Loc0,y0 and 1);267 Inc(Loc0,y0 and 1); 268 268 VicinityLoc[0]:=Loc0+lx; 269 269 VicinityLoc[2]:=Loc0+lx-1; … … 276 276 if x0=0 then 277 277 begin 278 inc(VicinityLoc[3],lx);278 Inc(VicinityLoc[3],lx); 279 279 if y0 and 1=0 then 280 280 begin 281 inc(VicinityLoc[2],lx);282 inc(VicinityLoc[4],lx);281 Inc(VicinityLoc[2],lx); 282 Inc(VicinityLoc[4],lx); 283 283 end 284 284 end … … 286 286 else 287 287 begin 288 dec(VicinityLoc[7],lx);288 Dec(VicinityLoc[7],lx); 289 289 if y0 and 1=1 then 290 290 begin 291 dec(VicinityLoc[0],lx);292 dec(VicinityLoc[6],lx);291 Dec(VicinityLoc[0],lx); 292 Dec(VicinityLoc[6],lx); 293 293 end 294 294 end; … … 306 306 end; 307 307 308 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);309 var 310 dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: integer;311 dst: ^ integer;312 begin 313 y0:= cardinal(Loc0)*decompose24 shr 24;308 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 309 var 310 dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: Integer; 311 dst: ^Integer; 312 begin 313 y0:=Cardinal(Loc0)*decompose24 shr 24; 314 314 xComp0:=Loc0-y0*G.lx-1; // Loc0 mod G.lx -1 315 315 xCompSwitch:=xComp0-1+y0 and 1; 316 if xComp0<0 then inc(xComp0,G.lx);317 if xCompSwitch<0 then inc(xCompSwitch,G.lx);316 if xComp0<0 then Inc(xComp0,G.lx); 317 if xCompSwitch<0 then Inc(xCompSwitch,G.lx); 318 318 xCompSwitch:=xCompSwitch xor xComp0; 319 319 yComp:=G.lx*(y0-3); … … 329 329 if bit and $67F7F76<>0 then dst^:=xComp+yComp 330 330 else dst^:=-1; 331 inc(xComp);332 if xComp>=G.lx then dec(xComp, G.lx);333 inc(dst);331 Inc(xComp); 332 if xComp>=G.lx then Dec(xComp, G.lx); 333 Inc(dst); 334 334 bit:=bit shl 1; 335 335 end; 336 inc(yComp,G.lx);336 Inc(yComp,G.lx); 337 337 end 338 338 else 339 339 begin 340 340 for dx:=0 to 3 do 341 begin dst^:=-$1000; inc(dst); end;341 begin dst^:=-$1000; Inc(dst); end; 342 342 end 343 343 end; … … 345 345 346 346 procedure Init(NewGameData: TNewGameData); 347 {$IFDEF DEBUG}var Loc: integer;{$ENDIF}347 {$IFDEF DEBUG}var Loc: Integer;{$ENDIF} 348 348 begin 349 349 G:=NewGameData; 350 350 MapSize:=G.lx*G.ly; 351 351 decompose24:=(1 shl 24-1) div G.lx +1; 352 {$IFDEF DEBUG}for Loc:=0 to MapSize-1 do assert(cardinal(Loc)*decompose24 shr 24=cardinal(Loc div G.lx));{$ENDIF}353 end; 354 355 356 constructor TCustomAI.Create(Nation: integer);352 {$IFDEF DEBUG}for Loc:=0 to MapSize-1 do Assert(Cardinal(Loc)*decompose24 shr 24=Cardinal(Loc div G.lx));{$ENDIF} 353 end; 354 355 356 constructor TCustomAI.Create(Nation: Integer); 357 357 begin 358 358 inherited Create; 359 me:=Nation;360 RO:= pointer(G.RO[Nation]);361 Map:= pointer(RO.Map);362 MyUnit:= pointer(RO.Un);363 MyCity:= pointer(RO.City);364 MyModel:= pointer(RO.Model);359 Me:=Nation; 360 RO:=Pointer(G.RO[Nation]); 361 Map:=Pointer(RO.Map); 362 MyUnit:=Pointer(RO.Un); 363 MyCity:=Pointer(RO.City); 364 MyModel:=Pointer(RO.Model); 365 365 Opponent:=-1; 366 366 end; … … 368 368 destructor TCustomAI.Destroy; 369 369 begin 370 Server(sSetDebugMap, me,0,nodata^);371 end; 372 373 374 procedure TCustomAI.Process(Command: integer; var Data);375 var 376 Nation,NewResearch,NewGov,count,ad,cix,iix: integer;370 Server(sSetDebugMap,Me,0,nodata^); 371 end; 372 373 374 procedure TCustomAI.Process(Command: Integer; var Data); 375 var 376 Nation,NewResearch,NewGov,count,ad,cix,iix: Integer; 377 377 NegoTime: TNegoTime; 378 378 begin … … 380 380 cTurn, cContinue: 381 381 begin 382 if RO.Alive and (1 shl me)=0 then382 if RO.Alive and (1 shl Me)=0 then 383 383 begin // I'm dead, huhu 384 Server(sTurn, me,0,nodata^);385 exit384 Server(sTurn,Me,0,nodata^); 385 Exit 386 386 end; 387 387 if Command=cTurn then 388 388 begin 389 fillchar(cixStateImp, sizeof(cixStateImp), $FF);389 FillChar(cixStateImp, SizeOf(cixStateImp), $FF); 390 390 for cix:=0 to RO.nCity-1 do if MyCity[cix].Loc>=0 then 391 391 for iix:=imPalace to imSpacePort do … … 396 396 NewGov:=ChooseGovernment; 397 397 if NewGov>gAnarchy then 398 Server(sSetGovernment, me,NewGov,nodata^);398 Server(sSetGovernment,Me,NewGov,nodata^); 399 399 end; 400 HaveTurned:= false;400 HaveTurned:=False; 401 401 Contacted:=[]; 402 402 end; … … 405 405 if OnNegoRejected_CancelTreaty then 406 406 if RO.Treaty[Opponent]>=trPeace then 407 if Server(sCancelTreaty, me,0,nodata^)<rExecuted then408 assert(false)407 if Server(sCancelTreaty,Me,0,nodata^)<rExecuted then 408 Assert(False) 409 409 end 410 410 else UnwantedNego:=[]; … … 415 415 if RO.Government<>gAnarchy then 416 416 for Nation:=0 to nPl-1 do 417 if (Nation<> me) and (1 shl Nation and RO.Alive<>0)417 if (Nation<>Me) and (1 shl Nation and RO.Alive<>0) 418 418 and (RO.Treaty[Nation]>=trNone) 419 419 and not (Nation in Contacted) and not (Nation in UnwantedNego) 420 and (Server(scContact-sExecute + Nation shl 4, me, 0, nodata^)>=rExecuted) then420 and (Server(scContact-sExecute + Nation shl 4, Me, 0, nodata^)>=rExecuted) then 421 421 if WantNegotiation(Nation, NegoTime) then 422 422 begin 423 if Server(scContact + Nation shl 4, me, 0, nodata^)>=rExecuted then423 if Server(scContact + Nation shl 4, Me, 0, nodata^)>=rExecuted then 424 424 begin 425 include(Contacted, Nation);425 Include(Contacted, Nation); 426 426 Opponent:=Nation; 427 427 MyAction:=scContact; 428 exit;428 Exit; 429 429 end; 430 430 end 431 else include(UnwantedNego,Nation);431 else Include(UnwantedNego,Nation); 432 432 if NegoTime=BeginOfTurn then 433 433 begin 434 434 DoTurn; 435 HaveTurned:= true;435 HaveTurned:=True; 436 436 Contacted:=[]; 437 437 UnwantedNego:=[]; 438 438 end 439 else break;440 until false;439 else Break; 440 until False; 441 441 if RO.Happened and phTech<>0 then 442 442 begin … … 446 446 count:=0; 447 447 for ad:=0 to nAdv-1 do if AdvanceResearchable(ad) then 448 begin inc(count); if random(count)=0 then NewResearch:=ad end448 begin Inc(count); if random(count)=0 then NewResearch:=ad end 449 449 end; 450 Server(sSetResearch, me,NewResearch,nodata^)450 Server(sSetResearch,Me,NewResearch,nodata^) 451 451 end; 452 if ( me=1) and (RO.Turn=800) then452 if (Me=1) and (RO.Turn=800) then 453 453 begin 454 454 count:=0; 455 Server(sReload, me,0,count)455 Server(sReload,Me,0,count) 456 456 end 457 457 else if (RO.Turn>10) and (random(1000)=0) then 458 458 begin 459 459 count:=RO.Turn-10; 460 Server(sReload, me,0,count)460 Server(sReload,Me,0,count) 461 461 end 462 else if Server(sTurn, me,0,nodata^)<rExecuted then463 assert(false);462 else if Server(sTurn,Me,0,nodata^)<rExecuted then 463 Assert(False); 464 464 end; 465 465 scContact: 466 if WantNegotiation( integer(Data), EnemyCalled) then466 if WantNegotiation(Integer(Data), EnemyCalled) then 467 467 begin 468 if Server(scDipStart, me, 0, nodata^)<rExecuted then469 assert(false);470 Opponent:= integer(Data);468 if Server(scDipStart, Me, 0, nodata^)<rExecuted then 469 Assert(False); 470 Opponent:=Integer(Data); 471 471 MyAction:=scDipStart; 472 472 end 473 473 else 474 474 begin 475 if Server(scReject, me, 0, nodata^)<rExecuted then476 assert(false);475 if Server(scReject, Me, 0, nodata^)<rExecuted then 476 Assert(False); 477 477 end; 478 478 scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak: … … 486 486 else begin MyAction:=scDipOffer; MyOffer.nDeliver:=0; MyOffer.nCost:=0; end; 487 487 DoNegotiation; 488 assert((MyAction=scDipNotice) or (MyAction=scDipAccept)488 Assert((MyAction=scDipNotice) or (MyAction=scDipAccept) 489 489 or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer) 490 490 or (MyAction=scDipBreak)); 491 if MyAction=scDipOffer then Server(MyAction, me, 0, MyOffer)492 else Server(MyAction, me, 0, nodata^);491 if MyAction=scDipOffer then Server(MyAction, Me, 0, MyOffer) 492 else Server(MyAction, Me, 0, nodata^); 493 493 end; 494 494 cShowEndContact: … … 515 515 516 516 procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo; ToLoc, EndHealth, 517 EndHealthDef: integer);518 begin 519 end; 520 521 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);517 EndHealthDef: Integer); 518 begin 519 end; 520 521 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); 522 522 begin 523 523 end; … … 531 531 end; 532 532 533 function TCustomAI.ChooseResearchAdvance: integer;534 begin 535 result:=-1536 end; 537 538 function TCustomAI.ChooseStealAdvance: integer;539 begin 540 result:=-1541 end; 542 543 function TCustomAI.ChooseGovernment: integer;544 begin 545 result:=gDespotism546 end; 547 548 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;549 begin 550 result:=false;551 end; 552 553 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;554 begin 555 result:=false;533 function TCustomAI.ChooseResearchAdvance: Integer; 534 begin 535 Result:=-1 536 end; 537 538 function TCustomAI.ChooseStealAdvance: Integer; 539 begin 540 Result:=-1 541 end; 542 543 function TCustomAI.ChooseGovernment: Integer; 544 begin 545 Result:=gDespotism 546 end; 547 548 function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 549 begin 550 Result:=False; 551 end; 552 553 function TCustomAI.OnNegoRejected_CancelTreaty: Boolean; 554 begin 555 Result:=False; 556 556 end; 557 557 {$HINTS ON} … … 559 559 procedure TCustomAI.StealAdvance; 560 560 var 561 Steal, ad, count: integer;561 Steal, ad, count: Integer; 562 562 begin 563 563 Steal:=ChooseStealAdvance; … … 566 566 count:=0; 567 567 for ad:=0 to nAdv-1 do if AdvanceStealable(ad) then 568 begin inc(count); if random(count)=0 then Steal:=ad end568 begin Inc(count); if random(count)=0 then Steal:=ad end 569 569 end; 570 if Steal>=0 then Server(sStealTech, me,Steal,nodata^);570 if Steal>=0 then Server(sStealTech,Me,Steal,nodata^); 571 571 RO.Happened:=RO.Happened and not phStealTech 572 572 end; 573 573 574 function TCustomAI.IsResearched(Advance: integer): boolean;575 begin 576 result:= RO.Tech[Advance]>=tsApplicable577 end; 578 579 function TCustomAI.ResearchCost: integer;580 begin 581 Server(sGetTechCost, me,0,result)582 end; 583 584 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;585 begin 586 result:=Server(sSetAttitude+Nation shl 4,me,Attitude,nodata^)587 end; 588 589 function TCustomAI.Revolution: integer;590 begin 591 result:=Server(sRevolution,me,0,nodata^);592 end; 593 594 function TCustomAI.ChangeRates(Tax,Lux: integer): integer;595 begin 596 result:=Server(sSetRates,me,Tax div 10 and $f+Lux div 10 and $fshl 4,nodata^)597 end; 598 599 function TCustomAI.PrepareNewModel(Domain: integer): integer;600 begin 601 result:=Server(sCreateDevModel,me,Domain,nodata^);602 end; 603 604 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;605 begin 606 result:=Server(sSetDevModelCap+Count shl 4,me,F,nodata^)607 end; 608 609 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;610 begin 611 result:= Server(sSetResearch-sExecute,me,Advance,nodata^)>=rExecuted;612 end; 613 614 function TCustomAI.AdvanceStealable(Advance: integer): boolean;615 begin 616 result:= Server(sStealTech-sExecute,me,Advance,nodata^)>=rExecuted;617 end; 618 619 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;620 begin 621 Text:= copy('P'+char(48+me)+' '+Text,1,254);622 Server(sMessage, me,Level,pchar(Text)^);623 624 result:=true;574 function TCustomAI.IsResearched(Advance: Integer): Boolean; 575 begin 576 Result:= RO.Tech[Advance]>=tsApplicable 577 end; 578 579 function TCustomAI.ResearchCost: Integer; 580 begin 581 Server(sGetTechCost,Me,0,Result) 582 end; 583 584 function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer; 585 begin 586 Result:=Server(sSetAttitude+Nation shl 4,Me,Attitude,nodata^) 587 end; 588 589 function TCustomAI.Revolution: Integer; 590 begin 591 Result:=Server(sRevolution,Me,0,nodata^); 592 end; 593 594 function TCustomAI.ChangeRates(Tax,Lux: Integer): Integer; 595 begin 596 Result:=Server(sSetRates,Me,Tax div 10 and $F+Lux div 10 and $F shl 4,nodata^) 597 end; 598 599 function TCustomAI.PrepareNewModel(Domain: Integer): Integer; 600 begin 601 Result:=Server(sCreateDevModel,Me,Domain,nodata^); 602 end; 603 604 function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer; 605 begin 606 Result:=Server(sSetDevModelCap+Count shl 4,Me,F,nodata^) 607 end; 608 609 function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean; 610 begin 611 Result:= Server(sSetResearch-sExecute,Me,Advance,nodata^)>=rExecuted; 612 end; 613 614 function TCustomAI.AdvanceStealable(Advance: Integer): Boolean; 615 begin 616 Result:= Server(sStealTech-sExecute,Me,Advance,nodata^)>=rExecuted; 617 end; 618 619 function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean; 620 begin 621 Text:=Copy('P'+char(48+Me)+' '+Text,1,254); 622 Server(sMessage,Me,Level,PChar(Text)^); 623 624 Result:=True; 625 625 // always returns true so that it can be used like 626 626 // "assert(DebugMessage(...));" -> not compiled in release build 627 627 end; 628 628 629 function TCustomAI.SetDebugMap(var DebugMap): boolean;630 begin 631 Server(sSetDebugMap, me, 0, DebugMap);632 633 result:=true;629 function TCustomAI.SetDebugMap(var DebugMap): Boolean; 630 begin 631 Server(sSetDebugMap, Me, 0, DebugMap); 632 633 Result:=True; 634 634 // always returns true so that it can be used like 635 635 // "assert(SetDebugMap(...));" -> not compiled in release build 636 636 end; 637 637 638 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);639 begin 640 if Server(sGetDefender, me,Loc,uix)<rExecuted then uix:=-1641 end; 642 643 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);638 procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer); 639 begin 640 if Server(sGetDefender,Me,Loc,uix)<rExecuted then uix:=-1 641 end; 642 643 procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer); 644 644 begin 645 645 euix:=RO.nEnemyUn-1; 646 646 while (euix>=0) and (RO.EnemyUn[euix].Loc<>Loc) do 647 dec(euix);648 end; 649 650 function TCustomAI.Unit_Move(uix,ToLoc: integer): integer;651 var 652 Step: integer;653 DestinationReached: boolean;647 Dec(euix); 648 end; 649 650 function TCustomAI.Unit_Move(uix,ToLoc: Integer): Integer; 651 var 652 Step: Integer; 653 DestinationReached: Boolean; 654 654 Advice: TMoveAdviceData; 655 655 begin 656 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit656 Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit 657 657 {Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b); 658 assert((a<>0) or (b<>0));659 if ( a>=-1) and (a<=1) and (b>=-1) and (b<=1) then658 Assert((A<>0) or (B<>0)); 659 if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then 660 660 begin // move to adjacent tile 661 !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)661 !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay) 662 662 Advice.nStep:=1; 663 Advice.dx[0]:= a-b;664 Advice.dy[0]:= a+b;663 Advice.dx[0]:=A-B; 664 Advice.dy[0]:=A+B; 665 665 Advice.MoreTurns:=0; 666 666 Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement; 667 result:=eOK;667 Result:=eOK; 668 668 end 669 669 else} … … 672 672 Advice.MoreTurns:=9999; 673 673 Advice.MaxHostile_MovementLeft:=100; 674 result:=Server(sGetMoveAdvice,me,uix,Advice);674 Result:=Server(sGetMoveAdvice,Me,uix,Advice); 675 675 end; 676 if result=eOk then676 if Result=eOk then 677 677 begin 678 DestinationReached:= false;678 DestinationReached:=False; 679 679 Step:=0; 680 680 repeat 681 if result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached681 if Result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached 682 682 if (ToLoc>=0) and (Advice.MoreTurns=0) and (Step=Advice.nStep-1) 683 683 and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // attack … … 685 685 and ((MyModel[MyUnit[uix].mix].Domain<>dGround) // bombardment 686 686 or (MyModel[MyUnit[uix].mix].Flags and mdCivil<>0))) then // can't capture 687 begin DestinationReached:= true; break end // stop next to destination687 begin DestinationReached:=True; Break end // stop next to destination 688 688 else if Step=Advice.nStep then 689 DestinationReached:= true; // normal move -- stop at destination690 691 if (Step=Advice.nStep) or ( result<>eOK) and (result<>eLoaded) then692 break;693 694 result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7,695 me,uix,nodata^);696 inc(Step);689 DestinationReached:=True; // normal move -- stop at destination 690 691 if (Step=Advice.nStep) or (Result<>eOK) and (Result<>eLoaded) then 692 Break; 693 694 Result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7, 695 Me,uix,nodata^); 696 Inc(Step); 697 697 if RO.Happened and phStealTech<>0 then StealAdvance; 698 until false;698 until False; 699 699 if DestinationReached then 700 700 if Advice.nStep=25 then 701 result:=Unit_Move(uix,ToLoc) // Shinkansen701 Result:=Unit_Move(uix,ToLoc) // Shinkansen 702 702 else if Advice.MoreTurns=0 then 703 result:=result or rLocationReached704 else result:=result or rMoreTurns;705 end 706 end; 707 708 function TCustomAI.Unit_Step(uix,ToLoc: integer): integer;709 var 710 a,b: integer;711 begin 712 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);713 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1));714 result:=Server(sMoveUnit+((a-b) and 7) shl 4 +((a+b) and 7) shl 7, me, uix, nodata^);703 Result:=Result or rLocationReached 704 else Result:=Result or rMoreTurns; 705 end 706 end; 707 708 function TCustomAI.Unit_Step(uix,ToLoc: Integer): Integer; 709 var 710 A,B: Integer; 711 begin 712 Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B); 713 Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); 714 Result:=Server(sMoveUnit+((A-B) and 7) shl 4 +((A+B) and 7) shl 7, Me, uix, nodata^); 715 715 if RO.Happened and phStealTech<>0 then StealAdvance; 716 716 end; 717 717 718 function TCustomAI.Unit_Attack(uix,ToLoc: integer): integer;719 var 720 a,b: integer;721 begin 722 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit718 function TCustomAI.Unit_Attack(uix,ToLoc: Integer): Integer; 719 var 720 A,B: Integer; 721 begin 722 Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit 723 723 and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // is an attack 724 724 or (Map[ToLoc] and (fCity or fOwned)=fCity) 725 725 and (MyModel[MyUnit[uix].mix].Domain<>dGround))); // is a bombardment 726 Loc_to_ab(MyUnit[uix].Loc,ToLoc, a,b);727 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // attack to adjacent tile728 result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);729 end; 730 731 function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: integer): integer;732 var 733 a,b: integer;734 begin 735 result:=Server(sSetSpyMission + MissionType shl 4,me,0,nodata^);736 if result>=rExecuted then726 Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B); 727 Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // attack to adjacent tile 728 Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^); 729 end; 730 731 function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer; 732 var 733 A,B: Integer; 734 begin 735 Result:=Server(sSetSpyMission + MissionType shl 4,Me,0,nodata^); 736 if Result>=rExecuted then 737 737 begin 738 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit738 Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit 739 739 and (MyModel[MyUnit[uix].mix].Kind=mkDiplomat)); // is a commando 740 Loc_to_ab(MyUnit[uix].Loc,ToLoc, a,b);741 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // city must be adjacent742 result:=Server(sMoveUnit-sExecute+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);743 if result=eMissionDone then744 result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^)745 else if ( result<>eNoTime_Move) and (result<>eTreaty) and (result<>eNoTurn) then746 result:=eInvalid // not a special commando mission!747 end 748 end; 749 750 function TCustomAI.Unit_MoveForecast(uix,ToLoc: integer;751 var RemainingMovement: integer): boolean;740 Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B); 741 Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // city must be adjacent 742 Result:=Server(sMoveUnit-sExecute+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^); 743 if Result=eMissionDone then 744 Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^) 745 else if (Result<>eNoTime_Move) and (Result<>eTreaty) and (Result<>eNoTurn) then 746 Result:=eInvalid // not a special commando mission! 747 end 748 end; 749 750 function TCustomAI.Unit_MoveForecast(uix,ToLoc: Integer; 751 var RemainingMovement: Integer): Boolean; 752 752 var 753 753 Advice: TMoveAdviceData; 754 754 begin 755 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit755 Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit 756 756 Advice.ToLoc:=ToLoc; 757 757 Advice.MoreTurns:=0; 758 758 Advice.MaxHostile_MovementLeft:=100; 759 if Server(sGetMoveAdvice, me,uix,Advice)=eOk then759 if Server(sGetMoveAdvice,Me,uix,Advice)=eOk then 760 760 begin 761 761 RemainingMovement:=Advice.MaxHostile_MovementLeft; 762 result:=true762 Result:=True 763 763 end 764 764 else 765 765 begin 766 766 RemainingMovement:=-1; 767 result:=false768 end 769 end; 770 771 function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: integer;772 var RemainingHealth: integer): boolean;767 Result:=False 768 end 769 end; 770 771 function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer; 772 var RemainingHealth: Integer): Boolean; 773 773 var 774 774 BattleForecast: TBattleForecast; 775 775 begin 776 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit776 Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit 777 777 and (Map[ToLoc] and (fUnit or fOwned)=fUnit)); // is an attack 778 778 RemainingHealth:=-$100; 779 result:=false;779 Result:=False; 780 780 if AttackMovement>=0 then with MyUnit[uix] do 781 781 begin 782 BattleForecast.pAtt:= me;782 BattleForecast.pAtt:=Me; 783 783 BattleForecast.mixAtt:=mix; 784 784 BattleForecast.HealthAtt:=Health; … … 786 786 BattleForecast.FlagsAtt:=Flags; 787 787 BattleForecast.Movement:=AttackMovement; 788 if Server(sGetBattleForecast, me,ToLoc,BattleForecast)>=rExecuted then788 if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then 789 789 begin 790 790 if BattleForecast.EndHealthAtt>0 then 791 791 RemainingHealth:=BattleForecast.EndHealthAtt 792 792 else RemainingHealth:=-BattleForecast.EndHealthDef; 793 result:=true793 Result:=True 794 794 end 795 795 end 796 796 end; 797 797 798 function TCustomAI.Unit_DefenseForecast(euix,ToLoc: integer;799 var RemainingHealth: integer): boolean;798 function TCustomAI.Unit_DefenseForecast(euix,ToLoc: Integer; 799 var RemainingHealth: Integer): Boolean; 800 800 var 801 801 BattleForecast: TBattleForecast; 802 802 begin 803 assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit803 Assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit 804 804 and (Map[ToLoc] and (fUnit or fOwned)=(fUnit or fOwned))); // is an attack 805 805 RemainingHealth:=$100; 806 result:=false;806 Result:=False; 807 807 with RO.EnemyUn[euix] do 808 808 begin … … 813 813 BattleForecast.FlagsAtt:=Flags; 814 814 BattleForecast.Movement:=100; 815 if Server(sGetBattleForecast, me,ToLoc,BattleForecast)>=rExecuted then815 if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then 816 816 begin 817 817 if BattleForecast.EndHealthDef>0 then 818 818 RemainingHealth:=BattleForecast.EndHealthDef 819 819 else RemainingHealth:=-BattleForecast.EndHealthAtt; 820 result:=true820 Result:=True 821 821 end 822 822 end 823 823 end; 824 824 825 function TCustomAI.Unit_Disband(uix: integer): integer;826 begin 827 result:=Server(sRemoveUnit,me,uix,nodata^)828 end; 829 830 function TCustomAI.Unit_StartJob(uix,NewJob: integer): integer;831 begin 832 result:=Server(sStartJob+NewJob shl 4,me,uix,nodata^)833 end; 834 835 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;836 begin 837 result:=Server(sSetUnitHome,me,uix,nodata^)838 end; 839 840 function TCustomAI.Unit_Load(uix: integer): integer;841 begin 842 result:=Server(sLoadUnit,me,uix,nodata^)843 end; 844 845 function TCustomAI.Unit_Unload(uix: integer): integer;846 begin 847 result:=Server(sUnloadUnit,me,uix,nodata^)848 end; 849 850 function TCustomAI.Unit_AddToCity(uix: integer): integer;851 begin 852 result:=Server(sAddToCity,me,uix,nodata^)853 end; 854 855 856 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);825 function TCustomAI.Unit_Disband(uix: Integer): Integer; 826 begin 827 Result:=Server(sRemoveUnit,Me,uix,nodata^) 828 end; 829 830 function TCustomAI.Unit_StartJob(uix,NewJob: Integer): Integer; 831 begin 832 Result:=Server(sStartJob+NewJob shl 4,Me,uix,nodata^) 833 end; 834 835 function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer; 836 begin 837 Result:=Server(sSetUnitHome,Me,uix,nodata^) 838 end; 839 840 function TCustomAI.Unit_Load(uix: Integer): Integer; 841 begin 842 Result:=Server(sLoadUnit,Me,uix,nodata^) 843 end; 844 845 function TCustomAI.Unit_Unload(uix: Integer): Integer; 846 begin 847 Result:=Server(sUnloadUnit,Me,uix,nodata^) 848 end; 849 850 function TCustomAI.Unit_AddToCity(uix: Integer): Integer; 851 begin 852 Result:=Server(sAddToCity,Me,uix,nodata^) 853 end; 854 855 856 procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer); 857 857 begin 858 858 if Map[Loc] and (fCity or fOwned)<>fCity or fOwned then … … 862 862 cix:=RO.nCity-1; 863 863 while (cix>=0) and (MyCity[cix].Loc<>Loc) do 864 dec(cix);865 end 866 end; 867 868 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);864 Dec(cix); 865 end 866 end; 867 868 procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer); 869 869 begin 870 870 if Map[Loc] and (fCity or fOwned)<>fCity then … … 874 874 ecix:=RO.nEnemyCity-1; 875 875 while (ecix>=0) and (RO.EnemyCity[ecix].Loc<>Loc) do 876 dec(ecix);877 end 878 end; 879 880 function TCustomAI.City_HasProject(cix: integer): boolean;881 begin 882 result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods883 end; 884 885 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;886 begin 887 if MyCity[cix].Project and cpImp=0 then result:=-1876 Dec(ecix); 877 end 878 end; 879 880 function TCustomAI.City_HasProject(cix: Integer): Boolean; 881 begin 882 Result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods 883 end; 884 885 function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer; 886 begin 887 if MyCity[cix].Project and cpImp=0 then Result:=-1 888 888 else 889 889 begin 890 result:=MyCity[cix].Project and cpIndex;891 if result=imTrGoods then result:=-1892 end 893 end; 894 895 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;896 begin 897 if MyCity[cix].Project and cpImp<>0 then result:=-1898 else result:=MyCity[cix].Project and cpIndex;899 end; 900 901 function TCustomAI.City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;890 Result:=MyCity[cix].Project and cpIndex; 891 if Result=imTrGoods then Result:=-1 892 end 893 end; 894 895 function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer; 896 begin 897 if MyCity[cix].Project and cpImp<>0 then Result:=-1 898 else Result:=MyCity[cix].Project and cpIndex; 899 end; 900 901 function TCustomAI.City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer; 902 902 begin 903 903 TileInfo.ExplCity:=cix; 904 result:=Server(sGetHypoCityTileInfo,me,TileLoc,TileInfo)905 end; 906 907 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;904 Result:=Server(sGetHypoCityTileInfo,Me,TileLoc,TileInfo) 905 end; 906 907 function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer; 908 908 begin 909 909 Report.HypoTiles:=-1; 910 910 Report.HypoTax:=-1; 911 911 Report.HypoLux:=-1; 912 result:=Server(sGetCityReport,me,cix,Report)913 end; 914 915 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;916 var Report: TCityReport): integer;912 Result:=Server(sGetCityReport,Me,cix,Report) 913 end; 914 915 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; 916 var Report: TCityReport): Integer; 917 917 begin 918 918 Report.HypoTiles:=HypoTiles; 919 919 Report.HypoTax:=HypoTax; 920 920 Report.HypoLux:=HypoLux; 921 result:=Server(sGetCityReport,me,cix,Report)922 end; 923 924 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;925 begin 926 result:=Server(sGetCityAreaInfo,me,cix,AreaInfo)927 end; 928 929 function TCustomAI.City_StartUnitProduction(cix,mix: integer): integer;930 begin 931 result:=Server(sSetCityProject,me,cix,mix)932 end; 933 934 function TCustomAI.City_StartEmigration(cix,mix: integer;935 AllowDisbandCity, AsConscripts: boolean): integer;936 var 937 NewProject: integer;921 Result:=Server(sGetCityReport,Me,cix,Report) 922 end; 923 924 function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer; 925 begin 926 Result:=Server(sGetCityAreaInfo,Me,cix,AreaInfo) 927 end; 928 929 function TCustomAI.City_StartUnitProduction(cix,mix: Integer): Integer; 930 begin 931 Result:=Server(sSetCityProject,Me,cix,mix) 932 end; 933 934 function TCustomAI.City_StartEmigration(cix,mix: Integer; 935 AllowDisbandCity, AsConscripts: Boolean): Integer; 936 var 937 NewProject: Integer; 938 938 begin 939 939 NewProject:=mix; 940 940 if AllowDisbandCity then NewProject:=NewProject or cpDisbandCity; 941 941 if AsConscripts then NewProject:=NewProject or cpConscripts; 942 result:=Server(sSetCityProject,me,cix,NewProject)943 end; 944 945 function TCustomAI.City_StartImprovement(cix,iix: integer): integer;946 var 947 NewProject: integer;942 Result:=Server(sSetCityProject,Me,cix,NewProject) 943 end; 944 945 function TCustomAI.City_StartImprovement(cix,iix: Integer): Integer; 946 var 947 NewProject: Integer; 948 948 begin 949 949 NewProject:=iix+cpImp; 950 result:=Server(sSetCityProject,me,cix,NewProject)951 end; 952 953 function TCustomAI.City_Improvable(cix,iix: integer): boolean;954 var 955 NewProject: integer;950 Result:=Server(sSetCityProject,Me,cix,NewProject) 951 end; 952 953 function TCustomAI.City_Improvable(cix,iix: Integer): Boolean; 954 var 955 NewProject: Integer; 956 956 begin 957 957 NewProject:=iix+cpImp; 958 result:= Server(sSetCityProject-sExecute,me,cix,NewProject)>=rExecuted;959 end; 960 961 function TCustomAI.City_StopProduction(cix: integer): integer;962 var 963 NewProject: integer;958 Result:= Server(sSetCityProject-sExecute,Me,cix,NewProject)>=rExecuted; 959 end; 960 961 function TCustomAI.City_StopProduction(cix: Integer): Integer; 962 var 963 NewProject: Integer; 964 964 begin 965 965 NewProject:=imTrGoods+cpImp; 966 result:=Server(sSetCityProject,me,cix,NewProject)967 end; 968 969 function TCustomAI.City_BuyProject(cix: integer): integer;970 begin 971 result:=Server(sBuyCityProject,me,cix,nodata^)972 end; 973 974 function TCustomAI.City_SellImprovement(cix,iix: integer): integer;975 begin 976 result:=Server(sSellCityImprovement,me,cix,iix)977 end; 978 979 function TCustomAI.City_RebuildImprovement(cix,iix: integer): integer;980 begin 981 result:=Server(sRebuildCityImprovement,me,cix,iix)982 end; 983 984 function TCustomAI.City_SetTiles(cix,NewTiles: integer): integer;985 begin 986 result:=Server(sSetCityTiles,me,cix,NewTiles)966 Result:=Server(sSetCityProject,Me,cix,NewProject) 967 end; 968 969 function TCustomAI.City_BuyProject(cix: Integer): Integer; 970 begin 971 Result:=Server(sBuyCityProject,Me,cix,nodata^) 972 end; 973 974 function TCustomAI.City_SellImprovement(cix,iix: Integer): Integer; 975 begin 976 Result:=Server(sSellCityImprovement,Me,cix,iix) 977 end; 978 979 function TCustomAI.City_RebuildImprovement(cix,iix: Integer): Integer; 980 begin 981 Result:=Server(sRebuildCityImprovement,Me,cix,iix) 982 end; 983 984 function TCustomAI.City_SetTiles(cix,NewTiles: Integer): Integer; 985 begin 986 Result:=Server(sSetCityTiles,Me,cix,NewTiles) 987 987 end; 988 988 989 989 990 990 // negotiation 991 function TCustomAI.Nego_CheckMyAction: integer;992 begin 993 assert(Opponent>=0); // only allowed in negotiation mode994 assert((MyAction=scDipNotice) or (MyAction=scDipAccept)991 function TCustomAI.Nego_CheckMyAction: Integer; 992 begin 993 Assert(Opponent>=0); // only allowed in negotiation mode 994 Assert((MyAction=scDipNotice) or (MyAction=scDipAccept) 995 995 or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer) 996 996 or (MyAction=scDipBreak)); 997 if MyAction=scDipOffer then result:=Server(MyAction-sExecute, me, 0, MyOffer)998 else result:=Server(MyAction-sExecute, me, 0, nodata^);997 if MyAction=scDipOffer then Result:=Server(MyAction-sExecute, Me, 0, MyOffer) 998 else Result:=Server(MyAction-sExecute, Me, 0, nodata^); 999 999 end; 1000 1000 1001 1001 1002 1002 initialization 1003 nodata:= pointer(0);1003 nodata:=Pointer(0); 1004 1004 RWDataSize:=0; 1005 1005 -
trunk/AI/StdAI/Pile.pas
r289 r447 8 8 interface 9 9 10 procedure Create(Size: integer);10 procedure Create(Size: Integer); 11 11 procedure Free; 12 12 procedure Empty; 13 function Put(Item, Value: integer): boolean;14 function TestPut(Item, Value: integer): boolean;15 function Get(var Item, Value: integer): boolean;13 function Put(Item, Value: Integer): Boolean; 14 function TestPut(Item, Value: Integer): Boolean; 15 function Get(var Item, Value: Integer): Boolean; 16 16 17 17 … … 23 23 type 24 24 TheapItem = record 25 Item: integer;26 Value: integer;25 Item: Integer; 26 Value: Integer; 27 27 end; 28 28 29 29 var 30 30 bh: array[0..MaxSize - 1] of TheapItem; 31 Ix: array[0..MaxSize - 1] of integer;32 n, CurrentSize: integer;33 {$IFDEF DEBUG}InUse: boolean;{$ENDIF}31 Ix: array[0..MaxSize - 1] of Integer; 32 N, CurrentSize: Integer; 33 {$IFDEF DEBUG}InUse: Boolean;{$ENDIF} 34 34 35 35 36 procedure Create(Size: integer);36 procedure Create(Size: Integer); 37 37 begin 38 38 {$IFDEF DEBUG} 39 assert(not InUse, 'Pile is a single instance class, ' +39 Assert(not InUse, 'Pile is a single instance class, ' + 40 40 'no multiple usage possible. Always call Pile.Free after use.'); 41 41 {$ENDIF} 42 assert(Size <= MaxSize);43 if ( n<> 0) or (Size > CurrentSize) then42 Assert(Size <= MaxSize); 43 if (N <> 0) or (Size > CurrentSize) then 44 44 begin 45 FillChar(Ix, Size * sizeOf( integer), 255);46 n:= 0;45 FillChar(Ix, Size * sizeOf(Integer), 255); 46 N := 0; 47 47 end; 48 48 CurrentSize := Size; … … 55 55 begin 56 56 {$IFDEF DEBUG} 57 assert(InUse);57 Assert(InUse); 58 58 InUse := False; 59 59 {$ENDIF} … … 62 62 procedure Empty; 63 63 begin 64 if n<> 0 then64 if N <> 0 then 65 65 begin 66 FillChar(Ix, CurrentSize * sizeOf( integer), 255);67 n:= 0;66 FillChar(Ix, CurrentSize * sizeOf(Integer), 255); 67 N := 0; 68 68 end; 69 69 end; 70 70 71 71 //Parent(i) = (i-1)/2. 72 function Put(Item, Value: integer): boolean; //O(lg(n))72 function Put(Item, Value: Integer): Boolean; //O(lg(n)) 73 73 var 74 i, j: integer;74 I, J: Integer; 75 75 begin 76 assert(Item < CurrentSize);77 i:= Ix[Item];78 if i>= 0 then76 Assert(Item < CurrentSize); 77 I := Ix[Item]; 78 if I >= 0 then 79 79 begin 80 if bh[ i].Value <= Value then80 if bh[I].Value <= Value then 81 81 begin 82 82 Result := False; 83 exit;83 Exit; 84 84 end; 85 85 end 86 86 else 87 87 begin 88 i := n;89 Inc( n);88 I := N; 89 Inc(N); 90 90 end; 91 91 92 while i> 0 do92 while I > 0 do 93 93 begin 94 j := (i- 1) shr 1; //Parent(i) = (i-1)/295 if Value >= bh[ j].Value then96 break;97 bh[ i] := bh[j];98 Ix[bh[ i].Item] := i;99 i := j;94 J := (I - 1) shr 1; //Parent(i) = (i-1)/2 95 if Value >= bh[J].Value then 96 Break; 97 bh[I] := bh[J]; 98 Ix[bh[I].Item] := I; 99 I := J; 100 100 end; 101 101 // Insert the new Item at the insertion point found. 102 bh[ i].Value := Value;103 bh[ i].Item := Item;104 Ix[bh[ i].Item] := i;102 bh[I].Value := Value; 103 bh[I].Item := Item; 104 Ix[bh[I].Item] := I; 105 105 Result := True; 106 106 end; 107 107 108 function TestPut(Item, Value: integer): boolean;108 function TestPut(Item, Value: Integer): Boolean; 109 109 var 110 i: integer;110 I: Integer; 111 111 begin 112 assert(Item < CurrentSize);113 i:= Ix[Item];114 Result := ( i < 0) or (bh[i].Value > Value);112 Assert(Item < CurrentSize); 113 I := Ix[Item]; 114 Result := (I < 0) or (bh[I].Value > Value); 115 115 end; 116 116 117 117 //Left(i) = 2*i+1. 118 118 //Right(i) = 2*i+2 => Left(i)+1 119 function Get(var Item, Value: integer): boolean; //O(lg(n))119 function Get(var Item, Value: Integer): Boolean; //O(lg(n)) 120 120 var 121 i, j: integer;122 last: TheapItem;121 I, J: Integer; 122 Last: TheapItem; 123 123 begin 124 if n= 0 then124 if N = 0 then 125 125 begin 126 126 Result := False; 127 exit;127 Exit; 128 128 end; 129 129 … … 133 133 Ix[Item] := -1; 134 134 135 Dec( n);136 if n> 0 then135 Dec(N); 136 if N > 0 then 137 137 begin 138 last := bh[n];139 i:= 0;140 j:= 1;141 while j < ndo138 Last := bh[N]; 139 I := 0; 140 J := 1; 141 while J < N do 142 142 begin 143 143 // Right(i) = Left(i)+1 144 if ( j < n - 1) and (bh[j].Value > bh[j+ 1].Value) then145 Inc( j);146 if last.Value <= bh[j].Value then147 break;144 if (J < N - 1) and (bh[J].Value > bh[J + 1].Value) then 145 Inc(J); 146 if Last.Value <= bh[J].Value then 147 Break; 148 148 149 bh[ i] := bh[j];150 Ix[bh[ i].Item] := i;151 i := j;152 j := jshl 1 + 1; //Left(j) = 2*j+1149 bh[I] := bh[J]; 150 Ix[bh[I].Item] := I; 151 I := J; 152 J := J shl 1 + 1; //Left(j) = 2*j+1 153 153 end; 154 154 155 155 // Insert the root in the correct place in the heap. 156 bh[ i] := last;157 Ix[ last.Item] := i;156 bh[I] := Last; 157 Ix[Last.Item] := I; 158 158 end; 159 159 Result := True; … … 161 161 162 162 initialization 163 n:= 0;163 N := 0; 164 164 CurrentSize := 0; 165 165 {$IFDEF DEBUG} -
trunk/AI/StdAI/Protocol.pas
r328 r447 916 916 Cost: Integer; 917 917 Maint: Integer; 918 Expiration: integer;918 Expiration: Integer; 919 919 end 920 920 = ((Kind: ikWonder; Preq: adMathematics; Cost: 400; Maint: 0; … … 1120 1120 Strength: Integer; 1121 1121 Trans: Integer; 1122 Cost: integer;1122 Cost: Integer; 1123 1123 end 1124 1124 = (((Preq: adWarriorCode; Strength: 4; Trans: 0; Cost: 3), … … 1510 1510 TGetCityData = record 1511 1511 Owner: Integer; 1512 c: TCity;1512 C: TCity; 1513 1513 end; 1514 1514 … … 1591 1591 TCreateUnitData = record 1592 1592 Loc: Integer; 1593 p: Integer;1593 P: Integer; 1594 1594 mix: Integer; 1595 1595 end; … … 1600 1600 TOwnerList = array [0 .. INFIN] of ShortInt; 1601 1601 TByteList = array [0 .. INFIN] of Byte; 1602 TIntList = array [0 .. INFIN] of integer;1602 TIntList = array [0 .. INFIN] of Integer; 1603 1603 TCityList = array [0 .. INFIN] of TCity; 1604 1604 TUnList = array [0 .. INFIN] of TUn; … … 1761 1761 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); 1762 1762 1763 SpecialModelPreq: array [0 .. nSpecialModel - 1] of integer = (preNone,1763 SpecialModelPreq: array [0 .. nSpecialModel - 1] of Integer = (preNone, 1764 1764 adExplosives, preNone, preNone, (* adWri, *) adIntelligence, adTrade, 1765 1765 (* adTheCorporation,adHorsebackRiding,adAutomobile,adNavigation, … … 1770 1770 DelphiRandSeed: Integer; 1771 1771 1772 procedure MakeUnitInfo( p: Integer; const u: TUn; var ui: TUnitInfo);1773 procedure MakeModelInfo( p, mix: Integer; const m: TModel; var mi: TModelInfo);1772 procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo); 1773 procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo); 1774 1774 function IsSameModel(const mi1, mi2: TModelInfo): Boolean; 1775 1775 function SpecialTile(Loc, TerrType, lx: Integer): Integer; … … 1781 1781 implementation 1782 1782 1783 procedure MakeUnitInfo( p: Integer; const u: TUn; var ui: TUnitInfo);1783 procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo); 1784 1784 begin 1785 ui.Owner := p;1786 ui.Loc := u.Loc;1787 ui.Health := u.Health;1788 ui.Fuel := u.Fuel;1789 ui.Job := u.Job;1790 ui.Exp := u.Exp;1791 ui.Load := u.TroopLoad + u.AirLoad;1792 ui.mix := u.mix;1793 ui.Flags := u.Flags;1785 ui.Owner := P; 1786 ui.Loc := U.Loc; 1787 ui.Health := U.Health; 1788 ui.Fuel := U.Fuel; 1789 ui.Job := U.Job; 1790 ui.Exp := U.Exp; 1791 ui.Load := U.TroopLoad + U.AirLoad; 1792 ui.mix := U.mix; 1793 ui.Flags := U.Flags; 1794 1794 end; 1795 1795 1796 procedure MakeModelInfo( p, mix: Integer; const m: TModel; var mi: TModelInfo);1796 procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo); 1797 1797 var 1798 i: Integer;1798 I: Integer; 1799 1799 begin 1800 mi.Owner := p;1800 mi.Owner := P; 1801 1801 mi.mix := mix; 1802 mi.ID := m.ID;1803 mi.Domain := m.Domain;1804 if m.Kind = mkEnemyDeveloped then1802 mi.ID := M.ID; 1803 mi.Domain := M.Domain; 1804 if M.Kind = mkEnemyDeveloped then 1805 1805 mi.Kind := mkSelfDeveloped // important for IsSameModel() 1806 1806 else 1807 mi.Kind := m.Kind;1808 mi.Attack := m.Attack;1809 mi.Defense := m.Defense;1810 mi.Speed := m.Speed;1811 mi.Cost := m.Cost;1807 mi.Kind := M.Kind; 1808 mi.Attack := M.Attack; 1809 mi.Defense := M.Defense; 1810 mi.Speed := M.Speed; 1811 mi.Cost := M.Cost; 1812 1812 if mi.Domain = dAir then 1813 1813 begin 1814 mi.TTrans := m.Cap[mcAirTrans] * m.MTrans;1815 mi.ATrans_Fuel := m.Cap[mcFuel];1814 mi.TTrans := M.Cap[mcAirTrans] * M.MTrans; 1815 mi.ATrans_Fuel := M.Cap[mcFuel]; 1816 1816 end 1817 1817 else 1818 1818 begin 1819 mi.TTrans := m.Cap[mcSeaTrans] * m.MTrans;1820 mi.ATrans_Fuel := m.Cap[mcCarrier] * m.MTrans;1821 end; 1822 mi.Bombs := m.Cap[mcBombs] * m.MStrength * 2;1819 mi.TTrans := M.Cap[mcSeaTrans] * M.MTrans; 1820 mi.ATrans_Fuel := M.Cap[mcCarrier] * M.MTrans; 1821 end; 1822 mi.Bombs := M.Cap[mcBombs] * M.MStrength * 2; 1823 1823 mi.Cap := 0; 1824 for i:= mcFirstNonCap to nFeature - 1 do1825 if m.Cap[i] > 0 then1826 mi.Cap := mi.Cap or (1 shl ( i- mcFirstNonCap));1824 for I := mcFirstNonCap to nFeature - 1 do 1825 if M.Cap[I] > 0 then 1826 mi.Cap := mi.Cap or (1 shl (I - mcFirstNonCap)); 1827 1827 mi.MaxUpgrade := 0; 1828 for i:= 1 to nUpgrade - 1 do1829 if m.Upgrades and (1 shl i) <> 0 then1830 mi.MaxUpgrade := i;1831 mi.Weight := m.Weight;1828 for I := 1 to nUpgrade - 1 do 1829 if M.Upgrades and (1 shl I) <> 0 then 1830 mi.MaxUpgrade := I; 1831 mi.Weight := M.Weight; 1832 1832 mi.Lost := 0; 1833 1833 end; … … 1841 1841 Compare1 := @mi1; 1842 1842 Compare2 := @mi2; 1843 result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and1843 Result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and 1844 1844 (Compare1[2] = Compare2[2]) and (Compare1[3] = Compare2[3]) and 1845 1845 (Compare1[4] = Compare2[4]) and (Compare1[5] = Compare2[5]) … … 1848 1848 function SpecialTile(Loc, TerrType, lx: Integer): Integer; 1849 1849 var 1850 x, y, qx, qy, a: Integer;1850 X, Y, qx, qy, A: Integer; 1851 1851 begin 1852 1852 if TerrType = fOcean then 1853 result := 01853 Result := 0 1854 1854 else 1855 1855 begin 1856 y:= Loc div lx;1857 x := Loc - y* lx;1856 Y := Loc div lx; 1857 X := Loc - Y * lx; 1858 1858 if TerrType = fGrass then { formula for productive grassland } 1859 if Odd((lymax + x - y shr 1) shr 1 + x + (y+ 1) shr 1) then1860 result := 11859 if Odd((lymax + X - Y shr 1) shr 1 + X + (Y + 1) shr 1) then 1860 Result := 1 1861 1861 else 1862 result := 01862 Result := 0 1863 1863 else { formula for special resources } 1864 1864 begin 1865 a := 4 * x - y+ 9980;1866 qx := adiv 10;1867 if (qx * 10 = a) and (qx and 3 <> 0) then1865 A := 4 * X - Y + 9980; 1866 qx := A div 10; 1867 if (qx * 10 = A) and (qx and 3 <> 0) then 1868 1868 begin 1869 qy := ( y + x) div 5;1869 qy := (Y + X) div 5; 1870 1870 if qy and 3 <> qx shr 2 and 1 * 2 then 1871 1871 if (TerrType = fArctic) or (TerrType = fSwamp) then 1872 result := 11872 Result := 1 1873 1873 else if TerrType = fShore then 1874 1874 begin 1875 1875 if (qx + qy) and 1 = 0 then 1876 1876 if qx and 3 = 2 then 1877 result := 21877 Result := 2 1878 1878 else 1879 result := 11879 Result := 1 1880 1880 else 1881 result := 01881 Result := 0 1882 1882 end 1883 1883 else 1884 result := (qx + qy) and 1 + 11884 Result := (qx + qy) and 1 + 1 1885 1885 else 1886 result := 0;1886 Result := 0; 1887 1887 end 1888 1888 else 1889 result := 0;1889 Result := 0; 1890 1890 end 1891 1891 end; -
trunk/AI/StdAI/StdAI.lpr
r289 r447 12 12 var 13 13 AIList: array[0..nPl - 1] of TCustomAI; 14 Defender: integer;14 Defender: Integer; 15 15 16 16 17 procedure Client(Command, Player: integer; var Data); stdcall;17 procedure Client(Command, Player: Integer; var Data); stdcall; 18 18 var 19 p, y0, ToLoc: integer;19 P, y0, ToLoc: Integer; 20 20 UnitInfo: TUnitInfo; 21 21 begin … … 32 32 {$ENDIF} 33 33 CustomAI.Init(TNewGameData(Data)); 34 for p:= nPl - 1 downto 0 do35 if G.RO[ p] <> nil then34 for P := nPl - 1 downto 0 do 35 if G.RO[P] <> nil then 36 36 begin 37 AIList[ p] := TAI.Create(p);38 AIList[ p].SetDataDefaults;37 AIList[P] := TAI.Create(P); 38 AIList[P].SetDataDefaults; 39 39 end 40 40 else 41 AIList[ p] := nil;41 AIList[P] := nil; 42 42 Defender := -1; 43 43 end; 44 44 cGetReady: 45 for p:= nPl - 1 downto 0 do46 if AIList[ p] <> nil then47 AIList[ p].SetDataRandom;45 for P := nPl - 1 downto 0 do 46 if AIList[P] <> nil then 47 AIList[P].SetDataRandom; 48 48 cBreakGame: 49 for p:= 0 to nPl - 1 do50 if AIList[ p] <> nil then51 AIList[ p].Free;49 for P := 0 to nPl - 1 do 50 if AIList[P] <> nil then 51 AIList[P].Free; 52 52 53 53 cTurn, cContinue, scContact..scDipBreak, cShowEndContact: -
trunk/AI/StdAI/ToolAI.pas
r442 r447 11 11 type 12 12 TGroupTransportPlan = record 13 LoadLoc, uixTransport, nLoad, TurnsEmpty, TurnsLoaded: integer;14 uixLoad: array[0..15] of integer;13 LoadLoc, uixTransport, nLoad, TurnsEmpty, TurnsLoaded: Integer; 14 uixLoad: array[0..15] of Integer; 15 15 end; 16 16 … … 18 18 TToolAI = class(TCustomAI) 19 19 protected 20 {$IFDEF DEBUG}DebugMap: array[0..lxmax * lymax - 1] of integer;{$ENDIF}21 22 function CenterOfEmpire: integer;20 {$IFDEF DEBUG}DebugMap: array[0..lxmax * lymax - 1] of Integer;{$ENDIF} 21 22 function CenterOfEmpire: Integer; 23 23 // tile that is in the middle of all own cities 24 24 25 function CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;25 function CityTaxBalance(cix: Integer; const CityReport: TCityReport): Integer; 26 26 // calculates exact difference of income and maintenance cost for a single city 27 27 // positive result = income higher than maintenance … … 29 29 // respects production and food converted to gold 30 30 // CityReport must have been prepared before 31 procedure SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);31 procedure SumCities(TaxRate: Integer; var TaxSum, ScienceSum: Integer); 32 32 // calculates exact total tax and science income 33 33 // tax is reduced by maintenance (so might be negative) … … 46 46 procedure JobAssignment_Initialize; 47 47 // initialization, must be called first of the JobAssignment functions 48 procedure JobAssignment_AddJob(Loc, Job, Score: integer);48 procedure JobAssignment_AddJob(Loc, Job, Score: Integer); 49 49 // add job for settlers with certain score 50 50 // jobs include founding cities! 51 procedure JobAssignment_AddUnit(uix: integer);51 procedure JobAssignment_AddUnit(uix: Integer); 52 52 // add a settler unit to do jobs 53 53 procedure JobAssignment_Go; … … 57 57 // starting a job one turn earlier counts the same as 4 points of score 58 58 // function does not cancel jobs that are already started 59 function JobAssignment_GotJob(uix: integer): boolean;59 function JobAssignment_GotJob(uix: Integer): Boolean; 60 60 // can be called after JobAssignment_Go to find out whether 61 61 // a certain settler has been assigned a job to … … 64 64 // calculates formations and districts 65 65 66 function CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;67 var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;68 IsCapture: boolean): integer;66 function CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: Integer; 67 var TimeAfterStep, RecoverTurns: Integer; FromTile, ToTile: Integer; 68 IsCapture: Boolean): Integer; 69 69 // forecast single unit move between adjacent tiles 70 70 // format of TimeBeforeStep and TimeAfterStep: $1000*number of turns + $800-MP left … … 74 74 // CrossCorner=1 for long moves that cross the tile corner, =0 for short ones that don't 75 75 76 function GetMyMoveStyle(mix, Health: integer): integer;77 78 function Unit_MoveEx(uix, ToLoc: integer; Options: integer = 0): integer;76 function GetMyMoveStyle(mix, Health: Integer): Integer; 77 78 function Unit_MoveEx(uix, ToLoc: Integer; Options: Integer = 0): Integer; 79 79 80 80 procedure SeaTransport_BeginInitialize; … … 90 90 // - all transports have same capacity 91 91 // - no transport is damaged 92 procedure SeaTransport_AddLoad(uix: integer);93 procedure SeaTransport_AddTransport(uix: integer);94 procedure SeaTransport_AddDestination(Loc: integer);95 function SeaTransport_MakeGroupPlan(var TransportPlan: TGroupTransportPlan): boolean;92 procedure SeaTransport_AddLoad(uix: Integer); 93 procedure SeaTransport_AddTransport(uix: Integer); 94 procedure SeaTransport_AddDestination(Loc: Integer); 95 function SeaTransport_MakeGroupPlan(var TransportPlan: TGroupTransportPlan): Boolean; 96 96 // make plan for group of units to transport from a single loading location by a single transport 97 97 // the plan optimizes: … … 103 103 // function returns false if no more transports are possible 104 104 105 function CurrentMStrength(Domain: integer): integer;105 function CurrentMStrength(Domain: Integer): Integer; 106 106 end; 107 107 … … 132 132 133 133 var 134 nContinent, nOcean, nDistrict: integer;135 Formation: array[0..lxmax * lymax - 1] of integer;134 nContinent, nOcean, nDistrict: Integer; 135 Formation: array[0..lxmax * lymax - 1] of Integer; 136 136 // water: ocean index, land: continent index, sorted by size 137 137 // territory unpassable due to peace treaty divides a continent 138 District: array[0..lxmax * lymax - 1] of integer;138 District: array[0..lxmax * lymax - 1] of Integer; 139 139 // index of coherent own territory, sorted by size 140 CityResult: array[0..nCmax - 1] of integer;141 142 Advancedness: array[0..nAdv - 1] of integer;140 CityResult: array[0..nCmax - 1] of Integer; 141 142 Advancedness: array[0..nAdv - 1] of Integer; 143 143 // total number of prerequisites for each advance 144 144 … … 149 149 150 150 type 151 pinteger = ^ integer;151 pinteger = ^Integer; 152 152 153 153 var 154 154 // for JobAssignment 155 MaxScore: integer;156 TileJob, TileJobScore: array[0..lxmax * lymax - 1] of byte;157 JobLocOfSettler: array[0..nUmax - 1] of integer; // ToAssign = find job155 MaxScore: Integer; 156 TileJob, TileJobScore: array[0..lxmax * lymax - 1] of Byte; 157 JobLocOfSettler: array[0..nUmax - 1] of Integer; // ToAssign = find job 158 158 159 159 // for Transport 160 TransportMoveStyle, TransportCapacity, nTransportLoad: integer;161 InitComplete, HaveDestinations: boolean;162 uixTransportLoad, TransportAvailable: array[0..nUmax - 1] of integer;163 TurnsAfterLoad: array[0..lxmax * lymax - 1] of shortint;164 165 procedure ReplaceD(Start, Stop: pinteger; Raider, Twix: integer);160 TransportMoveStyle, TransportCapacity, nTransportLoad: Integer; 161 InitComplete, HaveDestinations: Boolean; 162 uixTransportLoad, TransportAvailable: array[0..nUmax - 1] of Integer; 163 TurnsAfterLoad: array[0..lxmax * lymax - 1] of ShortInt; 164 165 procedure ReplaceD(Start, Stop: pinteger; Raider, Twix: Integer); 166 166 begin 167 167 while Start <> Stop do … … 173 173 end; 174 174 175 function NextZero(Start, Stop: pinteger; Mask: cardinal): pinteger;175 function NextZero(Start, Stop: pinteger; Mask: Cardinal): pinteger; 176 176 begin 177 177 while (Start <> Stop) and (Start^ and Mask <> 0) do … … 180 180 end; 181 181 182 function TToolAI.CenterOfEmpire: integer;183 var 184 cix, Loc, x, y, sy, n: integer;185 a, su, sv: double;186 begin 187 n:= 0;182 function TToolAI.CenterOfEmpire: Integer; 183 var 184 cix, Loc, X, Y, sy, N: Integer; 185 A, su, sv: Double; 186 begin 187 N := 0; 188 188 sy := 0; 189 189 su := 0; … … 194 194 if Loc >= 0 then 195 195 begin 196 y:= Loc div G.lx;197 x := Loc - y* G.lx;198 Inc(sy, y);199 a := 2 * pi * x/ G.lx;200 su := su + cos( a);201 sv := sv + sin( a);202 Inc( n);203 end; 204 end; 205 a:= arctan2(sv, su);206 x := round(G.lx * a/ (2 * pi));207 while x>= G.lx do208 Dec( x, G.lx);209 while x< 0 do210 Inc( x, G.lx);211 Result := ((2 * sy + n) div (2 * n)) * G.lx + x;212 end; 213 214 function TToolAI.CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;215 var 216 i: integer;196 Y := Loc div G.lx; 197 X := Loc - Y * G.lx; 198 Inc(sy, Y); 199 A := 2 * pi * X / G.lx; 200 su := su + cos(A); 201 sv := sv + sin(A); 202 Inc(N); 203 end; 204 end; 205 A := arctan2(sv, su); 206 X := round(G.lx * A / (2 * pi)); 207 while X >= G.lx do 208 Dec(X, G.lx); 209 while X < 0 do 210 Inc(X, G.lx); 211 Result := ((2 * sy + N) div (2 * N)) * G.lx + X; 212 end; 213 214 function TToolAI.CityTaxBalance(cix: Integer; const CityReport: TCityReport): Integer; 215 var 216 I: Integer; 217 217 begin 218 218 Result := 0; … … 229 229 Inc(Result, CityReport.FoodRep - CityReport.Eaten); 230 230 end; 231 for i:= nWonder to nImp - 1 do232 if MyCity[cix].Built[ i] > 0 then233 Dec(Result, Imp[ i].Maint);234 end; 235 236 procedure TToolAI.SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);237 var 238 cix, p1: integer;231 for I := nWonder to nImp - 1 do 232 if MyCity[cix].Built[I] > 0 then 233 Dec(Result, Imp[I].Maint); 234 end; 235 236 procedure TToolAI.SumCities(TaxRate: Integer; var TaxSum, ScienceSum: Integer); 237 var 238 cix, p1: Integer; 239 239 CityReport: TCityReport; 240 240 begin … … 242 242 ScienceSum := 0; 243 243 if RO.Government = gAnarchy then 244 exit;244 Exit; 245 245 for p1 := 0 to nPl - 1 do 246 246 if RO.Tribute[p1] <= RO.TributePaid[p1] then … … 268 268 procedure TToolAI.OptimizeCityTiles; 269 269 var 270 cix: integer;270 cix: Integer; 271 271 begin 272 272 for cix := 0 to RO.nCity - 1 do … … 278 278 procedure TToolAI.GetCityProdPotential; 279 279 var 280 cix: integer;280 cix: Integer; 281 281 Advice: TCityTileAdviceData; 282 282 begin … … 286 286 begin 287 287 Advice.ResourceWeights := rwMaxProd; 288 Server(sGetCityTileAdvice, me, cix, Advice);288 Server(sGetCityTileAdvice, Me, cix, Advice); 289 289 CityResult[cix] := Advice.CityReport.ProdRep; // considers factory, but shouldn't 290 290 end; … … 293 293 procedure TToolAI.GetCityTradePotential; 294 294 var 295 cix: integer;295 cix: Integer; 296 296 Advice: TCityTileAdviceData; 297 297 begin … … 301 301 begin 302 302 Advice.ResourceWeights := rwMaxScience; 303 Server(sGetCityTileAdvice, me, cix, Advice);303 Server(sGetCityTileAdvice, Me, cix, Advice); 304 304 CityResult[cix] := Advice.CityReport.Trade; 305 305 end; … … 314 314 procedure TToolAI.JobAssignment_Initialize; 315 315 begin 316 fillchar(JobLocOfSettler, RO.nUn * sizeof(integer), $FF); // -1317 fillchar(TileJob, MapSize, jNone);318 fillchar(TileJobScore, MapSize, 0);316 FillChar(JobLocOfSettler, RO.nUn * SizeOf(Integer), $FF); // -1 317 FillChar(TileJob, MapSize, jNone); 318 FillChar(TileJobScore, MapSize, 0); 319 319 MaxScore := 0; 320 320 end; 321 321 322 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: integer);322 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: Integer); 323 323 begin 324 324 if Score > 255 then … … 333 333 end; 334 334 335 procedure TToolAI.JobAssignment_AddUnit(uix: integer);336 begin 337 assert(MyModel[MyUnit[uix].mix].Kind in [mkSettler, mkSlaves]);335 procedure TToolAI.JobAssignment_AddUnit(uix: Integer); 336 begin 337 Assert(MyModel[MyUnit[uix].mix].Kind in [mkSettler, mkSlaves]); 338 338 JobLocOfSettler[uix] := ToAssign; 339 339 end; 340 340 341 function TToolAI.JobAssignment_GotJob(uix: integer): boolean;341 function TToolAI.JobAssignment_GotJob(uix: Integer): Boolean; 342 342 begin 343 343 Result := JobLocOfSettler[uix] >= 0; … … 347 347 const 348 348 DistanceScore = 4; 349 StepSizeByTerrain: array[0..11] of integer =349 StepSizeByTerrain: array[0..11] of Integer = 350 350 (0, 0, 1, 2, 1, 1, 0, 1, 0, 1, 1, 2); 351 351 //Oc-Sh-Gr-De-Pr-Tu-Ar-Sw-XX-Fo-Hi-Mo 352 352 var 353 353 uix, BestScore, BestCount, BestLoc, BestJob, BestDistance, TestLoc, 354 NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: integer;355 UnitsToAssign: boolean;354 NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: Integer; 355 UnitsToAssign: Boolean; 356 356 Adjacent: TVicinity8Loc; 357 357 SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of smallint; 358 358 // DistToLoc is only defined where SettlerOfJobLoc>=0 359 TileChecked: array[0..lxmax * lymax - 1] of boolean;360 begin 361 fillchar(SettlerOfJobLoc, MapSize * 2, $FF); // -1359 TileChecked: array[0..lxmax * lymax - 1] of Boolean; 360 begin 361 FillChar(SettlerOfJobLoc, MapSize * 2, $FF); // -1 362 362 363 363 // keep up jobs that are already started … … 380 380 BestJob := jNone; 381 381 BestScore := -999999; 382 FillChar(TileChecked, MapSize * sizeof(boolean), False);382 FillChar(TileChecked, MapSize * SizeOf(Boolean), False); 383 383 Pile.Create(MapSize); 384 384 Pile.Put(MyUnit[uix].Loc, 0); // start search for new job at current location … … 399 399 and (Map[NextLoc] and (fUnit or fOwned) <> fUnit) // no foreign unit 400 400 and ((RO.Territory[NextLoc] < 0) or 401 (RO.Territory[NextLoc] = me)) // no foreign territory401 (RO.Territory[NextLoc] = Me)) // no foreign territory 402 402 and (Map[TestLoc] and Map[NextLoc] and fInEnemyZoC = 0) then 403 403 // move not prevented by ZoC … … 414 414 ((SettlerOfJobLoc[TestLoc] < 0) or (DistToLoc[TestLoc] > TestDistance)) then 415 415 begin 416 TestScore := integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;416 TestScore := Integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance; 417 417 if TestScore > BestScore then 418 418 BestCount := 0; … … 469 469 procedure TToolAI.AnalyzeMap; 470 470 var 471 i, j, Loc, Loc1, V8, Count, Kind, MostIndex: integer;471 I, J, Loc, Loc1, V8, Count, Kind, MostIndex: Integer; 472 472 Adjacent: TVicinity8Loc; 473 473 IndexOfID: array[0..lxmax * lymax - 1] of smallint; 474 474 IDOfIndex: array[0..lxmax * lymax div 2 - 1] of smallint; 475 475 begin 476 fillchar(District, MapSize * 4, $FF);476 FillChar(District, MapSize * 4, $FF); 477 477 for Loc := 0 to MapSize - 1 do 478 478 if Map[Loc] and fTerrain = fUNKNOWN then … … 500 500 Formation[Loc], Formation[Loc1]); 501 501 end; 502 if (RO.Territory[Loc] = me) and (Map[Loc] and fTerrain >= fGrass) then502 if (RO.Territory[Loc] = Me) and (Map[Loc] and fTerrain >= fGrass) then 503 503 begin 504 504 District[Loc] := Loc; … … 545 545 Inc(Count); 546 546 end; 547 for i:= 0 to Count - 2 do548 begin 549 MostIndex := i;550 for j := i+ 1 to Count - 1 do551 if IndexOfID[IDOfIndex[ j]] > IndexOfID[IDOfIndex[MostIndex]] then552 MostIndex := j;553 if MostIndex <> ithen554 begin 555 j := IDOfIndex[i];556 IDOfIndex[ i] := IDOfIndex[MostIndex];557 IDOfIndex[MostIndex] := j;558 end; 559 end; 560 for i:= 0 to Count - 1 do561 IndexOfID[IDOfIndex[ i]] := i;547 for I := 0 to Count - 2 do 548 begin 549 MostIndex := I; 550 for J := I + 1 to Count - 1 do 551 if IndexOfID[IDOfIndex[J]] > IndexOfID[IDOfIndex[MostIndex]] then 552 MostIndex := J; 553 if MostIndex <> I then 554 begin 555 J := IDOfIndex[I]; 556 IDOfIndex[I] := IDOfIndex[MostIndex]; 557 IDOfIndex[MostIndex] := J; 558 end; 559 end; 560 for I := 0 to Count - 1 do 561 IndexOfID[IDOfIndex[I]] := I; 562 562 563 563 case Kind of … … 605 605 // other: | Basic | 0| Speed | X X X | MaxTerrType | 606 606 607 function TToolAI.GetMyMoveStyle(mix, Health: integer): integer;607 function TToolAI.GetMyMoveStyle(mix, Health: Integer): Integer; 608 608 begin 609 609 with MyModel[mix] do … … 614 614 begin 615 615 Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); //HeavyCost 616 if RO.Wonder[woShinkansen].EffectiveOwner <> me then616 if RO.Wonder[woShinkansen].EffectiveOwner <> Me then 617 617 Inc(Result, Speed * (4 * 1311) shr 17); // RailCost 618 if (RO.Wonder[woGardens].EffectiveOwner <> me) or618 if (RO.Wonder[woGardens].EffectiveOwner <> Me) or 619 619 (Kind = mkSettler) and (Speed >= 200) then 620 620 Inc(Result, msHostile); … … 631 631 begin 632 632 Result := Speed; 633 if RO.Wonder[woMagellan].EffectiveOwner = me then633 if RO.Wonder[woMagellan].EffectiveOwner = Me then 634 634 Inc(Result, 200); 635 635 if Health < 100 then … … 646 646 end; 647 647 648 function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;649 var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;650 IsCapture: boolean): integer;651 var 652 MoveCost, RecoverCost: integer;648 function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: Integer; 649 var TimeAfterStep, RecoverTurns: Integer; FromTile, ToTile: Integer; 650 IsCapture: Boolean): Integer; 651 var 652 MoveCost, RecoverCost: Integer; 653 653 begin 654 654 //IsCapture:=true; 655 assert(((FromTile and fTerrain <= fMountains) or (FromTile and655 Assert(((FromTile and fTerrain <= fMountains) or (FromTile and 656 656 fTerrain = fUNKNOWN)) and ((ToTile and fTerrain <= fMountains) or 657 657 (ToTile and fTerrain = fUNKNOWN))); … … 701 701 if ToTile and fPeace <> 0 then 702 702 Result := csCheckTerritory; 703 exit;703 Exit; 704 704 end; 705 705 end; … … 820 820 begin 821 821 Result := csForbiddenTile; 822 exit;822 Exit; 823 823 end; 824 824 end … … 869 869 // must wait for next turn 870 870 Result := csOk; 871 exit;871 Exit; 872 872 end; 873 873 end; … … 894 894 -------- Pathfinding Reference Implementation -------- 895 895 var 896 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: integer;896 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: Integer; 897 897 Adjacent: TVicinity8Loc; 898 Reached: array[0..lxmax*lymax-1] of boolean;899 begin 900 fillchar(Reached, MapSize, false);898 Reached: array[0..lxmax*lymax-1] of Boolean; 899 begin 900 FillChar(Reached, MapSize, False); 901 901 MoveStyle:=GetMyMoveStyle(MyUnit[uix].mix, MyUnit[uix].Health); 902 902 Pile.Create(MapSize); … … 906 906 // todo: check exit condition, e.g. whether destination reached 907 907 908 Reached[Loc]:= true;908 Reached[Loc]:=True; 909 909 V8_to_Loc(Loc, Adjacent); 910 910 for V8:=0 to 7 do … … 916 916 Pile.Put(NextLoc, NextTime+RecoverTurns*$1000); 917 917 csForbiddenTile: 918 Reached[NextLoc]:= true; // don't check moving there again918 Reached[NextLoc]:=True; // don't check moving there again 919 919 csCheckTerritory: 920 920 if RO.Territory[NextLoc]=RO.Territory[Loc] then … … 927 927 *) 928 928 929 function TToolAI.Unit_MoveEx(uix, ToLoc: integer; Options: integer): integer;929 function TToolAI.Unit_MoveEx(uix, ToLoc: Integer; Options: Integer): Integer; 930 930 var 931 931 Loc, NextLoc, Temp, FromLoc, EndLoc, Time, V8, MoveResult, RecoverTurns, 932 NextTime, MoveStyle: integer;932 NextTime, MoveStyle: Integer; 933 933 Adjacent: TVicinity8Loc; 934 PreLoc: array[0..lxmax * lymax - 1] of integer;935 Reached: array[0..lxmax * lymax - 1] of boolean;934 PreLoc: array[0..lxmax * lymax - 1] of Integer; 935 Reached: array[0..lxmax * lymax - 1] of Boolean; 936 936 begin 937 937 Result := eOk; 938 938 FromLoc := MyUnit[uix].Loc; 939 939 if FromLoc = ToLoc then 940 exit;940 Exit; 941 941 942 942 FillChar(Reached, MapSize, False); … … 1003 1003 begin 1004 1004 Result := MoveResult; 1005 break;1005 Break; 1006 1006 end; 1007 1007 end; … … 1016 1016 procedure TToolAI.SeaTransport_BeginInitialize; 1017 1017 begin 1018 fillchar(TransportAvailable, RO.nUn * sizeof(integer), $FF); // -11018 FillChar(TransportAvailable, RO.nUn * SizeOf(Integer), $FF); // -1 1019 1019 InitComplete := False; 1020 1020 HaveDestinations := False; … … 1025 1025 end; 1026 1026 1027 procedure TToolAI.SeaTransport_AddLoad(uix: integer);1028 var 1029 i: integer;1030 begin 1031 assert(not InitComplete); // call order violation!1027 procedure TToolAI.SeaTransport_AddLoad(uix: Integer); 1028 var 1029 I: Integer; 1030 begin 1031 Assert(not InitComplete); // call order violation! 1032 1032 if Map[MyUnit[uix].Loc] and fTerrain < fGrass then 1033 exit;1034 for i:= 0 to nTransportLoad - 1 do1035 if uix = uixTransportLoad[ i] then1036 exit;1033 Exit; 1034 for I := 0 to nTransportLoad - 1 do 1035 if uix = uixTransportLoad[I] then 1036 Exit; 1037 1037 uixTransportLoad[nTransportLoad] := uix; 1038 1038 Inc(nTransportLoad); 1039 1039 end; 1040 1040 1041 procedure TToolAI.SeaTransport_AddTransport(uix: integer);1042 var 1043 MoveStyle: integer;1044 begin 1045 assert(not InitComplete); // call order violation!1046 assert(MyModel[MyUnit[uix].mix].Cap[mcSeaTrans] > 0);1041 procedure TToolAI.SeaTransport_AddTransport(uix: Integer); 1042 var 1043 MoveStyle: Integer; 1044 begin 1045 Assert(not InitComplete); // call order violation! 1046 Assert(MyModel[MyUnit[uix].mix].Cap[mcSeaTrans] > 0); 1047 1047 TransportAvailable[uix] := 1; 1048 1048 with MyModel[MyUnit[uix].mix] do … … 1058 1058 end; 1059 1059 1060 procedure TToolAI.SeaTransport_AddDestination(Loc: integer);1061 begin 1062 assert(not InitComplete); // call order violation!1060 procedure TToolAI.SeaTransport_AddDestination(Loc: Integer); 1061 begin 1062 Assert(not InitComplete); // call order violation! 1063 1063 Pile.Put(Loc, $800); 1064 1064 HaveDestinations := True; … … 1067 1067 procedure TToolAI.SeaTransport_EndInitialize; 1068 1068 var 1069 Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: integer;1069 Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: Integer; 1070 1070 Adjacent: TVicinity8Loc; 1071 1071 begin 1072 assert(not InitComplete); // call order violation!1072 Assert(not InitComplete); // call order violation! 1073 1073 InitComplete := True; 1074 1074 if HaveDestinations then 1075 1075 begin // calculate TurnsAfterLoad from destination locs 1076 fillchar(TurnsAfterLoad, MapSize, $FF); // -11076 FillChar(TurnsAfterLoad, MapSize, $FF); // -1 1077 1077 while Pile.Get(Loc0, Time0) do 1078 1078 begin // search backward … … 1100 1100 1101 1101 function TToolAI.SeaTransport_MakeGroupPlan( 1102 var TransportPlan: TGroupTransportPlan): boolean;1103 var 1104 V8, i, j, iPicked, uix, Loc0, Time0, Loc1, RecoverTurns, MoveStyle,1102 var TransportPlan: TGroupTransportPlan): Boolean; 1103 var 1104 V8, I, J, iPicked, uix, Loc0, Time0, Loc1, RecoverTurns, MoveStyle, 1105 1105 TurnsLoaded, TurnCount, tuix, tuix1, ArriveTime, TotalDelay, 1106 1106 BestTotalDelay, GroupCount, BestGroupCount, BestLoadLoc, FullMovementLoc, 1107 nSelectedLoad, f, OriginContinent, a, b: integer;1108 CompleteFlag, NotReachedFlag, ContinueUnit: cardinal;1109 IsComplete, ok, IsFirstLoc: boolean;1107 nSelectedLoad, F, OriginContinent, A, B: Integer; 1108 CompleteFlag, NotReachedFlag, ContinueUnit: Cardinal; 1109 IsComplete, ok, IsFirstLoc: Boolean; 1110 1110 StartLocPtr, ArrivedEnd: pinteger; 1111 1111 Adjacent: TVicinity8Loc; 1112 uixSelectedLoad: array[0..15] of integer;1113 tuixSelectedLoad: array[0..15] of integer;1114 Arrived: array[0..lxmax * lymax] of cardinal;1112 uixSelectedLoad: array[0..15] of Integer; 1113 tuixSelectedLoad: array[0..15] of Integer; 1114 Arrived: array[0..lxmax * lymax] of Cardinal; 1115 1115 ResponsibleTransport: array[0..lxmax * lymax - 1] of smallint; 1116 TurnsBeforeLoad: array[0..lxmax * lymax - 1] of shortint;1117 GroupComplete: array[0..lxmax * lymax - 1] of boolean;1118 begin 1119 assert(InitComplete); // call order violation!1116 TurnsBeforeLoad: array[0..lxmax * lymax - 1] of ShortInt; 1117 GroupComplete: array[0..lxmax * lymax - 1] of Boolean; 1118 begin 1119 Assert(InitComplete); // call order violation! 1120 1120 1121 1121 if HaveDestinations and (nTransportLoad > 0) then … … 1128 1128 for tuix := 0 to nTransportLoad - 1 do 1129 1129 begin 1130 Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);1131 if (abs( a) <= 1) and (abs(b) <= 1) then1130 Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, A, B); 1131 if (abs(A) <= 1) and (abs(B) <= 1) then 1132 1132 begin 1133 assert((a <> 0) or (b<> 0));1133 Assert((A <> 0) or (B <> 0)); 1134 1134 Inc(GroupCount); 1135 1135 end; … … 1145 1145 for tuix := nTransportLoad - 1 downto 0 do 1146 1146 begin 1147 Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);1148 if (abs( a) <= 1) and (abs(b) <= 1) then1147 Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, A, B); 1148 if (abs(A) <= 1) and (abs(B) <= 1) then 1149 1149 begin 1150 1150 TransportPlan.uixLoad[TransportPlan.nLoad] := uixTransportLoad[tuix]; … … 1153 1153 Inc(TransportPlan.nLoad); 1154 1154 if TransportPlan.nLoad = TransportCapacity then 1155 break;1155 Break; 1156 1156 end; 1157 1157 end; 1158 1158 Result := True; 1159 exit;1159 Exit; 1160 1160 end; 1161 1161 end; … … 1165 1165 begin 1166 1166 // select units from same continent 1167 fillchar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter1167 FillChar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter 1168 1168 for tuix := 0 to nTransportLoad - 1 do 1169 1169 begin 1170 assert(Map[MyUnit[uixTransportLoad[tuix]].Loc] and fTerrain >= fGrass);1171 f:= Formation[MyUnit[uixTransportLoad[tuix]].Loc];1172 if f>= 0 then1173 Inc(Arrived[ f]);1170 Assert(Map[MyUnit[uixTransportLoad[tuix]].Loc] and fTerrain >= fGrass); 1171 F := Formation[MyUnit[uixTransportLoad[tuix]].Loc]; 1172 if F >= 0 then 1173 Inc(Arrived[F]); 1174 1174 end; 1175 1175 OriginContinent := 0; 1176 for f:= 1 to nContinent - 1 do1177 if Arrived[ f] > Arrived[OriginContinent] then1178 OriginContinent := f;1176 for F := 1 to nContinent - 1 do 1177 if Arrived[F] > Arrived[OriginContinent] then 1178 OriginContinent := F; 1179 1179 nSelectedLoad := 0; 1180 1180 for tuix := 0 to nTransportLoad - 1 do … … 1185 1185 Inc(nSelectedLoad); 1186 1186 if nSelectedLoad = 16 then 1187 break;1187 Break; 1188 1188 end; 1189 1189 1190 1190 Pile.Create(MapSize); 1191 fillchar(ResponsibleTransport, MapSize * 2, $FF); // -11192 fillchar(TurnsBeforeLoad, MapSize, $FF); // -11191 FillChar(ResponsibleTransport, MapSize * 2, $FF); // -1 1192 FillChar(TurnsBeforeLoad, MapSize, $FF); // -1 1193 1193 ok := False; 1194 1194 for uix := 0 to RO.nUn - 1 do … … 1203 1203 Result := False; 1204 1204 Pile.Free; 1205 exit;1205 Exit; 1206 1206 end; 1207 1207 while Pile.Get(Loc0, Time0) do … … 1224 1224 end; 1225 1225 1226 fillchar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles1227 fillchar(GroupComplete, MapSize, False);1226 FillChar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles 1227 FillChar(GroupComplete, MapSize, False); 1228 1228 BestLoadLoc := -1; 1229 1229 … … 1232 1232 begin 1233 1233 uix := uixSelectedLoad[tuix]; 1234 if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then1234 if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then 1235 1235 begin 1236 1236 NotReachedFlag := 1 shl (2 * tuix); … … 1246 1246 if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then 1247 1247 begin 1248 i:= 1;1248 I := 1; 1249 1249 GroupCount := 0; 1250 1250 for tuix1 := 0 to nSelectedLoad - 1 do 1251 1251 begin 1252 if Arrived[loc1] and i= 0 then1252 if Arrived[loc1] and I = 0 then 1253 1253 Inc(GroupCount); 1254 i := ishl 2;1254 I := I shl 2; 1255 1255 end; 1256 assert(GroupCount <= TransportCapacity);1256 Assert(GroupCount <= TransportCapacity); 1257 1257 if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then 1258 1258 GroupComplete[loc1] := True; … … 1292 1292 begin 1293 1293 Pile.Put(MyUnit[uix].Loc, $1800 - MyUnit[uix].Movement); 1294 if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then1294 if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then 1295 1295 FullMovementLoc := MyUnit[uix].Loc; 1296 1296 // surrounding tiles can be loaded immediately … … 1308 1308 if StartLocPtr <> ArrivedEnd then 1309 1309 begin 1310 Loc0 := ( integer(StartLocPtr) - integer(@Arrived)) shr 2;1310 Loc0 := (Integer(StartLocPtr) - Integer(@Arrived)) shr 2; 1311 1311 Inc(StartLocPtr); 1312 1312 Time0 := $800; … … 1316 1316 if IsFirstLoc then 1317 1317 ContinueUnit := ContinueUnit and not (1 shl tuix); 1318 break;1318 Break; 1319 1319 end; 1320 1320 IsFirstLoc := False; … … 1323 1323 if not GroupComplete[Loc0] and (Map[Loc0] and fTerrain <> fMountains) then 1324 1324 begin // check whether group complete -- no mountains because complete flag might be faked there 1325 i:= 1;1325 I := 1; 1326 1326 GroupCount := 0; 1327 1327 for tuix1 := 0 to nSelectedLoad - 1 do 1328 1328 begin 1329 if Arrived[Loc0] and i= 0 then1329 if Arrived[Loc0] and I = 0 then 1330 1330 Inc(GroupCount); 1331 i := ishl 2;1331 I := I shl 2; 1332 1332 end; 1333 assert(GroupCount <= TransportCapacity);1333 Assert(GroupCount <= TransportCapacity); 1334 1334 if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then 1335 1335 GroupComplete[Loc0] := True; … … 1353 1353 if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then 1354 1354 begin 1355 i:= 1;1355 I := 1; 1356 1356 GroupCount := 0; 1357 1357 for tuix1 := 0 to nSelectedLoad - 1 do 1358 1358 begin 1359 if Arrived[loc1] and i= 0 then1359 if Arrived[loc1] and I = 0 then 1360 1360 Inc(GroupCount); 1361 i := ishl 2;1361 I := I shl 2; 1362 1362 end; 1363 assert(GroupCount <= TransportCapacity);1363 Assert(GroupCount <= TransportCapacity); 1364 1364 if (GroupCount = TransportCapacity) or 1365 1365 (GroupCount = nSelectedLoad) then … … 1436 1436 if 1 shl (2 * tuix) and Arrived[BestLoadLoc] = 0 then 1437 1437 begin 1438 assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);1438 Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]); 1439 1439 TransportPlan.uixLoad[TransportPlan.nLoad] := uixSelectedLoad[tuix]; 1440 1440 uixTransportLoad[tuixSelectedLoad[tuix]] := … … 1444 1444 end; 1445 1445 Result := True; 1446 exit;1446 Exit; 1447 1447 end; 1448 1448 … … 1451 1451 for tuix := nSelectedLoad - 1 downto 0 do 1452 1452 begin 1453 assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);1453 Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]); 1454 1454 uixTransportLoad[tuixSelectedLoad[tuix]] := 1455 1455 uixTransportLoad[nTransportLoad - 1]; … … 1464 1464 // Misc 1465 1465 1466 function TToolAI.CurrentMStrength(Domain: integer): integer;1467 var 1468 i: integer;1466 function TToolAI.CurrentMStrength(Domain: Integer): Integer; 1467 var 1468 I: Integer; 1469 1469 begin 1470 1470 Result := 0; 1471 for i:= 0 to nUpgrade - 1 do1472 with upgrade[Domain, i] do1471 for I := 0 to nUpgrade - 1 do 1472 with upgrade[Domain, I] do 1473 1473 if (Preq = preNone) or (Preq >= 0) and 1474 1474 ((RO.Tech[Preq] >= tsApplicable) or (Preq in FutureTech) and … … 1486 1486 procedure SetAdvancedness; 1487 1487 var 1488 ad, j, Reduction, AgeThreshold: integer;1489 known: array[0..nAdv - 1] of integer;1490 1491 procedure MarkPreqs(ad: integer);1488 ad, J, Reduction, AgeThreshold: Integer; 1489 known: array[0..nAdv - 1] of Integer; 1490 1491 procedure MarkPreqs(ad: Integer); 1492 1492 var 1493 i: integer;1493 I: Integer; 1494 1494 begin 1495 1495 if known[ad] = 0 then 1496 1496 begin 1497 1497 known[ad] := 1; 1498 for i:= 0 to 2 do1499 if AdvPreq[ad, i] >= 0 then1500 MarkPreqs(AdvPreq[ad, i]);1498 for I := 0 to 2 do 1499 if AdvPreq[ad, I] >= 0 then 1500 MarkPreqs(AdvPreq[ad, I]); 1501 1501 end; 1502 1502 end; … … 1508 1508 FillChar(known, SizeOf(known), 0); 1509 1509 MarkPreqs(ad); 1510 for j:= 0 to nAdv - 1 do1511 if known[ j] > 0 then1510 for J := 0 to nAdv - 1 do 1511 if known[J] > 0 then 1512 1512 Inc(Advancedness[ad]); 1513 1513 end; -
trunk/CityProcessing.pas
r425 r447 8 8 9 9 // Reporting 10 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);11 function CanCityGrow( p, cix: integer): boolean;12 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;13 function GetCityReportNew( p, cix: integer;14 var CityReportNew: TCityReportNew): integer;10 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 11 function CanCityGrow(P, cix: Integer): Boolean; 12 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 13 function GetCityReportNew(P, cix: Integer; 14 var CityReportNew: TCityReportNew): Integer; 15 15 16 16 // Internal Tile Picking 17 function AddBestCityTile( p, cix: integer): boolean;18 procedure CityGrowth( p, cix: integer);19 procedure CityShrink( p, cix: integer);20 procedure Pollute( p, cix: integer);17 function AddBestCityTile(P, cix: Integer): Boolean; 18 procedure CityGrowth(P, cix: Integer); 19 procedure CityShrink(P, cix: Integer); 20 procedure Pollute(P, cix: Integer); 21 21 22 22 // Turn Processing 23 procedure PayCityMaintenance( p, cix: integer);24 procedure CollectCityResources( p, cix: integer);25 function CityTurn( p, cix: integer): boolean;23 procedure PayCityMaintenance(P, cix: Integer); 24 procedure CollectCityResources(P, cix: Integer); 25 function CityTurn(P, cix: Integer): Boolean; 26 26 27 27 // Tile Access 28 function SetCityTiles( p, cix, NewTiles: integer;29 TestOnly: boolean = false): integer;30 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);28 function SetCityTiles(P, cix, NewTiles: Integer; 29 TestOnly: Boolean = False): Integer; 30 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 31 31 32 32 // Start/End Game … … 67 67 68 68 var 69 MaxDist: integer;69 MaxDist: Integer; 70 70 71 71 { … … 73 73 ____________________________________________________________________ 74 74 } 75 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);76 var 77 V21, Loc1, p1: integer;75 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 76 var 77 V21, Loc1, p1: Integer; 78 78 Radius: TVicinity21Loc; 79 79 begin 80 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}80 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 81 81 with CityAreaInfo do 82 82 begin … … 90 90 begin 91 91 p1 := RealMap[Loc1] shr 27; 92 if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then92 if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then 93 93 Available[V21] := faTreaty 94 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> p) and95 (RW[ p].Treaty[Occupant[Loc1]] < trAlliance) then94 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> P) and 95 (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then 96 96 Available[V21] := faSiege 97 97 else if (UsedByCity[Loc1] <> -1) and (UsedByCity[Loc1] <> Loc) then … … 104 104 end; 105 105 106 function CanCityGrow( p, cix: integer): boolean;107 begin 108 with RW[ p].City[cix] do109 result := (Size < MaxCitySize) and106 function CanCityGrow(P, cix: Integer): Boolean; 107 begin 108 with RW[P].City[cix] do 109 Result := (Size < MaxCitySize) and 110 110 ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and 111 111 (Size < NeedSewerSize) or (Built[imSewer] = 1)); 112 112 end; 113 113 114 procedure DetermineCityProdProcessing( p, cix: integer;114 procedure DetermineCityProdProcessing(P, cix: Integer; 115 115 var ProdProcessing: TProdProcessing); 116 116 begin 117 with RW[ p].City[cix], ProdProcessing do117 with RW[P].City[cix], ProdProcessing do 118 118 begin 119 119 ProdBonus := 0; 120 120 PollBonus := 0; 121 121 if Built[imFactory] = 1 then 122 inc(ProdBonus);122 Inc(ProdBonus); 123 123 if Built[imMfgPlant] = 1 then 124 inc(ProdBonus);124 Inc(ProdBonus); 125 125 if (Built[imPower] = 1) or (Built[imHydro] = 1) or (Built[imNuclear] = 1) or 126 (GWonder[woHoover].EffectiveOwner = p) then126 (GWonder[woHoover].EffectiveOwner = P) then 127 127 ProdBonus := ProdBonus * 2; 128 128 if Built[imFactory] = 1 then 129 inc(PollBonus);129 Inc(PollBonus); 130 130 if Built[imMfgPlant] = 1 then 131 inc(PollBonus);131 Inc(PollBonus); 132 132 if (Built[imFactory] + Built[imMfgPlant] > 0) then 133 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = p) then134 dec(PollBonus)133 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = P) then 134 Dec(PollBonus) 135 135 else if (Built[imNuclear] = 0) and (Built[imPower] = 1) then 136 inc(PollBonus);137 if (RW[ p].Government <= gDespotism) or (Built[imRecycling] = 1) then136 Inc(PollBonus); 137 if (RW[P].Government <= gDespotism) or (Built[imRecycling] = 1) then 138 138 PollBonus := -2; // no pollution 139 139 PollThreshold := Size; 140 140 FutProdBonus := 0; 141 if RW[ p].Tech[futProductionTechnology] > 0 then141 if RW[P].Tech[futProductionTechnology] > 0 then 142 142 begin // future tech benefits 143 143 if Built[imFactory] = 1 then 144 inc(FutProdBonus, FactoryFutureBonus * RW[p].Tech144 Inc(FutProdBonus, FactoryFutureBonus * RW[P].Tech 145 145 [futProductionTechnology]); 146 146 if Built[imMfgPlant] = 1 then 147 inc(FutProdBonus, MfgPlantFutureBonus * RW[p].Tech147 Inc(FutProdBonus, MfgPlantFutureBonus * RW[P].Tech 148 148 [futProductionTechnology]); 149 149 end; … … 151 151 end; 152 152 153 procedure BoostProd(BaseProd: integer; ProdProcessing: TProdProcessing;154 var Prod, Poll: integer);153 procedure BoostProd(BaseProd: Integer; ProdProcessing: TProdProcessing; 154 var Prod, Poll: Integer); 155 155 begin 156 156 Poll := BaseProd * (2 + ProdProcessing.PollBonus) shr 1; … … 158 158 Poll := 0 159 159 else 160 dec(Poll, ProdProcessing.PollThreshold);160 Dec(Poll, ProdProcessing.PollThreshold); 161 161 if ProdProcessing.FutProdBonus > 0 then 162 162 Prod := BaseProd * (100 + ProdProcessing.ProdBonus * 50 + … … 166 166 end; 167 167 168 procedure DetermineCityTradeProcessing( p, cix, HappinessBeforeLux: integer;168 procedure DetermineCityTradeProcessing(P, cix, HappinessBeforeLux: Integer; 169 169 var TradeProcessing: TTradeProcessing); 170 170 var 171 i, Dist: integer;172 begin 173 with RW[ p].City[cix], TradeProcessing do171 I, Dist: Integer; 172 begin 173 with RW[P].City[cix], TradeProcessing do 174 174 begin 175 175 TaxBonus := 0; 176 176 ScienceBonus := 0; 177 177 if Built[imMarket] = 1 then 178 inc(TaxBonus, 2);178 Inc(TaxBonus, 2); 179 179 if Built[imBank] = 1 then 180 180 begin 181 inc(TaxBonus, 3);182 if RW[ p].NatBuilt[imStockEx] = 1 then183 inc(TaxBonus, 3);181 Inc(TaxBonus, 3); 182 if RW[P].NatBuilt[imStockEx] = 1 then 183 Inc(TaxBonus, 3); 184 184 end; 185 185 LuxBonus := TaxBonus; 186 186 if Built[imLibrary] = 1 then 187 inc(ScienceBonus, 2);187 Inc(ScienceBonus, 2); 188 188 if Built[imUniversity] = 1 then 189 inc(ScienceBonus, 3);189 Inc(ScienceBonus, 3); 190 190 if Built[imResLab] = 1 then 191 inc(ScienceBonus, 3);191 Inc(ScienceBonus, 3); 192 192 ScienceDoubling := 0; 193 193 if Built[imNatObs] > 0 then 194 inc(ScienceDoubling);195 if RW[ p].Government = gFundamentalism then196 dec(ScienceDoubling)197 else if (GWonder[woNewton].EffectiveOwner = p) and198 (RW[ p].Government = gMonarchy) then199 inc(ScienceDoubling);200 FlexibleLuxury := ((ServerVersion[ p] >= $0100F1) and201 (GWonder[woLiberty].EffectiveOwner = p) or (ServerVersion[p] < $0100F1)202 and (GWonder[woMich].EffectiveOwner = p)) and203 (RW[ p].Government <> gAnarchy);194 Inc(ScienceDoubling); 195 if RW[P].Government = gFundamentalism then 196 Dec(ScienceDoubling) 197 else if (GWonder[woNewton].EffectiveOwner = P) and 198 (RW[P].Government = gMonarchy) then 199 Inc(ScienceDoubling); 200 FlexibleLuxury := ((ServerVersion[P] >= $0100F1) and 201 (GWonder[woLiberty].EffectiveOwner = P) or (ServerVersion[P] < $0100F1) 202 and (GWonder[woMich].EffectiveOwner = P)) and 203 (RW[P].Government <> gAnarchy); 204 204 FutResBonus := 0; 205 if RW[ p].Tech[futResearchTechnology] > 0 then205 if RW[P].Tech[futResearchTechnology] > 0 then 206 206 begin // future tech benefits 207 207 if Built[imUniversity] = 1 then 208 inc(FutResBonus, UniversityFutureBonus * RW[p].Tech208 Inc(FutResBonus, UniversityFutureBonus * RW[P].Tech 209 209 [futResearchTechnology]); 210 210 if Built[imResLab] = 1 then 211 inc(FutResBonus, ResLabFutureBonus * RW[p].Tech[futResearchTechnology]);212 end; 213 if (RW[ p].NatBuilt[imPalace] > 0) or (ServerVersion[p] < $010000) then211 Inc(FutResBonus, ResLabFutureBonus * RW[P].Tech[futResearchTechnology]); 212 end; 213 if (RW[P].NatBuilt[imPalace] > 0) or (ServerVersion[P] < $010000) then 214 214 begin // calculate corruption 215 215 Dist := MaxDist; 216 for i := 0 to RW[p].nCity - 1 do217 if (RW[ p].City[i].Loc >= 0) and (RW[p].City[i].Built[imPalace] = 1) then218 Dist := Distance(Loc, RW[ p].City[i].Loc);219 if (Dist = 0) or (CorrLevel[RW[ p].Government] = 0) then216 for I := 0 to RW[P].nCity - 1 do 217 if (RW[P].City[I].Loc >= 0) and (RW[P].City[I].Built[imPalace] = 1) then 218 Dist := Distance(Loc, RW[P].City[I].Loc); 219 if (Dist = 0) or (CorrLevel[RW[P].Government] = 0) then 220 220 RelCorr := 0.0 221 221 else 222 222 begin 223 223 RelCorr := Dist / MaxDist; 224 if CorrLevel[RW[ p].Government] > 1 then225 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[ p].Government]);224 if CorrLevel[RW[P].Government] > 1 then 225 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[P].Government]); 226 226 if Built[imCourt] = 1 then 227 227 RelCorr := RelCorr / 2; … … 237 237 end; 238 238 239 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: integer;239 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: Integer; 240 240 TradeProcessing: TTradeProcessing; var Corruption, Tax, Lux, 241 Science: integer);242 var 243 plus: integer;241 Science: Integer); 242 var 243 plus: Integer; 244 244 begin 245 245 Corruption := Trunc(Trade * TradeProcessing.RelCorr); … … 276 276 end; 277 277 278 function GetProjectCost( p, cix: integer): integer;279 var 280 i: integer;281 begin 282 with RW[ p].City[cix] do278 function GetProjectCost(P, cix: Integer): Integer; 279 var 280 I: Integer; 281 begin 282 with RW[P].City[cix] do 283 283 begin 284 284 if Project and cpImp = 0 then 285 285 begin 286 result := RW[p].Model[Project and cpIndex].Cost; { unit project }286 Result := RW[P].Model[Project and cpIndex].Cost; { unit project } 287 287 if Project and cpConscripts <> 0 then 288 288 begin 289 i := RW[p].Model[Project and cpIndex].MCost;290 result := result - 3 * i;291 if result <= 0 then292 result := i;289 I := RW[P].Model[Project and cpIndex].MCost; 290 Result := Result - 3 * I; 291 if Result <= 0 then 292 Result := I; 293 293 end 294 else if RW[ p].Model[Project and cpIndex].Cap[mcLine] > 0 then294 else if RW[P].Model[Project and cpIndex].Cap[mcLine] > 0 then 295 295 if Project0 and (not cpAuto or cpRepeat) = Project and not cpAuto or cpRepeat 296 296 then 297 result := result shr 1297 Result := Result shr 1 298 298 else 299 result := result * 2;299 Result := Result * 2; 300 300 end 301 301 else 302 302 begin { improvement project } 303 result := Imp[Project and cpIndex].Cost;304 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = p)303 Result := Imp[Project and cpIndex].Cost; 304 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = P) 305 305 then 306 result := result * ColossusEffect div 100;307 end; 308 result := result * BuildCostMod[Difficulty[p]] div 12;309 end; 310 end; 311 312 function GetSmallCityReport( p, cix: integer; var CityReport: TCityReport;313 PCityReportEx: PCityReportEx = nil): integer;314 var 315 i, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: integer;306 Result := Result * ColossusEffect div 100; 307 end; 308 Result := Result * BuildCostMod[Difficulty[P]] div 12; 309 end; 310 end; 311 312 function GetSmallCityReport(P, cix: Integer; var CityReport: TCityReport; 313 PCityReportEx: PCityReportEx = nil): Integer; 314 var 315 I, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: Integer; 316 316 ProdProcessing: TProdProcessing; 317 317 TradeProcessing: TTradeProcessing; 318 318 Radius: TVicinity21Loc; 319 319 UnitReport: TUnitReport; 320 RareOK: array [0 .. 3] of integer;320 RareOK: array [0 .. 3] of Integer; 321 321 TileInfo: TTileInfo; 322 322 begin 323 with RW[ p].City[cix], CityReport do323 with RW[P].City[cix], CityReport do 324 324 begin 325 325 if HypoTiles <= 0 then 326 326 HypoTiles := Tiles; 327 327 if HypoTax < 0 then 328 HypoTax := RW[ p].TaxRate;328 HypoTax := RW[P].TaxRate; 329 329 if HypoLux < 0 then 330 HypoLux := RW[ p].LuxRate;331 332 if (Flags and chCaptured <> 0) or (RW[ p].Government = gAnarchy) then330 HypoLux := RW[P].LuxRate; 331 332 if (Flags and chCaptured <> 0) or (RW[P].Government = gAnarchy) then 333 333 begin 334 334 Working := 0; 335 335 for V21 := 1 to 26 do 336 336 if HypoTiles and (1 shl V21) <> 0 then 337 inc(Working); // for backward compatibility338 339 if RW[ p].Government = gFundamentalism then337 Inc(Working); // for backward compatibility 338 339 if RW[P].Government = gFundamentalism then 340 340 begin 341 341 Happy := Size; … … 380 380 BaseHappiness := Size; 381 381 end; 382 for i:= 0 to nWonder - 1 do383 if Built[ i] = 1 then382 for I := 0 to nWonder - 1 do 383 if Built[I] = 1 then 384 384 begin 385 inc(Happy);386 inc(BaseHappiness, 2);385 Inc(Happy); 386 Inc(BaseHappiness, 2); 387 387 end; 388 388 if Built[imTemple] = 1 then 389 389 begin 390 inc(Happy);391 inc(BaseHappiness, 2);390 Inc(Happy); 391 Inc(BaseHappiness, 2); 392 392 end; 393 393 if Built[imCathedral] = 1 then 394 394 begin 395 inc(Happy, 2);396 inc(BaseHappiness, 4);397 if GWonder[woBach].EffectiveOwner = pthen395 Inc(Happy, 2); 396 Inc(BaseHappiness, 4); 397 if GWonder[woBach].EffectiveOwner = P then 398 398 begin 399 inc(Happy);400 inc(BaseHappiness, 2);399 Inc(Happy); 400 Inc(BaseHappiness, 2); 401 401 end; 402 402 end; 403 403 if Built[imTheater] > 0 then 404 404 begin 405 inc(Happy, 2);406 inc(BaseHappiness, 4);405 Inc(Happy, 2); 406 Inc(BaseHappiness, 4); 407 407 end; 408 408 409 409 // calculate unit support 410 {$IFOPT O-} assert(InvalidTreatyMap = 0); {$ENDIF}410 {$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF} 411 411 Support := 0; 412 412 ForcedSupport := 0; 413 413 Eaten := Size * 2; 414 414 Deployed := 0; 415 for uix := 0 to RW[ p].nUn - 1 do416 with RW[ p].Un[uix] do415 for uix := 0 to RW[P].nUn - 1 do 416 with RW[P].Un[uix] do 417 417 if (Loc >= 0) and (Home = cix) then 418 418 begin 419 GetUnitReport( p, uix, UnitReport);420 inc(Eaten, UnitReport.FoodSupport);419 GetUnitReport(P, uix, UnitReport); 420 Inc(Eaten, UnitReport.FoodSupport); 421 421 if UnitReport.ReportFlags and urfAlwaysSupport <> 0 then 422 inc(ForcedSupport, UnitReport.ProdSupport)422 Inc(ForcedSupport, UnitReport.ProdSupport) 423 423 else 424 inc(Support, UnitReport.ProdSupport);424 Inc(Support, UnitReport.ProdSupport); 425 425 if UnitReport.ReportFlags and urfDeployed <> 0 then 426 inc(Deployed);426 Inc(Deployed); 427 427 end; 428 428 if Deployed >= Happy then 429 429 Happy := 0 430 430 else 431 dec(Happy, Deployed);432 dec(Support, Size * SupportFree[RW[p].Government] shr 1);431 Dec(Happy, Deployed); 432 Dec(Support, Size * SupportFree[RW[P].Government] shr 1); 433 433 if Support < 0 then 434 434 Support := 0; 435 inc(Support, ForcedSupport);435 Inc(Support, ForcedSupport); 436 436 437 437 { control } 438 case RW[ p].Government of438 case RW[P].Government of 439 439 gDespotism: 440 for uix := 0 to RW[ p].nUn - 1 do441 if (RW[ p].Un[uix].Loc = Loc) and442 (RW[ p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_TownGuard) then440 for uix := 0 to RW[P].nUn - 1 do 441 if (RW[P].Un[uix].Loc = Loc) and 442 (RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_TownGuard) then 443 443 begin 444 inc(Happy);445 inc(Control, 2);444 Inc(Happy); 445 Inc(Control, 2); 446 446 end; 447 447 gFundamentalism: … … 454 454 455 455 // collect processing parameters 456 DetermineCityProdProcessing( p, cix, ProdProcessing);457 DetermineCityTradeProcessing( p, cix, BaseHappiness + Control - 2 *456 DetermineCityProdProcessing(P, cix, ProdProcessing); 457 DetermineCityTradeProcessing(P, cix, BaseHappiness + Control - 2 * 458 458 Deployed, TradeProcessing); 459 459 … … 472 472 // HypoTiles go beyond map border! 473 473 begin 474 result := eInvalid;475 exit;474 Result := eInvalid; 475 Exit; 476 476 end; 477 GetTileInfo( p, cix, Loc1, TileInfo);478 inc(FoodRep, TileInfo.Food);479 inc(ProdRep, TileInfo.Prod);480 inc(Trade, TileInfo.Trade);477 GetTileInfo(P, cix, Loc1, TileInfo); 478 Inc(FoodRep, TileInfo.Food); 479 Inc(ProdRep, TileInfo.Prod); 480 Inc(Trade, TileInfo.Trade); 481 481 if (RealMap[Loc1] and fModern <> 0) and 482 (RW[ p].Tech[adMassProduction] >= tsApplicable) then483 inc(RareOK[RealMap[Loc1] shr 25 and 3]);484 inc(Working);482 (RW[P].Tech[adMassProduction] >= tsApplicable) then 483 Inc(RareOK[RealMap[Loc1] shr 25 and 3]); 484 Inc(Working); 485 485 end; 486 486 if Built[imAlgae] = 1 then 487 inc(FoodRep, 12);487 Inc(FoodRep, 12); 488 488 489 489 if PCityReportEx <> nil then … … 510 510 end; 511 511 end; 512 result := eOk;513 end; 514 515 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;516 begin 517 result := GetSmallCityReport(p, cix, CityReport);518 CityReport.Storage := StorageSize[Difficulty[ p]];519 CityReport.ProdCost := GetProjectCost( p, cix);520 end; 521 522 function GetCityReportNew( p, cix: integer;523 var CityReportNew: TCityReportNew): integer;512 Result := eOk; 513 end; 514 515 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 516 begin 517 Result := GetSmallCityReport(P, cix, CityReport); 518 CityReport.Storage := StorageSize[Difficulty[P]]; 519 CityReport.ProdCost := GetProjectCost(P, cix); 520 end; 521 522 function GetCityReportNew(P, cix: Integer; 523 var CityReportNew: TCityReportNew): Integer; 524 524 var 525 525 CityReport: TCityReport; … … 531 531 CityReport.HypoTax := HypoTaxRate; 532 532 CityReport.HypoLux := HypoLuxuryRate; 533 result := GetSmallCityReport(p, cix, CityReport, @CityReportEx);534 FoodSupport := CityReport.Eaten - 2 * RW[ p].City[cix].Size;533 Result := GetSmallCityReport(P, cix, CityReport, @CityReportEx); 534 FoodSupport := CityReport.Eaten - 2 * RW[P].City[cix].Size; 535 535 MaterialSupport := CityReport.Support; 536 ProjectCost := GetProjectCost( p, cix);537 Storage := StorageSize[Difficulty[ p]];536 ProjectCost := GetProjectCost(P, cix); 537 Storage := StorageSize[Difficulty[P]]; 538 538 Deployed := CityReport.Deployed; 539 539 Morale := CityReportEx.BaseHappiness; 540 540 CollectedControl := CityReportEx.BaseControl + 541 (RW[ p].City[cix].Size - CityReport.Working) * 2;541 (RW[P].City[cix].Size - CityReport.Working) * 2; 542 542 CollectedFood := CityReport.FoodRep; 543 543 CollectedMaterial := CityReportEx.Material; … … 551 551 Luxury := CityReport.Lux; 552 552 FoodSurplus := CityReport.FoodRep - CityReport.Eaten; 553 HappinessBalance := Morale + Luxury + CollectedControl - RW[ p].City[cix]553 HappinessBalance := Morale + Luxury + CollectedControl - RW[P].City[cix] 554 554 .Size - 2 * Deployed; 555 555 end; … … 560 560 ____________________________________________________________________ 561 561 } 562 procedure NextBest( p, cix: integer; var SelectedLoc, SelectedV21: integer);562 procedure NextBest(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 563 563 { best tile unused but available by city cix } 564 564 var 565 Resources, Most, Loc1, p1, V21: integer;565 Resources, Most, Loc1, p1, V21: Integer; 566 566 TileInfo: TTileInfo; 567 567 Radius: TVicinity21Loc; 568 568 begin 569 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}569 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 570 570 Most := 0; 571 571 SelectedLoc := -1; 572 572 SelectedV21 := -1; 573 with RW[ p].City[cix] do573 with RW[P].City[cix] do 574 574 begin 575 575 V21_to_Loc(Loc, Radius); … … 580 580 begin 581 581 p1 := RealMap[Loc1] shr 27; 582 if ((p1 = nPl) or (p1 = p) or (RW[p].Treaty[p1] < trPeace)) and583 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = p) or584 (RW[ p].Treaty[Occupant[Loc1]] = trAlliance)) then582 if ((p1 = nPl) or (p1 = P) or (RW[P].Treaty[p1] < trPeace)) and 583 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = P) or 584 (RW[P].Treaty[Occupant[Loc1]] = trAlliance)) then 585 585 begin 586 GetTileInfo( p, cix, Loc1, TileInfo);586 GetTileInfo(P, cix, Loc1, TileInfo); 587 587 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 588 588 TileInfo.Trade; … … 600 600 end; 601 601 602 procedure NextWorst( p, cix: integer; var SelectedLoc, SelectedV21: integer);602 procedure NextWorst(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 603 603 { worst tile used by city cix } 604 604 var 605 Resources, Least, Loc1, V21: integer;605 Resources, Least, Loc1, V21: Integer; 606 606 Radius: TVicinity21Loc; 607 607 TileInfo: TTileInfo; … … 610 610 SelectedLoc := -1; 611 611 SelectedV21 := -1; 612 with RW[ p].City[cix] do612 with RW[P].City[cix] do 613 613 begin 614 614 V21_to_Loc(Loc, Radius); … … 619 619 if (Loc1 >= 0) and (Loc1 < MapSize) and (1 shl V21 and Tiles <> 0) then 620 620 begin 621 GetTileInfo( p, cix, Loc1, TileInfo);621 GetTileInfo(P, cix, Loc1, TileInfo); 622 622 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 623 623 TileInfo.Trade; … … 634 634 end; 635 635 636 function NextPoll( p, cix: integer): integer;637 var 638 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: integer;636 function NextPoll(P, cix: Integer): Integer; 637 var 638 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: Integer; 639 639 Radius: TVicinity21Loc; 640 640 TileInfo: TTileInfo; 641 641 begin 642 642 BestDist := MaxInt; 643 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}643 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 644 644 Best := 0; 645 result := -1;646 with RW[ p].City[cix] do645 Result := -1; 646 with RW[P].City[cix] do 647 647 begin 648 648 V21_to_Loc(Loc, Radius); … … 656 656 begin 657 657 pTerr := RealMap[Loc1] shr 27; 658 if (pTerr = nPl) or (pTerr = p) or (RW[p].Treaty[pTerr] < trPeace)658 if (pTerr = nPl) or (pTerr = P) or (RW[P].Treaty[pTerr] < trPeace) 659 659 then 660 660 begin 661 GetTileInfo( p, cix, Loc1, TileInfo);661 GetTileInfo(P, cix, Loc1, TileInfo); 662 662 Resources := TileInfo.Prod shl 16 + TileInfo.Trade shl 8 + 663 663 TileInfo.Food; … … 669 669 then 670 670 begin 671 result := Loc1;671 Result := Loc1; 672 672 Best := Resources; 673 673 BestDist := Dist; … … 679 679 end; 680 680 681 function AddBestCityTile( p, cix: integer): boolean;682 var 683 TileLoc, V21: integer;684 begin 685 NextBest( p, cix, TileLoc, V21);686 result := TileLoc >= 0;687 if result then688 with RW[ p].City[cix] do689 begin 690 assert(1 shl V21 and Tiles = 0);681 function AddBestCityTile(P, cix: Integer): Boolean; 682 var 683 TileLoc, V21: Integer; 684 begin 685 NextBest(P, cix, TileLoc, V21); 686 Result := TileLoc >= 0; 687 if Result then 688 with RW[P].City[cix] do 689 begin 690 Assert(1 shl V21 and Tiles = 0); 691 691 Tiles := Tiles or (1 shl V21); 692 692 UsedByCity[TileLoc] := Loc; … … 694 694 end; 695 695 696 procedure CityGrowth( p, cix: integer);697 var 698 TileLoc, V21: integer;696 procedure CityGrowth(P, cix: Integer); 697 var 698 TileLoc, V21: Integer; 699 699 AltCityReport: TCityReport; 700 700 begin 701 with RW[ p].City[cix] do701 with RW[P].City[cix] do 702 702 begin 703 inc(Size);704 NextBest( p, cix, TileLoc, V21);703 Inc(Size); 704 NextBest(P, cix, TileLoc, V21); 705 705 if TileLoc >= 0 then 706 706 begin { test whether exploitation of tile would lead to disorder } … … 708 708 AltCityReport.HypoTax := -1; 709 709 AltCityReport.HypoLux := -1; 710 GetSmallCityReport( p, cix, AltCityReport);710 GetSmallCityReport(P, cix, AltCityReport); 711 711 if AltCityReport.Working - AltCityReport.Happy <= Size shr 1 then 712 712 // !!! change to new style disorder 713 713 begin { no disorder -- exploit tile } 714 assert(1 shl V21 and Tiles = 0);714 Assert(1 shl V21 and Tiles = 0); 715 715 Tiles := Tiles or (1 shl V21); 716 716 UsedByCity[TileLoc] := Loc; … … 720 720 end; 721 721 722 procedure CityShrink( p, cix: integer);723 var 724 TileLoc, V21, Working: integer;722 procedure CityShrink(P, cix: Integer); 723 var 724 TileLoc, V21, Working: Integer; 725 725 AltCityReport: TCityReport; 726 726 begin 727 with RW[ p].City[cix] do727 with RW[P].City[cix] do 728 728 begin 729 729 Working := 0; 730 730 for V21 := 1 to 26 do 731 731 if Tiles and (1 shl V21) <> 0 then 732 inc(Working);733 dec(Size);734 if Food > StorageSize[Difficulty[ p]] then735 Food := StorageSize[Difficulty[ p]];736 NextWorst( p, cix, TileLoc, V21);732 Inc(Working); 733 Dec(Size); 734 if Food > StorageSize[Difficulty[P]] then 735 Food := StorageSize[Difficulty[P]]; 736 NextWorst(P, cix, TileLoc, V21); 737 737 if Working > Size then 738 738 begin { all citizens were working -- worst tile no longer exploited } 739 assert(1 shl V21 and Tiles <> 0);739 Assert(1 shl V21 and Tiles <> 0); 740 740 Tiles := Tiles and not(1 shl V21); 741 741 UsedByCity[TileLoc] := -1; … … 746 746 AltCityReport.HypoTax := -1; 747 747 AltCityReport.HypoLux := -1; 748 GetSmallCityReport( p, cix, AltCityReport);748 GetSmallCityReport(P, cix, AltCityReport); 749 749 if AltCityReport.Working - AltCityReport.Happy > Size shr 1 then 750 750 // !!! change to new style disorder 751 751 begin { disorder -- don't exploit tile } 752 assert(1 shl V21 and Tiles <> 0);752 Assert(1 shl V21 and Tiles <> 0); 753 753 Tiles := Tiles and not(1 shl V21); 754 754 UsedByCity[TileLoc] := -1; … … 758 758 end; 759 759 760 procedure Pollute( p, cix: integer);761 var 762 PollutionLoc: integer;763 begin 764 with RW[ p].City[cix] do760 procedure Pollute(P, cix: Integer); 761 var 762 PollutionLoc: Integer; 763 begin 764 with RW[P].City[cix] do 765 765 begin 766 766 Pollution := Pollution - MaxPollution; 767 PollutionLoc := NextPoll( p, cix);767 PollutionLoc := NextPoll(P, cix); 768 768 if PollutionLoc >= 0 then 769 769 begin 770 inc(Flags, chPollution);770 Inc(Flags, chPollution); 771 771 RealMap[PollutionLoc] := RealMap[PollutionLoc] or fPoll; 772 772 end; … … 778 778 ____________________________________________________________________ 779 779 } 780 procedure PayCityMaintenance( p, cix: integer);781 var 782 i: integer;783 begin 784 with RW[ p], City[cix] do785 for i:= nWonder to nImp - 1 do786 if (Built[ i] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or i))780 procedure PayCityMaintenance(P, cix: Integer); 781 var 782 I: Integer; 783 begin 784 with RW[P], City[cix] do 785 for I := nWonder to nImp - 1 do 786 if (Built[I] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or I)) 787 787 then // don't pay maintenance when just completed 788 788 begin 789 dec(Money, Imp[i].Maint);789 Dec(Money, Imp[I].Maint); 790 790 if Money < 0 then 791 791 begin { out of money - sell improvement } 792 inc(Money, Imp[i].Cost * BuildCostMod[Difficulty[p]] div 12);793 Built[ i] := 0;794 if Imp[ i].Kind <> ikCommon then792 Inc(Money, Imp[I].Cost * BuildCostMod[Difficulty[P]] div 12); 793 Built[I] := 0; 794 if Imp[I].Kind <> ikCommon then 795 795 begin 796 assert(i<> imSpacePort);796 Assert(I <> imSpacePort); 797 797 // never sell automatically! (solution: no maintenance) 798 NatBuilt[ i] := 0;799 if i= imGrWall then800 GrWallContinent[ p] := -1;798 NatBuilt[I] := 0; 799 if I = imGrWall then 800 GrWallContinent[P] := -1; 801 801 end; 802 inc(Flags, chImprovementLost);803 end; 804 end; 805 end; 806 807 procedure CollectCityResources( p, cix: integer);808 var 809 CityStorage, CityProjectCost: integer;802 Inc(Flags, chImprovementLost); 803 end; 804 end; 805 end; 806 807 procedure CollectCityResources(P, cix: Integer); 808 var 809 CityStorage, CityProjectCost: Integer; 810 810 CityReport: TCityReportNew; 811 Disorder: boolean;812 begin 813 with RW[ p], City[cix], CityReport do811 Disorder: Boolean; 812 begin 813 with RW[P], City[cix], CityReport do 814 814 if Flags and chCaptured <> 0 then 815 815 begin 816 816 Flags := Flags and not chDisorder; 817 dec(Flags, $10000);817 Dec(Flags, $10000); 818 818 if Flags and chCaptured = 0 then 819 819 Flags := Flags or chAfterCapture; … … 826 826 HypoTaxRate := -1; 827 827 HypoLuxuryRate := -1; 828 GetCityReportNew( p, cix, CityReport);829 CityStorage := StorageSize[Difficulty[ p]];830 CityProjectCost := GetProjectCost( p, cix);828 GetCityReportNew(P, cix, CityReport); 829 CityStorage := StorageSize[Difficulty[P]]; 830 CityProjectCost := GetProjectCost(P, cix); 831 831 832 832 Disorder := (HappinessBalance < 0); … … 840 840 if not Disorder and ((Government = gFuture) or (Size >= NeedAqueductSize) 841 841 and (FoodSurplus < 2)) and (FoodSurplus > 0) then 842 inc(Money, FoodSurplus)842 Inc(Money, FoodSurplus) 843 843 else if not(Disorder and (FoodSurplus > 0)) then 844 844 begin { calculate new food storage } … … 849 849 (Project and (cpImp + cpIndex) <> cpImp + imAqueduct) and 850 850 (Project and (cpImp + cpIndex) <> cpImp + imSewer) and 851 not CanCityGrow( p, cix) then852 inc(Flags, chNoGrowthWarning);851 not CanCityGrow(P, cix) then 852 Inc(Flags, chNoGrowthWarning); 853 853 end; 854 854 855 855 if Prod > CityProjectCost then 856 856 begin 857 inc(Money, Prod - CityProjectCost);857 Inc(Money, Prod - CityProjectCost); 858 858 Prod := CityProjectCost; 859 859 end; … … 862 862 else if not Disorder and (Flags and chProductionSabotaged = 0) then 863 863 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 864 inc(Money, Production)864 Inc(Money, Production) 865 865 else 866 inc(Prod, Production);866 Inc(Prod, Production); 867 867 868 868 if not Disorder then 869 869 begin 870 870 { sum research points and taxes } 871 inc(Research, Science);872 inc(Money, Tax);871 Inc(Research, Science); 872 Inc(Money, Tax); 873 873 Pollution := Pollution + AddPollution; 874 874 end; … … 876 876 end; 877 877 878 function CityTurn( p, cix: integer): boolean;878 function CityTurn(P, cix: Integer): Boolean; 879 879 // return value: whether city keeps existing 880 880 var 881 i, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,882 TestDet: integer;883 LackOfMaterial, CheckGrow, DoProd, IsActive: boolean;884 begin 885 with RW[ p], City[cix] do881 I, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det, 882 TestDet: Integer; 883 LackOfMaterial, CheckGrow, DoProd, IsActive: Boolean; 884 begin 885 with RW[P], City[cix] do 886 886 begin 887 887 SizeMod := 0; 888 CityStorage := StorageSize[Difficulty[ p]];889 CityProjectCost := GetProjectCost( p, cix);888 CityStorage := StorageSize[Difficulty[P]]; 889 CityProjectCost := GetProjectCost(P, cix); 890 890 891 891 LackOfMaterial := Flags and chUnitLost <> 0; … … 897 897 if CheckGrow and (GTestFlags and tfImmGrow <> 0) then { fast growth } 898 898 begin 899 if CanCityGrow( p, cix) then900 inc(SizeMod);899 if CanCityGrow(P, cix) then 900 Inc(SizeMod); 901 901 end 902 902 else if CheckGrow and (Food >= CityStorage) then { normal growth } 903 903 begin 904 if CanCityGrow( p, cix) then904 if CanCityGrow(P, cix) then 905 905 begin 906 906 if Built[imGranary] = 1 then 907 dec(Food, CityStorage shr 1)907 Dec(Food, CityStorage shr 1) 908 908 else 909 dec(Food, CityStorage);910 inc(SizeMod);909 Dec(Food, CityStorage); 910 Inc(SizeMod); 911 911 end; 912 912 end … … 916 916 // check if settlers or conscripts there to disband 917 917 uix := -1; 918 for i:= 0 to nUn - 1 do919 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) and920 ((Model[Un[ i].mix].Kind = mkSettler)918 for I := 0 to nUn - 1 do 919 if (Un[I].Loc >= 0) and (Un[I].Home = cix) and 920 ((Model[Un[I].mix].Kind = mkSettler) 921 921 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } 922 or (Un[ i].Flags and unConscripts <> 0)) and923 ((uix = -1) or (Model[Un[ i].mix].Cost < Model[Un[uix].mix].Cost) or924 (Model[Un[ i].mix].Cost = Model[Un[uix].mix].Cost) and925 (Un[ i].Exp < Un[uix].Exp)) then926 uix := i;922 or (Un[I].Flags and unConscripts <> 0)) and 923 ((uix = -1) or (Model[Un[I].mix].Cost < Model[Un[uix].mix].Cost) or 924 (Model[Un[I].mix].Cost = Model[Un[uix].mix].Cost) and 925 (Un[I].Exp < Un[uix].Exp)) then 926 uix := I; 927 927 928 928 if uix >= 0 then 929 929 begin 930 RemoveUnit_UpdateMap( p, uix);931 inc(Flags, chUnitLost);930 RemoveUnit_UpdateMap(P, uix); 931 Inc(Flags, chUnitLost); 932 932 end 933 933 else 934 934 begin 935 dec(SizeMod);936 inc(Flags, chPopDecrease);935 Dec(SizeMod); 936 Inc(Flags, chPopDecrease); 937 937 end 938 938 end; … … 946 946 uix := -1; 947 947 Det := MaxInt; 948 for i:= 0 to nUn - 1 do949 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) then950 with Model[Un[ i].mix] do948 for I := 0 to nUn - 1 do 949 if (Un[I].Loc >= 0) and (Un[I].Home = cix) then 950 with Model[Un[I].mix] do 951 951 begin 952 952 if Kind = mkSpecial_TownGuard then 953 TestDet := Un[ i].Health + Un[i].Exp shl 8953 TestDet := Un[I].Health + Un[I].Exp shl 8 954 954 // disband townguards first 955 955 else 956 956 begin 957 TestDet := Un[ i].Health + Un[i].Exp shl 8 + Cost shl 16;957 TestDet := Un[I].Health + Un[I].Exp shl 8 + Cost shl 16; 958 958 // value of unit 959 959 if Flags and mdDoubleSupport <> 0 then … … 963 963 if TestDet < Det then 964 964 begin 965 uix := i;965 uix := I; 966 966 Det := TestDet; 967 967 end; … … 969 969 if uix >= 0 then 970 970 begin 971 RemoveUnit_UpdateMap( p, uix);972 inc(Flags, chUnitLost);971 RemoveUnit_UpdateMap(P, uix); 972 Inc(Flags, chUnitLost); 973 973 end; 974 974 end; … … 984 984 (GWonder[Project and cpIndex].CityID <> WonderNotBuiltYet) then 985 985 begin 986 inc(Flags, chOldWonder);987 DoProd := false;986 Inc(Flags, chOldWonder); 987 DoProd := False; 988 988 end; 989 989 … … 995 995 (Project and cpConscripts <> 0))) then 996 996 begin 997 inc(Flags, chNoSettlerProd);998 DoProd := false;997 Inc(Flags, chNoSettlerProd); 998 DoProd := False; 999 999 end; 1000 1000 1001 1001 if DoProd then 1002 1002 begin { project complete } 1003 dec(Prod, CityProjectCost);1003 Dec(Prod, CityProjectCost); 1004 1004 if Project and cpImp = 0 then { produce unit } 1005 1005 begin 1006 1006 if nUn < numax then 1007 1007 begin 1008 CreateUnit( p, Project and cpIndex);1008 CreateUnit(P, Project and cpIndex); 1009 1009 Un[nUn - 1].Loc := Loc; 1010 1010 with Un[nUn - 1] do … … 1020 1020 Flags := Flags or unConscripts; 1021 1021 end; 1022 PlaceUnit( p, nUn - 1);1022 PlaceUnit(P, nUn - 1); 1023 1023 UpdateUnitMap(Loc); 1024 1024 if Model[Project and cpIndex].Kind = mkSettler then 1025 dec(SizeMod, 2) { settler produced - city shrink }1025 Dec(SizeMod, 2) { settler produced - city shrink } 1026 1026 else if (Model[Project and cpIndex].Kind = mkSlaves) or 1027 1027 (Project and cpConscripts <> 0) then 1028 dec(SizeMod); { slaves/conscripts produced - city shrink }1028 Dec(SizeMod); { slaves/conscripts produced - city shrink } 1029 1029 end; 1030 1030 Project0 := Project or cpRepeat or cpCompleted; … … 1032 1032 else if Imp[Project and cpIndex].Kind = ikShipPart then 1033 1033 begin { produce ship parts } 1034 inc(GShip[p].Parts[Project and cpIndex - imShipComp]);1034 Inc(GShip[P].Parts[Project and cpIndex - imShipComp]); 1035 1035 Project0 := Project or cpCompleted; 1036 1036 end … … 1038 1038 begin 1039 1039 NewImp := Project and cpIndex; 1040 inc(Money, Prod); { change rest to money }1040 Inc(Money, Prod); { change rest to money } 1041 1041 Project0 := Project or cpCompleted; 1042 1042 Project := cpImp + imTrGoods; … … 1045 1045 if Imp[NewImp].Kind in [ikNatLocal, ikNatGlobal] then 1046 1046 begin // nat. project 1047 for i:= 0 to nCity - 1 do1048 if (City[ i].Loc >= 0) and (City[i].Built[NewImp] = 1) then1047 for I := 0 to nCity - 1 do 1048 if (City[I].Loc >= 0) and (City[I].Built[NewImp] = 1) then 1049 1049 begin { allowed only once } 1050 inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[p]] div 12);1051 City[ i].Built[NewImp] := 0;1050 Inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[P]] div 12); 1051 City[I].Built[NewImp] := 0; 1052 1052 end; 1053 1053 NatBuilt[NewImp] := 1; … … 1056 1056 case NewImp of 1057 1057 imGrWall: 1058 GrWallContinent[ p] := Continent[Loc];1058 GrWallContinent[P] := Continent[Loc]; 1059 1059 end; 1060 1060 end; … … 1063 1063 begin // wonder 1064 1064 GWonder[NewImp].CityID := ID; 1065 GWonder[NewImp].EffectiveOwner := p;1065 GWonder[NewImp].EffectiveOwner := P; 1066 1066 CheckExpiration(NewImp); 1067 1067 … … 1070 1070 woEiffel: 1071 1071 begin // reactivate wonders 1072 for i:= 0 to nWonder - 1 do1073 if Imp[ i].Expiration >= 0 then1072 for I := 0 to nWonder - 1 do 1073 if Imp[I].Expiration >= 0 then 1074 1074 for cix2 := 0 to nCity - 1 do 1075 if (City[cix2].Loc >= 0) and (City[cix2].Built[ i] = 1)1075 if (City[cix2].Loc >= 0) and (City[cix2].Built[I] = 1) 1076 1076 then 1077 GWonder[ i].EffectiveOwner := p;1077 GWonder[I].EffectiveOwner := P; 1078 1078 end; 1079 1079 woLighthouse: 1080 CheckSpecialModels( p, preLighthouse);1080 CheckSpecialModels(P, preLighthouse); 1081 1081 woLeo: 1082 1082 begin 1083 inc(Research, TechBaseCost(nTech[p], Difficulty[p]) +1084 TechBaseCost(nTech[ p] + 2, Difficulty[p]));1085 CheckSpecialModels( p, preLeo);1083 Inc(Research, TechBaseCost(nTech[P], Difficulty[P]) + 1084 TechBaseCost(nTech[P] + 2, Difficulty[P])); 1085 CheckSpecialModels(P, preLeo); 1086 1086 end; 1087 1087 woPyramids: 1088 CheckSpecialModels( p, preBuilder);1088 CheckSpecialModels(P, preBuilder); 1089 1089 woMir: 1090 1090 begin 1091 1091 for p1 := 0 to nPl - 1 do 1092 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1092 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1093 1093 begin 1094 if RW[ p].Treaty[p1] = trNoContact then1095 IntroduceEnemy( p, p1);1096 GiveCivilReport( p, p1);1097 GiveMilReport( p, p1);1094 if RW[P].Treaty[p1] = trNoContact then 1095 IntroduceEnemy(P, p1); 1096 GiveCivilReport(P, p1); 1097 GiveMilReport(P, p1); 1098 1098 end; 1099 1099 end; … … 1101 1101 end; 1102 1102 1103 for i:= 0 to nImpReplacement - 1 do // sell obsolete buildings1104 if (ImpReplacement[ i].NewImp = NewImp) and1105 (Built[ImpReplacement[ i].OldImp] > 0) then1103 for I := 0 to nImpReplacement - 1 do // sell obsolete buildings 1104 if (ImpReplacement[I].NewImp = NewImp) and 1105 (Built[ImpReplacement[I].OldImp] > 0) then 1106 1106 begin 1107 inc(RW[p].Money, Imp[ImpReplacement[i].OldImp].Cost * BuildCostMod1108 [Difficulty[ p]] div 12);1109 Built[ImpReplacement[ i].OldImp] := 0;1107 Inc(RW[P].Money, Imp[ImpReplacement[I].OldImp].Cost * BuildCostMod 1108 [Difficulty[P]] div 12); 1109 Built[ImpReplacement[I].OldImp] := 0; 1110 1110 end; 1111 1111 1112 1112 if NewImp in [imPower, imHydro, imNuclear] then 1113 for i:= 0 to nImp - 1 do1114 if ( i <> NewImp) and (iin [imPower, imHydro, imNuclear]) and1115 (Built[ i] > 0) then1113 for I := 0 to nImp - 1 do 1114 if (I <> NewImp) and (I in [imPower, imHydro, imNuclear]) and 1115 (Built[I] > 0) then 1116 1116 begin // sell obsolete power plant 1117 inc(RW[p].Money, Imp[i].Cost * BuildCostMod[Difficulty[p]1117 Inc(RW[P].Money, Imp[I].Cost * BuildCostMod[Difficulty[P] 1118 1118 ] div 12); 1119 Built[ i] := 0;1119 Built[I] := 0; 1120 1120 end; 1121 1121 … … 1123 1123 end; 1124 1124 Prod0 := Prod; 1125 inc(Flags, chProduction);1125 Inc(Flags, chProduction); 1126 1126 end 1127 1127 else … … 1135 1135 if SizeMod > 0 then 1136 1136 begin 1137 CityGrowth( p, cix);1138 inc(Flags, chPopIncrease);1139 end; 1140 result := Size + SizeMod >= 2;1141 if result then1137 CityGrowth(P, cix); 1138 Inc(Flags, chPopIncrease); 1139 end; 1140 Result := Size + SizeMod >= 2; 1141 if Result then 1142 1142 while SizeMod < 0 do 1143 1143 begin 1144 CityShrink( p, cix);1145 inc(SizeMod);1144 CityShrink(P, cix); 1145 Inc(SizeMod); 1146 1146 end; 1147 1147 end; … … 1152 1152 ____________________________________________________________________ 1153 1153 } 1154 function SetCityTiles( p, cix, NewTiles: integer;1155 TestOnly: boolean = false): integer;1156 var 1157 V21, Working, ChangeTiles, AddTiles, Loc1: integer;1154 function SetCityTiles(P, cix, NewTiles: Integer; 1155 TestOnly: Boolean = False): Integer; 1156 var 1157 V21, Working, ChangeTiles, AddTiles, Loc1: Integer; 1158 1158 CityAreaInfo: TCityAreaInfo; 1159 1159 Radius: TVicinity21Loc; 1160 1160 begin 1161 with RW[ p].City[cix] do1161 with RW[P].City[cix] do 1162 1162 begin 1163 ChangeTiles := NewTiles xor integer(Tiles);1163 ChangeTiles := NewTiles xor Integer(Tiles); 1164 1164 AddTiles := NewTiles and not Tiles; 1165 1165 if Mode = moPlaying then … … 1167 1167 if NewTiles and not $67F7F76 <> 0 then 1168 1168 begin 1169 result := eInvalid;1170 exit1169 Result := eInvalid; 1170 Exit 1171 1171 end; // invalid tile index included 1172 1172 if NewTiles and (1 shl 13) = 0 then 1173 1173 begin 1174 result := eViolation;1175 exit1174 Result := eViolation; 1175 Exit 1176 1176 end; // city tile must be exploited 1177 1177 if ChangeTiles = 0 then 1178 1178 begin 1179 result := eNotChanged;1180 exit1179 Result := eNotChanged; 1180 Exit 1181 1181 end; 1182 1182 if AddTiles <> 0 then 1183 1183 begin 1184 1184 // check if new tiles possible 1185 GetCityAreaInfo( p, Loc, CityAreaInfo);1185 GetCityAreaInfo(P, Loc, CityAreaInfo); 1186 1186 for V21 := 1 to 26 do 1187 1187 if AddTiles and (1 shl V21) <> 0 then 1188 1188 if CityAreaInfo.Available[V21] <> faAvailable then 1189 1189 begin 1190 result := eTileNotAvailable;1191 exit;1190 Result := eTileNotAvailable; 1191 Exit; 1192 1192 end; 1193 1193 // not more tiles than inhabitants … … 1195 1195 for V21 := 1 to 26 do 1196 1196 if NewTiles and (1 shl V21) <> 0 then 1197 inc(Working);1197 Inc(Working); 1198 1198 if Working > Size then 1199 1199 begin 1200 result := eNoWorkerAvailable;1201 exit;1202 end; 1203 end; 1204 end; 1205 result := eOk;1200 Result := eNoWorkerAvailable; 1201 Exit; 1202 end; 1203 end; 1204 end; 1205 Result := eOk; 1206 1206 if not TestOnly then 1207 1207 begin … … 1211 1211 begin 1212 1212 Loc1 := Radius[V21]; 1213 assert((Loc1 >= 0) and (Loc1 < MapSize));1213 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1214 1214 if NewTiles and (1 shl V21) <> 0 then 1215 1215 UsedByCity[Loc1] := Loc // employ tile 1216 1216 else if UsedByCity[Loc1] <> Loc then 1217 assert(Mode < moPlaying)1217 Assert(Mode < moPlaying) 1218 1218 // should only happen during loading, because of wrong sSetCityTiles command order 1219 1219 else … … 1225 1225 end; 1226 1226 1227 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);1227 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 1228 1228 const 1229 1229 oFood = 0; … … 1240 1240 end; 1241 1241 var 1242 i, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking,1242 I, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking, 1243 1243 WantedProd, MinFood, MinProd, count, Take, MaxTake, AreaSize, FormulaCode, 1244 1244 NeedRare, RareTiles, cix1, dx, dy, BestTiles, ProdBeforeBoost, TestTiles, 1245 SubPlus, SuperPlus: integer;1246 SuperValue, BestSuperValue, SubValue, BestSubValue: integer;1247 Value, BestValue, ValuePlus: extended;1248 ValueFormula_Weight: array [oFood .. oScience] of extended;1249 ValueFormula_Multiply: array [oFood .. oScience] of boolean;1250 Output: array [oFood .. oScience] of integer;1245 SubPlus, SuperPlus: Integer; 1246 SuperValue, BestSuperValue, SubValue, BestSubValue: Integer; 1247 Value, BestValue, ValuePlus: Extended; 1248 ValueFormula_Weight: array [oFood .. oScience] of Extended; 1249 ValueFormula_Multiply: array [oFood .. oScience] of Boolean; 1250 Output: array [oFood .. oScience] of Integer; 1251 1251 TileInfo, BaseTileInfo: TTileInfo; 1252 1252 Radius, Radius1: TVicinity21Loc; … … 1255 1255 CityAreaInfo: TCityAreaInfo; 1256 1256 Hierarchy: array [0 .. 20, 0 .. 31] of TTileData; 1257 nTile, nSelection: array [0 .. 20] of integer;1258 SubCriterion: array [0 .. 27] of integer;1259 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: boolean;1260 begin 1261 if (RW[ p].Government = gAnarchy) or (RW[p].City[cix].Flags and chCaptured <> 0)1257 nTile, nSelection: array [0 .. 20] of Integer; 1258 SubCriterion: array [0 .. 27] of Integer; 1259 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: Boolean; 1260 begin 1261 if (RW[P].Government = gAnarchy) or (RW[P].City[cix].Flags and chCaptured <> 0) 1262 1262 then 1263 1263 begin … … 1265 1265 Advice.Tiles := 1 shl CityOwnTile; 1266 1266 Advice.CityReport.HypoTiles := 1 shl CityOwnTile; 1267 exit;1268 end; 1269 1270 for i:= oFood to oScience do1267 Exit; 1268 end; 1269 1270 for I := oFood to oScience do 1271 1271 begin // decode evaluation formula from weights parameter 1272 FormulaCode := Advice.ResourceWeights shr (24 - 8 * i) and $FF;1273 ValueFormula_Multiply[ i] := FormulaCode and $80 <> 0;1272 FormulaCode := Advice.ResourceWeights shr (24 - 8 * I) and $FF; 1273 ValueFormula_Multiply[I] := FormulaCode and $80 <> 0; 1274 1274 if FormulaCode and $40 <> 0 then 1275 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1275 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1276 1276 (1 shl (FormulaCode and $30 shr 4)) / 16 1277 1277 else 1278 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1278 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1279 1279 (1 shl (FormulaCode and $30 shr 4)); 1280 1280 end; … … 1283 1283 TestReport.HypoTax := -1; 1284 1284 TestReport.HypoLux := -1; 1285 GetSmallCityReport( p, cix, TestReport, @CityReportEx);1286 with RW[ p].City[cix] do1285 GetSmallCityReport(P, cix, TestReport, @CityReportEx); 1286 with RW[P].City[cix] do 1287 1287 begin 1288 1288 V21_to_Loc(Loc, Radius); 1289 FoodToTax := RW[ p].Government = gFuture;1289 FoodToTax := RW[P].Government = gFuture; 1290 1290 ProdToTax := Project and (cpImp + cpIndex) = cpImp + imTrGoods; 1291 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[ p]]) and1292 not CanCityGrow( p, cix);1291 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[P]]) and 1292 not CanCityGrow(P, cix); 1293 1293 1294 1294 // sub criteria … … 1300 1300 V21 xor $15; 1301 1301 end; 1302 for cix1 := 0 to RW[ p].nCity - 1 do1302 for cix1 := 0 to RW[P].nCity - 1 do 1303 1303 if cix1 <> cix then 1304 1304 begin 1305 Loc1 := RW[ p].City[cix1].Loc;1305 Loc1 := RW[P].City[cix1].Loc; 1306 1306 if Loc1 >= 0 then 1307 1307 begin … … 1316 1316 begin 1317 1317 dxdy(Loc, Loc1, dx, dy); 1318 dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);1318 Dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160); 1319 1319 end; 1320 1320 end; … … 1323 1323 end; 1324 1324 1325 GetCityAreaInfo( p, Loc, CityAreaInfo);1325 GetCityAreaInfo(P, Loc, CityAreaInfo); 1326 1326 AreaSize := 0; 1327 1327 for V21 := 1 to 26 do 1328 1328 if CityAreaInfo.Available[V21] = faAvailable then 1329 inc(AreaSize);1330 1331 if RW[ p].Government = gFundamentalism then1329 Inc(AreaSize); 1330 1331 if RW[P].Government = gFundamentalism then 1332 1332 begin 1333 1333 MinWorking := Size; … … 1339 1339 if MinWorking > Size then 1340 1340 MinWorking := Size; 1341 if (RW[ p].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury1341 if (RW[P].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury 1342 1342 then 1343 1343 MaxWorking := MinWorking … … 1376 1376 Loc1 := Radius[V21]; 1377 1377 if (Loc1 >= 0) and (Loc1 < MapSize) and 1378 (RealMap[Loc1] and fModern = cardinal(NeedRare)) then1378 (RealMap[Loc1] and fModern = Cardinal(NeedRare)) then 1379 1379 RareTiles := RareTiles or (1 shl V21); 1380 1380 end; … … 1388 1388 begin 1389 1389 Loc1 := Radius[V21]; 1390 assert((Loc1 >= 0) and (Loc1 < MapSize));1391 GetTileInfo( p, cix, Loc1, TileInfo);1390 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1391 GetTileInfo(P, cix, Loc1, TileInfo); 1392 1392 if V21 = CityOwnTile then 1393 1393 BaseTileInfo := TileInfo … … 1405 1405 (TileInfo.Trade = Hierarchy[iH, iT].Trade) and 1406 1406 (SubCriterion[V21] >= SubCriterion[Hierarchy[iH, iT].V21])) do 1407 inc(iT);1407 Inc(iT); 1408 1408 if (iT = nTile[iH]) // new worst tile in this hierarchy 1409 1409 or ((TileInfo.Food >= Hierarchy[iH, iT].Food) … … 1411 1411 and (TileInfo.Prod >= Hierarchy[iH, iT].Prod) and 1412 1412 (TileInfo.Trade >= Hierarchy[iH, iT].Trade)) then 1413 break; // insert position found!1414 inc(iH);1413 Break; // insert position found! 1414 Inc(iH); 1415 1415 end; 1416 1416 if iH = nHierarchy then 1417 1417 begin // need to start new hierarchy 1418 1418 nTile[iH] := 0; 1419 inc(nHierarchy);1419 Inc(nHierarchy); 1420 1420 iT := 0; 1421 1421 end; 1422 move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],1422 Move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1], 1423 1423 (nTile[iH] - iT) * SizeOf(TTileData)); 1424 inc(nTile[iH]);1424 Inc(nTile[iH]); 1425 1425 Hierarchy[iH, iT].V21 := V21; 1426 1426 Hierarchy[iH, iT].Food := TileInfo.Food; … … 1438 1438 begin 1439 1439 Loc1 := Radius[V21]; 1440 assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));1441 GetTileInfo( p, cix, Loc1, TileInfo);1440 Assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize)); 1441 GetTileInfo(P, cix, Loc1, TileInfo); 1442 1442 if iH = nHierarchy then 1443 1443 begin // need to start new hierarchy 1444 1444 nTile[iH] := 0; 1445 inc(nHierarchy);1445 Inc(nHierarchy); 1446 1446 iT := 0; 1447 1447 end 1448 1448 else 1449 1449 iT := nTile[iH]; 1450 inc(nTile[iH]);1450 Inc(nTile[iH]); 1451 1451 Hierarchy[iH, iT].V21 := V21; 1452 1452 Hierarchy[iH, iT].Food := TileInfo.Food; // = 0 … … 1457 1457 end; 1458 1458 if Built[imAlgae] > 0 then 1459 inc(BaseTileInfo.Food, 12);1459 Inc(BaseTileInfo.Food, 12); 1460 1460 1461 1461 // step 2: summarize resources 1462 1462 for iH := 0 to nHierarchy - 1 do 1463 1463 begin 1464 move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));1464 Move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData)); 1465 1465 Hierarchy[iH, 0].Food := 0; 1466 1466 Hierarchy[iH, 0].Prod := 0; … … 1470 1470 for iT := 1 to nTile[iH] do 1471 1471 begin 1472 inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food);1473 inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod);1474 inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade);1475 inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue);1472 Inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food); 1473 Inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod); 1474 Inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade); 1475 Inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue); 1476 1476 Hierarchy[iH, iT].V21 := 1 shl Hierarchy[iH, iT].V21 + 1477 1477 Hierarchy[iH, iT - 1].V21; … … 1501 1501 (ProdBeforeBoost < WantedProd)) do 1502 1502 begin 1503 assert(nSelection[iH] = 0);1503 Assert(nSelection[iH] = 0); 1504 1504 Take := MinWorking - TestReport.Working; 1505 1505 if Take > nTile[iH] then … … 1514 1514 while (Take < MaxTake) and 1515 1515 (TestReport.FoodRep + Hierarchy[iH, Take].Food < MinFood) do 1516 inc(Take);1516 Inc(Take); 1517 1517 while (Take < MaxTake) and 1518 1518 (ProdBeforeBoost + Hierarchy[iH, Take].Prod < MinProd) do 1519 inc(Take);1519 Inc(Take); 1520 1520 end; 1521 1521 nSelection[iH] := Take; 1522 inc(TestReport.Working, Take);1522 Inc(TestReport.Working, Take); 1523 1523 with Hierarchy[iH, Take] do 1524 1524 begin 1525 inc(TestReport.FoodRep, Food);1526 inc(ProdBeforeBoost, Prod);1527 inc(TestReport.Trade, Trade);1528 end; 1529 inc(iH);1530 end; 1531 1532 assert((TestReport.Working >= MinWorking) and1525 Inc(TestReport.FoodRep, Food); 1526 Inc(ProdBeforeBoost, Prod); 1527 Inc(TestReport.Trade, Trade); 1528 end; 1529 Inc(iH); 1530 end; 1531 1532 Assert((TestReport.Working >= MinWorking) and 1533 1533 (TestReport.Working <= MaxWorking)); 1534 1534 if (TestReport.FoodRep >= MinFood) and (ProdBeforeBoost >= MinProd) then 1535 1535 begin 1536 SplitTrade(TestReport.Trade, RW[ p].TaxRate, RW[p].LuxRate,1536 SplitTrade(TestReport.Trade, RW[P].TaxRate, RW[P].LuxRate, 1537 1537 TestReport.Working, CityReportEx.TradeProcessing, 1538 1538 TestReport.Corruption, TestReport.Tax, TestReport.Lux, … … 1543 1543 TestReport.Deployed >= Size then 1544 1544 begin // city is not in disorder -- evaluate combination 1545 inc(count);1545 Inc(count); 1546 1546 if (MinProd < WantedProd) and (ProdBeforeBoost > MinProd) then 1547 1547 begin // no combination reached wanted prod yet … … 1591 1591 then 1592 1592 begin 1593 inc(Output[oTax], Output[oFood]);1593 Inc(Output[oTax], Output[oFood]); 1594 1594 Output[oFood] := 0; 1595 1595 end; … … 1603 1603 if NeedRare > 0 then 1604 1604 begin 1605 RareOK := false;1605 RareOK := False; 1606 1606 for iH := 0 to nHierarchy - 1 do 1607 1607 if Hierarchy[iH, nSelection[iH]].V21 and RareTiles <> 0 then 1608 RareOK := true;1608 RareOK := True; 1609 1609 if not RareOK then 1610 1610 TestReport.ProdRep := TestReport.Support; … … 1613 1613 if ProdToTax then 1614 1614 begin 1615 inc(Output[oTax], Output[oProd]);1615 Inc(Output[oTax], Output[oProd]); 1616 1616 Output[oProd] := 0; 1617 1617 end; 1618 1618 end; 1619 1619 1620 NeedStep2 := false;1620 NeedStep2 := False; 1621 1621 Value := 0; 1622 for i:= oFood to oScience do1623 if ValueFormula_Multiply[ i] then1624 NeedStep2 := true1622 for I := oFood to oScience do 1623 if ValueFormula_Multiply[I] then 1624 NeedStep2 := True 1625 1625 else 1626 Value := Value + ValueFormula_Weight[ i] * Output[i];1626 Value := Value + ValueFormula_Weight[I] * Output[I]; 1627 1627 if NeedStep2 then 1628 1628 begin 1629 1629 if Value > 0 then 1630 1630 Value := ln(Value) + 123; 1631 for i:= oFood to oScience do1632 if ValueFormula_Multiply[ i] and (Output[i] > 0) then1633 Value := Value + ValueFormula_Weight[ i] *1634 (ln(Output[ i]) + 123);1631 for I := oFood to oScience do 1632 if ValueFormula_Multiply[I] and (Output[I] > 0) then 1633 Value := Value + ValueFormula_Weight[I] * 1634 (ln(Output[I]) + 123); 1635 1635 end; 1636 1636 … … 1643 1643 for iH := 0 to nHierarchy - 1 do 1644 1644 begin 1645 inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);1646 inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);1645 Inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21); 1646 Inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue); 1647 1647 end; 1648 IsBest := true;1648 IsBest := True; 1649 1649 if (SuperPlus = 0) and (ValuePlus = 0.0) then 1650 1650 begin 1651 1651 SubPlus := SubValue - BestSubValue; 1652 1652 if SubPlus < 0 then 1653 IsBest := false1653 IsBest := False 1654 1654 else if SubPlus = 0 then 1655 1655 begin 1656 assert(TestTiles <> BestTiles);1656 Assert(TestTiles <> BestTiles); 1657 1657 IsBest := TestTiles > BestTiles 1658 1658 end … … 1679 1679 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1680 1680 begin 1681 dec(TestReport.FoodRep, Food);1682 dec(ProdBeforeBoost, Prod);1683 dec(TestReport.Trade, Trade);1684 end; 1685 inc(nSelection[iH_Switch]);1686 inc(TestReport.Working);1681 Dec(TestReport.FoodRep, Food); 1682 Dec(ProdBeforeBoost, Prod); 1683 Dec(TestReport.Trade, Trade); 1684 end; 1685 Inc(nSelection[iH_Switch]); 1686 Inc(TestReport.Working); 1687 1687 if (nSelection[iH_Switch] <= nTile[iH_Switch]) and 1688 1688 (TestReport.Working <= MaxWorking) then … … 1690 1690 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1691 1691 begin 1692 inc(TestReport.FoodRep, Food);1693 inc(ProdBeforeBoost, Prod);1694 inc(TestReport.Trade, Trade);1692 Inc(TestReport.FoodRep, Food); 1693 Inc(ProdBeforeBoost, Prod); 1694 Inc(TestReport.Trade, Trade); 1695 1695 end; 1696 break;1697 end; 1698 dec(TestReport.Working, nSelection[iH_Switch]);1696 Break; 1697 end; 1698 Dec(TestReport.Working, nSelection[iH_Switch]); 1699 1699 nSelection[iH_Switch] := 0; 1700 inc(iH_Switch);1700 Inc(iH_Switch); 1701 1701 until iH_Switch = nHierarchy; 1702 1702 until iH_Switch = nHierarchy; // everything tested -- done 1703 1703 end; 1704 assert(BestSuperValue > 0); // advice should always be possible1704 Assert(BestSuperValue > 0); // advice should always be possible 1705 1705 Advice.Tiles := BestTiles; 1706 1706 Advice.CityReport.HypoTiles := BestTiles; … … 1713 1713 procedure InitGame; 1714 1714 var 1715 p, i, mixTownGuard: integer;1715 P, I, mixTownGuard: Integer; 1716 1716 begin 1717 1717 MaxDist := Distance(0, MapSize - lx shr 1); 1718 for p:= 0 to nPl - 1 do1719 if (1 shl pand GAlive <> 0) then1720 with RW[ p] do1718 for P := 0 to nPl - 1 do 1719 if (1 shl P and GAlive <> 0) then 1720 with RW[P] do 1721 1721 begin // initialize capital 1722 1722 mixTownGuard := 0; 1723 1723 while Model[mixTownGuard].Kind <> mkSpecial_TownGuard do 1724 inc(mixTownGuard);1724 Inc(mixTownGuard); 1725 1725 with City[0] do 1726 1726 begin 1727 1727 Built[imPalace] := 1; 1728 1728 Size := 4; 1729 for i:= 2 to Size do1730 AddBestCityTile( p, 0);1729 for I := 2 to Size do 1730 AddBestCityTile(P, 0); 1731 1731 Project := mixTownGuard; 1732 1732 end; -
trunk/CmdList.pas
r438 r447 10 10 MaxDataSize = 1024; 11 11 CommandDataElementSize = 4; 12 CommandDataElementCountMask = $ f;12 CommandDataElementCountMask = $F; 13 13 CommandDataMaxSize = CommandDataElementSize * CommandDataElementCountMask; 14 14 … … 27 27 constructor Create; 28 28 destructor Destroy; override; 29 procedure Get(var Command, Player, Subject: integer; var Data: pointer);30 procedure GetDataChanges(Data: pointer; DataSize: integer);31 procedure Put(Command, Player, Subject: integer; Data: pointer);32 procedure PutDataChanges(Command, Player: integer;33 OldData, NewData: pointer; DataSize: integer);34 procedure LoadFromFile(const f: TFileStream);35 procedure SaveToFile(const f: TFileStream);36 procedure AppendToFile(const f: TFileStream; const OldState: TCmdListState);29 procedure Get(var Command, Player, Subject: Integer; var Data: Pointer); 30 procedure GetDataChanges(Data: Pointer; DataSize: Integer); 31 procedure Put(Command, Player, Subject: Integer; Data: Pointer); 32 procedure PutDataChanges(Command, Player: Integer; 33 OldData, NewData: Pointer; DataSize: Integer); 34 procedure LoadFromFile(const F: TFileStream); 35 procedure SaveToFile(const F: TFileStream); 36 procedure AppendToFile(const F: TFileStream; const OldState: TCmdListState); 37 37 procedure Cut; 38 function Progress: integer;38 function Progress: Integer; 39 39 private 40 LogAlloc: integer; { allocated size of LogData in bytes }40 LogAlloc: Integer; { allocated size of LogData in bytes } 41 41 LogData: ^TLogData; 42 42 FState: TCmdListState; 43 procedure PutData(Data: pointer; Length: integer);43 procedure PutData(Data: Pointer; Length: Integer); 44 44 procedure CompleteMoveCode; 45 45 public … … 92 92 end; 93 93 94 procedure TCmdList.Get(var Command, Player, Subject: integer; var Data: pointer);94 procedure TCmdList.Get(var Command, Player, Subject: Integer; var Data: Pointer); 95 95 var 96 96 DirCode: Cardinal; … … 127 127 else 128 128 begin 129 code := Cardinal((@LogData[FState.LoadPos])^);130 if code and 3 = 0 then129 Code := Cardinal((@LogData[FState.LoadPos])^); 130 if Code and 3 = 0 then 131 131 begin // non-clientex command 132 Command := code shr 2 and $3FFF + sExecute;133 Player := code shr 16 and $F;134 Subject := code shr 20 and $FFF;135 inc(FState.LoadPos, 4);136 end 137 else if code and 7 = 2 then132 Command := Code shr 2 and $3FFF + sExecute; 133 Player := Code shr 16 and $F; 134 Subject := Code shr 20 and $FFF; 135 Inc(FState.LoadPos, 4); 136 end 137 else if Code and 7 = 2 then 138 138 begin // clientex command 139 Command := code shr 3 and $FFFF;140 Player := code shr 19 and $F;139 Command := Code shr 3 and $FFFF; 140 Player := Code shr 19 and $F; 141 141 Subject := 0; 142 inc(FState.LoadPos, 3);142 Inc(FState.LoadPos, 3); 143 143 end 144 144 else 145 145 begin // move command shortcut 146 if ( code and 1 = 1) and (code and (7 shl 4) <> 6 shl 4) then146 if (Code and 1 = 1) and (Code and (7 shl 4) <> 6 shl 4) then 147 147 begin 148 FState.LoadMoveCode := code and $FF;149 inc(FState.LoadPos);148 FState.LoadMoveCode := Code and $FF; 149 Inc(FState.LoadPos); 150 150 end 151 151 else 152 152 begin 153 FState.LoadMoveCode := code and $FFFFFF;154 inc(FState.LoadPos, 3);153 FState.LoadMoveCode := Code and $FFFFFF; 154 Inc(FState.LoadPos, 3); 155 155 end; 156 156 Get(Command, Player, Subject, Data); … … 163 163 begin 164 164 Data := @LogData[FState.LoadPos]; 165 inc(FState.LoadPos, Command and CommandDataElementCountMask * CommandDataElementSize);166 end; 167 end; 168 end; 169 170 procedure TCmdList.GetDataChanges(Data: pointer; DataSize: integer);165 Inc(FState.LoadPos, Command and CommandDataElementCountMask * CommandDataElementSize); 166 end; 167 end; 168 end; 169 170 procedure TCmdList.GetDataChanges(Data: Pointer; DataSize: Integer); 171 171 var 172 b0, b1: integer;172 b0, b1: Integer; 173 173 Map0, Map1: Cardinal; 174 174 begin 175 175 Map0 := Cardinal((@LogData[FState.LoadPos])^); 176 inc(FState.LoadPos, 4);176 Inc(FState.LoadPos, 4); 177 177 b0 := 0; 178 178 while Map0 > 0 do begin 179 179 if Map0 and 1 <> 0 then begin 180 180 Map1 := Cardinal((@LogData[FState.LoadPos])^); 181 inc(FState.LoadPos, 4);181 Inc(FState.LoadPos, 4); 182 182 for b1 := 0 to 31 do 183 183 if 1 shl b1 and Map1 <> 0 then begin 184 184 if b0 * 32 + b1 < DataSize then 185 185 PData(Data)[b0 * 32 + b1] := Cardinal((@LogData[FState.LoadPos])^); 186 inc(FState.LoadPos, 4);186 Inc(FState.LoadPos, 4); 187 187 end; 188 188 end; 189 inc(b0);189 Inc(b0); 190 190 Map0 := Map0 shr 1; 191 191 end; 192 192 end; 193 193 194 procedure TCmdList.Put(Command, Player, Subject: integer; Data: pointer);194 procedure TCmdList.Put(Command, Player, Subject: Integer; Data: Pointer); 195 195 var 196 DirCode, code: Cardinal;196 DirCode, Code: Cardinal; 197 197 begin 198 198 if Command and $FC00 = sMoveUnit then … … 209 209 end; 210 210 if Subject = FState.LastMovingUnit then 211 code := 1 + DirCode shl 1212 else 213 code := 6 + DirCode shl 3 + Cardinal(Subject) shl 6;211 Code := 1 + DirCode shl 1 212 else 213 Code := 6 + DirCode shl 3 + Cardinal(Subject) shl 6; 214 214 if FState.MoveCode = 0 then 215 FState.MoveCode := code215 FState.MoveCode := Code 216 216 else if FState.MoveCode and 1 = 1 then 217 217 begin // FM + this 218 FState.MoveCode := FState.MoveCode + code shl 4;219 if code and 1 = 1 then218 FState.MoveCode := FState.MoveCode + Code shl 4; 219 if Code and 1 = 1 then 220 220 PutData(@FState.MoveCode, 1) // FM + FM 221 221 else … … 223 223 FState.MoveCode := 0; 224 224 end 225 else if code and 1 = 1 then225 else if Code and 1 = 1 then 226 226 begin // M + FM 227 FState.MoveCode := FState.MoveCode + code shl 18;227 FState.MoveCode := FState.MoveCode + Code shl 18; 228 228 PutData(@FState.MoveCode, 3); 229 229 FState.MoveCode := 0; … … 232 232 begin 233 233 PutData(@FState.MoveCode, 3); 234 FState.MoveCode := code;234 FState.MoveCode := Code; 235 235 end; 236 236 FState.LastMovingUnit := Subject; … … 241 241 if Command >= cClientEx then 242 242 begin 243 code := 2 + Command shl 3 + Player shl 19;244 PutData(@ code, 3);245 end 246 else 247 begin 248 code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16 +243 Code := 2 + Command shl 3 + Player shl 19; 244 PutData(@Code, 3); 245 end 246 else 247 begin 248 Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16 + 249 249 Cardinal(Subject) shl 20; 250 PutData(@ code, 4);250 PutData(@Code, 4); 251 251 end; 252 252 end; … … 255 255 end; 256 256 257 procedure TCmdList.PutDataChanges(Command, Player: integer;258 OldData, NewData: pointer; DataSize: integer);257 procedure TCmdList.PutDataChanges(Command, Player: Integer; 258 OldData, NewData: Pointer; DataSize: Integer); 259 259 var 260 MapPos, LogPos, b0, b1, RowEnd: integer;261 Map0, Map1, code: Cardinal;260 MapPos, LogPos, b0, b1, RowEnd: Integer; 261 Map0, Map1, Code: Cardinal; 262 262 begin 263 263 if DataSize <= 0 then 264 exit;264 Exit; 265 265 if DataSize > MaxDataSize then 266 266 DataSize := MaxDataSize; … … 273 273 if LogPos + 4 * 32 > LogAlloc then 274 274 begin 275 inc(LogAlloc, LogGrow);275 Inc(LogAlloc, LogGrow); 276 276 ReallocMem(LogData, LogAlloc); 277 277 end; … … 287 287 begin 288 288 Cardinal((@LogData[LogPos])^) := PData(NewData)[b1]; 289 inc(LogPos, 4);290 inc(Map1, $80000000);289 Inc(LogPos, 4); 290 Inc(Map1, $80000000); 291 291 end; 292 292 end; … … 296 296 Cardinal((@LogData[MapPos])^) := Map1; 297 297 MapPos := LogPos; 298 inc(LogPos, 4);299 inc(Map0, $80000000);298 Inc(LogPos, 4); 299 Inc(Map0, $80000000); 300 300 end; 301 301 end; 302 302 if Map0 = 0 then 303 exit; // no changes303 Exit; // no changes 304 304 305 305 Map0 := Map0 shr (31 - (DataSize - 1) div 32); 306 306 Cardinal((@LogData[FState.nLog + 4])^) := Map0; 307 code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;308 Cardinal((@LogData[FState.nLog])^) := code;307 Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16; 308 Cardinal((@LogData[FState.nLog])^) := Code; 309 309 FState.nLog := MapPos; 310 310 end; 311 311 312 procedure TCmdList.PutData(Data: pointer; Length: integer);312 procedure TCmdList.PutData(Data: Pointer; Length: Integer); 313 313 begin 314 314 if FState.nLog + Length > LogAlloc then 315 315 begin 316 inc(LogAlloc, LogGrow);316 Inc(LogAlloc, LogGrow); 317 317 ReallocMem(LogData, LogAlloc); 318 318 end; 319 move(Data^, LogData[FState.nLog], Length);320 inc(FState.nLog, Length);319 Move(Data^, LogData[FState.nLog], Length); 320 Inc(FState.nLog, Length); 321 321 end; 322 322 … … 333 333 end; 334 334 335 procedure TCmdList.LoadFromFile(const f: TFileStream);336 begin 337 f.read(FState.nLog, 4);335 procedure TCmdList.LoadFromFile(const F: TFileStream); 336 begin 337 F.read(FState.nLog, 4); 338 338 LogData := nil; 339 339 LogAlloc := ((FState.nLog + 2) div LogGrow + 1) * LogGrow; 340 340 ReallocMem(LogData, LogAlloc); 341 f.read(LogData^, FState.nLog);341 F.read(LogData^, FState.nLog); 342 342 FState.LoadPos := 0; 343 343 end; 344 344 345 procedure TCmdList.SaveToFile(const f: TFileStream);345 procedure TCmdList.SaveToFile(const F: TFileStream); 346 346 begin 347 347 CompleteMoveCode; 348 f.write(FState.nLog, 4);349 f.write(LogData^, FState.nLog);350 end; 351 352 procedure TCmdList.AppendToFile(const f: TFileStream;348 F.write(FState.nLog, 4); 349 F.write(LogData^, FState.nLog); 350 end; 351 352 procedure TCmdList.AppendToFile(const F: TFileStream; 353 353 const OldState: TCmdListState); 354 354 begin 355 355 CompleteMoveCode; 356 f.write(FState.nLog, 4);357 f.Position := f.Position + OldState.nLog;358 f.write(LogData[OldState.nLog], FState.nLog - OldState.nLog);356 F.write(FState.nLog, 4); 357 F.Position := F.Position + OldState.nLog; 358 F.write(LogData[OldState.nLog], FState.nLog - OldState.nLog); 359 359 end; 360 360 … … 364 364 end; 365 365 366 function TCmdList.Progress: integer;366 function TCmdList.Progress: Integer; 367 367 begin 368 368 if (FState.LoadPos = FState.nLog) and (FState.LoadMoveCode = 0) then 369 result := 1000 // loading complete369 Result := 1000 // loading complete 370 370 else if FState.nLog > 1 shl 20 then 371 result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)371 Result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8) 372 372 else 373 result := FState.LoadPos * 999 div FState.nLog;373 Result := FState.LoadPos * 999 div FState.nLog; 374 374 end; 375 375 … … 379 379 Byte3 Byte2 Byte1 Byte0 380 380 ssssssss sssspppp cccccccc cccccc00 381 ( c = Command-sExecute, p = Player, s= Subject)381 (C = Command-sExecute, P = Player, S = Subject) 382 382 383 383 ClientEx-Command: 384 384 Byte2 Byte1 Byte0 385 385 0ppppccc cccccccc ccccc010 386 ( c = Command, p= Player)386 (C = Command, P = Player) 387 387 388 388 Single Move: 389 389 Byte2 Byte1 Byte0 390 390 000000ss ssssssss ssaaa110 391 ( a = Direction, s= Subject)391 (A = Direction, S = Subject) 392 392 393 393 Move + Follow Move: 394 394 Byte2 Byte1 Byte0 395 395 00bbb1ss ssssssss ssaaa110 396 ( a = Direction 1, s = Subject 1, b= Direction 2)396 (A = Direction 1, S = Subject 1, B = Direction 2) 397 397 398 398 Follow Move + Move: 399 399 Byte2 Byte1 Byte0 400 400 00ssssss ssssssbb b110aaa1 401 ( a = Direction 1, b = Direction 2, s= Subject 2)401 (A = Direction 1, B = Direction 2, S = Subject 2) 402 402 403 403 Single Follow Move: 404 404 Byte0 405 405 0000aaa1 406 ( a= Direction)406 (A = Direction) 407 407 408 408 Double Follow Move: 409 409 Byte0 410 410 bbb1aaa1 411 ( a = Direction 1, b= Direction 2)411 (A = Direction 1, B = Direction 2) 412 412 } 413 413 -
trunk/Database.pas
r442 r447 26 26 27 27 nStartUn = 1; 28 StartUn: array [0 .. nStartUn - 1] of integer = (0); // mix of start units28 StartUn: array [0 .. nStartUn - 1] of Integer = (0); // mix of start units 29 29 30 30 CityOwnTile = 13; … … 50 50 Mode: TGameMode; 51 51 GWonder: array [0 .. nWonder - 1] of TWonderInfo; 52 ServerVersion: array [0 .. nPl - 1] of integer;53 ProcessClientData: array [0 .. nPl - 1] of boolean;52 ServerVersion: array [0 .. nPl - 1] of Integer; 53 ProcessClientData: array [0 .. nPl - 1] of Boolean; 54 54 CL: TCmdList; 55 55 {$IFDEF TEXTLOG}CmdInfo: string; … … 58 58 // map data 59 59 RealMap: array [0 .. lxmax * lymax - 1] of Cardinal; 60 Continent: array [0 .. lxmax * lymax - 1] of integer;60 Continent: array [0 .. lxmax * lymax - 1] of Integer; 61 61 { continent id for each tile } 62 62 Occupant: array [0 .. lxmax * lymax - 1] of ShortInt; … … 65 65 ObserveLevel: array [0 .. lxmax * lymax - 1] of Cardinal; 66 66 { Observe Level of player p in bits 2*p and 2*p+1 } 67 UsedByCity: array [0 .. lxmax * lymax - 1] of integer;67 UsedByCity: array [0 .. lxmax * lymax - 1] of Integer; 68 68 { location of exploiting city for 69 69 each tile, =-1 if not exploited } … … 71 71 // player data 72 72 RW: array [0 .. nPl - 1] of TPlayerContext; { player data } 73 Difficulty: array [0 .. nPl - 1] of integer;73 Difficulty: array [0 .. nPl - 1] of Integer; 74 74 GShip: array [0 .. nPl - 1] of TShipInfo; 75 75 ResourceMask: array [0 .. nPl - 1] of Cardinal; 76 Founded: array [0 .. nPl - 1] of integer; { number of cities founded }77 TerritoryCount: array [0 .. nPl] of integer;76 Founded: array [0 .. nPl - 1] of Integer; { number of cities founded } 77 TerritoryCount: array [0 .. nPl] of Integer; 78 78 LastValidStat, Researched, Discovered, // number of tiles discovered 79 GrWallContinent: array [0 .. nPl - 1] of integer;79 GrWallContinent: array [0 .. nPl - 1] of Integer; 80 80 RWemix: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt; 81 81 // [p1,p2,mix] -> index of p2's model mix in p1's enemy model list 82 82 Destroyed: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt; 83 83 // [p1,p2,mix] -> number of p2's units with model mix that p1 has destroyed 84 nTech: array [0 .. nPl - 1] of integer; { number of known techs }84 nTech: array [0 .. nPl - 1] of Integer; { number of known techs } 85 85 // NewContact: array[0..nPl-1,0..nPl-1] of boolean; 86 86 87 87 type 88 TVicinity8Loc = array [0 .. 7] of integer;89 TVicinity21Loc = array [0 .. 27] of integer;90 91 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);92 procedure IntServer(Command, Player, Subject: integer; var Data);93 procedure CompactLists( p: integer);94 procedure ClearTestFlags(ClearFlags: integer);95 procedure SetTestFlags( p, SetFlags: integer);88 TVicinity8Loc = array [0 .. 7] of Integer; 89 TVicinity21Loc = array [0 .. 27] of Integer; 90 91 procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal); 92 procedure IntServer(Command, Player, Subject: Integer; var Data); 93 procedure CompactLists(P: Integer); 94 procedure ClearTestFlags(ClearFlags: Integer); 95 procedure SetTestFlags(P, SetFlags: Integer); 96 96 97 97 // Tech Related Functions 98 function TechBaseCost(nTech, diff: integer): integer;99 function TechCost( p: integer): integer;100 procedure CalculateModel(var m: TModel);101 procedure CheckSpecialModels( p, pre: integer);102 procedure EnableDevModel( p: integer);103 procedure SeeTech( p, ad: integer);104 procedure DiscoverTech( p, ad: integer);105 procedure CheckExpiration(Wonder: integer);98 function TechBaseCost(nTech, diff: Integer): Integer; 99 function TechCost(P: Integer): Integer; 100 procedure CalculateModel(var M: TModel); 101 procedure CheckSpecialModels(P, pre: Integer); 102 procedure EnableDevModel(P: Integer); 103 procedure SeeTech(P, ad: Integer); 104 procedure DiscoverTech(P, ad: Integer); 105 procedure CheckExpiration(Wonder: Integer); 106 106 107 107 // Location Navigation 108 function dLoc(Loc, dx, dy: integer): integer;109 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);110 function Distance(Loc0, Loc1: integer): integer;111 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);112 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);108 function dLoc(Loc, dx, dy: Integer): Integer; 109 procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer); 110 function Distance(Loc0, Loc1: Integer): Integer; 111 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 112 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 113 113 114 114 // Game Initialization 115 115 procedure InitRandomGame; 116 procedure InitMapGame(Human: integer);116 procedure InitMapGame(Human: Integer); 117 117 procedure ReleaseGame; 118 118 119 119 // Map Editor 120 function MapGeneratorAvailable: boolean;120 function MapGeneratorAvailable: Boolean; 121 121 procedure CreateElevation; 122 procedure CreateMap(preview: boolean);122 procedure CreateMap(preview: Boolean); 123 123 procedure InitMapEditor; 124 124 procedure ReleaseMapEditor; 125 procedure EditTile(Loc, NewTile: integer);125 procedure EditTile(Loc, NewTile: Integer); 126 126 127 127 // Map Revealing 128 function GetTileInfo( p, cix, Loc: integer; var Info: TTileInfo): integer;129 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);130 function UnitSpeed( p, mix, Health: integer): integer;131 procedure GetUnitReport( p, uix: integer; var UnitReport: TUnitReport);132 procedure SearchCity(Loc: integer; var p, cix: integer);133 procedure TellAboutModel( p, taOwner, tamix: integer);134 function emixSafe( p, taOwner, tamix: integer): integer;135 function Discover9(Loc, p, Level: integer;136 TellAllied, EnableContact: boolean): boolean;137 function Discover21(Loc, p, AdjacentLevel: integer;138 TellAllied, EnableContact: boolean): boolean;139 procedure DiscoverAll( p, Level: integer);140 procedure DiscoverViewAreas( p: integer);141 function GetUnitStack( p, Loc: integer): integer;142 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);143 procedure RecalcV8ZoC( p, Loc: integer);144 procedure RecalcMapZoC( p: integer);145 procedure RecalcPeaceMap( p: integer);128 function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer; 129 procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer); 130 function UnitSpeed(P, mix, Health: Integer): Integer; 131 procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport); 132 procedure SearchCity(Loc: Integer; var P, cix: Integer); 133 procedure TellAboutModel(P, taOwner, tamix: Integer); 134 function emixSafe(P, taOwner, tamix: Integer): Integer; 135 function Discover9(Loc, P, Level: Integer; 136 TellAllied, EnableContact: Boolean): Boolean; 137 function Discover21(Loc, P, AdjacentLevel: Integer; 138 TellAllied, EnableContact: Boolean): Boolean; 139 procedure DiscoverAll(P, Level: Integer); 140 procedure DiscoverViewAreas(P: Integer); 141 function GetUnitStack(P, Loc: Integer): Integer; 142 procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False); 143 procedure RecalcV8ZoC(P, Loc: Integer); 144 procedure RecalcMapZoC(P: Integer); 145 procedure RecalcPeaceMap(P: Integer); 146 146 147 147 // Territory Calculation 148 procedure CheckBorders(OriginLoc: integer; PlayerLosingCity: integer = -1);149 procedure LogCheckBorders( p, cix: integer; PlayerLosingCity: integer = -1);148 procedure CheckBorders(OriginLoc: Integer; PlayerLosingCity: Integer = -1); 149 procedure LogCheckBorders(P, cix: Integer; PlayerLosingCity: Integer = -1); 150 150 151 151 // Map Processing 152 procedure CreateUnit( p, mix: integer);153 procedure FreeUnit( p, uix: integer);154 procedure PlaceUnit( p, uix: integer);155 procedure RemoveUnit( p, uix: integer; Enemy: integer = -1);156 procedure RemoveUnit_UpdateMap( p, uix: integer);157 procedure RemoveAllUnits( p, Loc: integer; Enemy: integer = -1);158 procedure RemoveDomainUnits( d, p, Loc: integer);159 procedure FoundCity( p, FoundLoc: integer);160 procedure DestroyCity( p, cix: integer; SaveUnits: boolean);161 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);162 procedure CompleteJob( p, Loc, Job: integer);152 procedure CreateUnit(P, mix: Integer); 153 procedure FreeUnit(P, uix: Integer); 154 procedure PlaceUnit(P, uix: Integer); 155 procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1); 156 procedure RemoveUnit_UpdateMap(P, uix: Integer); 157 procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1); 158 procedure RemoveDomainUnits(D, P, Loc: Integer); 159 procedure FoundCity(P, FoundLoc: Integer); 160 procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean); 161 procedure ChangeCityOwner(pOld, cixOld, pNew: Integer); 162 procedure CompleteJob(P, Loc, Job: Integer); 163 163 164 164 // Diplomacy 165 procedure IntroduceEnemy(p1, p2: integer);166 procedure GiveCivilReport( p, pAbout: integer);167 procedure GiveMilReport( p, pAbout: integer);168 procedure ShowPrice(pSender, pTarget, Price: integer);169 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;170 procedure CancelTreaty( p, pWith: integer; DecreaseCredibility: boolean = true);171 function DoSpyMission( p, pCity, cix, Mission: integer): Cardinal;165 procedure IntroduceEnemy(p1, p2: Integer); 166 procedure GiveCivilReport(P, pAbout: Integer); 167 procedure GiveMilReport(P, pAbout: Integer); 168 procedure ShowPrice(pSender, pTarget, Price: Integer); 169 function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean; 170 procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean = True); 171 function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal; 172 172 173 173 … … 180 180 181 181 var 182 UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }183 184 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);182 UnBuilt: array [0 .. nPl - 1] of Integer; { number of units built } 183 184 procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal); 185 185 var 186 186 I: Integer; 187 187 begin 188 188 for I := 0 to Count - 1 do 189 x[I] := x[I] and Mask;190 end; 191 192 procedure CompactLists( p: integer);193 var 194 uix, uix1, cix: integer;195 {$IFOPT O-}V21: integer;189 X[I] := X[I] and Mask; 190 end; 191 192 procedure CompactLists(P: Integer); 193 var 194 uix, uix1, cix: Integer; 195 {$IFOPT O-}V21: Integer; 196 196 Radius: TVicinity21Loc; {$ENDIF} 197 197 begin 198 with RW[ p] do198 with RW[P] do 199 199 begin 200 200 // compact unit list … … 203 203 if Un[uix].Loc < 0 then 204 204 begin 205 dec(nUn);205 Dec(nUn); 206 206 Un[uix] := Un[nUn]; { replace removed unit by last } 207 207 if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then … … 212 212 end 213 213 else 214 inc(uix);214 Inc(uix); 215 215 216 216 // compact city list … … 219 219 if City[cix].Loc < 0 then 220 220 begin 221 dec(nCity);221 Dec(nCity); 222 222 City[cix] := City[nCity]; { replace city by last } 223 223 for uix1 := 0 to nUn - 1 do … … 227 227 end 228 228 else 229 inc(cix);229 Inc(cix); 230 230 231 231 // compact enemy city list … … 234 234 if EnemyCity[cix].Loc < 0 then 235 235 begin 236 dec(nEnemyCity);236 Dec(nEnemyCity); 237 237 EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last } 238 238 end 239 239 else 240 inc(cix);240 Inc(cix); 241 241 242 242 {$IFOPT O-} … … 247 247 for V21 := 1 to 26 do 248 248 if Tiles and (1 shl V21) <> 0 then 249 assert(UsedByCity[Radius[V21]] = Loc);249 Assert(UsedByCity[Radius[V21]] = Loc); 250 250 end; 251 251 {$ENDIF} … … 257 257 ____________________________________________________________________ 258 258 } 259 function TechBaseCost(nTech, diff: integer): integer;260 var 261 c0: single;259 function TechBaseCost(nTech, diff: Integer): Integer; 260 var 261 c0: Single; 262 262 begin 263 263 c0 := TechFormula_M[diff] * (nTech + 4) * 264 264 exp((nTech + 4) / TechFormula_D[diff]); 265 265 if c0 >= $10000000 then 266 result := $10000000266 Result := $10000000 267 267 else 268 result := trunc(c0);269 end; 270 271 function TechCost( p: integer): integer;272 begin 273 with RW[ p] do274 begin 275 result := TechBaseCost(nTech[p], Difficulty[p]);268 Result := trunc(c0); 269 end; 270 271 function TechCost(P: Integer): Integer; 272 begin 273 with RW[P] do 274 begin 275 Result := TechBaseCost(nTech[P], Difficulty[P]); 276 276 if ResearchTech >= 0 then 277 277 if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then 278 result := result shr 1278 Result := Result shr 1 279 279 else if ResearchTech in FutureTech then 280 280 if Government = gFuture then 281 result := result * 2281 Result := Result * 2 282 282 else 283 result := result * 4;284 end; 285 end; 286 287 procedure SetModelFlags(var m: TModel);288 begin 289 m.Flags := 0;290 if ( m.Domain = dGround) and (m.Kind <> mkDiplomat) then291 m.Flags := m.Flags or mdZOC;292 if ( m.Kind = mkDiplomat) or (m.Attack + m.Cap[mcBombs] = 0) then293 m.Flags := m.Flags or mdCivil;294 if ( m.Cap[mcOver] > 0) or (m.Domain = dSea) and (m.Weight >= 6) then295 m.Flags := m.Flags or mdDoubleSupport;296 end; 297 298 procedure CalculateModel(var m: TModel);283 Result := Result * 4; 284 end; 285 end; 286 287 procedure SetModelFlags(var M: TModel); 288 begin 289 M.Flags := 0; 290 if (M.Domain = dGround) and (M.Kind <> mkDiplomat) then 291 M.Flags := M.Flags or mdZOC; 292 if (M.Kind = mkDiplomat) or (M.Attack + M.Cap[mcBombs] = 0) then 293 M.Flags := M.Flags or mdCivil; 294 if (M.Cap[mcOver] > 0) or (M.Domain = dSea) and (M.Weight >= 6) then 295 M.Flags := M.Flags or mdDoubleSupport; 296 end; 297 298 procedure CalculateModel(var M: TModel); 299 299 { calculate attack, defense, cost... of a model by features } 300 300 var 301 i: integer;302 begin 303 with mdo301 I: Integer; 302 begin 303 with M do 304 304 begin 305 305 Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength; … … 312 312 Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines]; 313 313 if Cap[mcNP] = 0 then 314 inc(Speed, 100 * Cap[mcSE]);314 Inc(Speed, 100 * Cap[mcSE]); 315 315 end; 316 316 dAir: … … 318 318 end; 319 319 Cost := 0; 320 for i:= 0 to nFeature - 1 do321 if 1 shl Domain and Feature[ i].Domains <> 0 then322 inc(Cost, Cap[i] * Feature[i].Cost);320 for I := 0 to nFeature - 1 do 321 if 1 shl Domain and Feature[I].Domains <> 0 then 322 Inc(Cost, Cap[I] * Feature[I].Cost); 323 323 Cost := Cost * MCost; 324 324 Weight := 0; 325 for i:= 0 to nFeature - 1 do326 if 1 shl Domain and Feature[ i].Domains <> 0 then327 if (Domain = dGround) and ( i= mcDefense) then328 inc(Weight, Cap[i] * 2)325 for I := 0 to nFeature - 1 do 326 if 1 shl Domain and Feature[I].Domains <> 0 then 327 if (Domain = dGround) and (I = mcDefense) then 328 Inc(Weight, Cap[I] * 2) 329 329 else 330 inc(Weight, Cap[i] * Feature[i].Weight);331 end; 332 SetModelFlags( m);333 end; 334 335 procedure CheckSpecialModels( p, pre: integer);336 var 337 i, mix1: integer;338 HasAlready: boolean;339 begin 340 for i:= 0 to nSpecialModel -330 Inc(Weight, Cap[I] * Feature[I].Weight); 331 end; 332 SetModelFlags(M); 333 end; 334 335 procedure CheckSpecialModels(P, pre: Integer); 336 var 337 I, mix1: Integer; 338 HasAlready: Boolean; 339 begin 340 for I := 0 to nSpecialModel - 341 341 1 do { check whether new special model available } 342 if (SpecialModelPreq[ i] = pre) and (RW[p].nModel < nmmax) then343 begin 344 HasAlready := false;345 for mix1 := 0 to RW[ p].nModel - 1 do346 if (RW[ p].Model[mix1].Kind = SpecialModel[i].Kind) and347 (RW[ p].Model[mix1].Attack = SpecialModel[i].Attack) and348 (RW[ p].Model[mix1].Speed = SpecialModel[i].Speed) then349 HasAlready := true;342 if (SpecialModelPreq[I] = pre) and (RW[P].nModel < nmmax) then 343 begin 344 HasAlready := False; 345 for mix1 := 0 to RW[P].nModel - 1 do 346 if (RW[P].Model[mix1].Kind = SpecialModel[I].Kind) and 347 (RW[P].Model[mix1].Attack = SpecialModel[I].Attack) and 348 (RW[P].Model[mix1].Speed = SpecialModel[I].Speed) then 349 HasAlready := True; 350 350 if not HasAlready then 351 351 begin 352 RW[ p].Model[RW[p].nModel] := SpecialModel[i];353 SetModelFlags(RW[ p].Model[RW[p].nModel]);354 with RW[ p].Model[RW[p].nModel] do352 RW[P].Model[RW[P].nModel] := SpecialModel[I]; 353 SetModelFlags(RW[P].Model[RW[P].nModel]); 354 with RW[P].Model[RW[P].nModel] do 355 355 begin 356 356 Status := 0; … … 359 359 Built := 0; 360 360 Lost := 0; 361 ID := p shl 12 + RW[p].nModel;362 if (Kind = mkSpecial_Boat) and (ServerVersion[ p] < $000EF0) then361 ID := P shl 12 + RW[P].nModel; 362 if (Kind = mkSpecial_Boat) and (ServerVersion[P] < $000EF0) then 363 363 Speed := 350; // old longboat 364 364 end; 365 inc(RW[p].nModel);366 end; 367 end; 368 end; 369 370 procedure EnableDevModel( p: integer);371 begin 372 with RW[ p] do365 Inc(RW[P].nModel); 366 end; 367 end; 368 end; 369 370 procedure EnableDevModel(P: Integer); 371 begin 372 with RW[P] do 373 373 if nModel < nmmax then 374 374 begin … … 381 381 Built := 0; 382 382 Lost := 0; 383 ID := pshl 12 + nModel;384 end; 385 inc(nModel);386 inc(Researched[p]);387 end; 388 end; 389 390 procedure SeeTech( p, ad: integer);391 begin 392 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [ p, ad]); {$ENDIF}393 RW[ p].Tech[ad] := tsSeen;383 ID := P shl 12 + nModel; 384 end; 385 Inc(nModel); 386 Inc(Researched[P]); 387 end; 388 end; 389 390 procedure SeeTech(P, ad: Integer); 391 begin 392 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [P, ad]); {$ENDIF} 393 RW[P].Tech[ad] := tsSeen; 394 394 // inc(nTech[p]); 395 inc(Researched[p]);395 Inc(Researched[P]); 396 396 end; 397 397 398 398 procedure FreeSlaves; 399 399 var 400 p1, uix: integer;400 p1, uix: Integer; 401 401 begin 402 402 for p1 := 0 to nPl - 1 do … … 407 407 end; 408 408 409 procedure DiscoverTech( p, ad: integer);410 411 procedure TellAboutKeyTech( p, Source: integer);409 procedure DiscoverTech(P, ad: Integer); 410 411 procedure TellAboutKeyTech(P, Source: Integer); 412 412 var 413 i, p1: integer;414 begin 415 for i:= 1 to 3 do416 if ad = AgePreq[ i] then413 I, p1: Integer; 414 begin 415 for I := 1 to 3 do 416 if ad = AgePreq[I] then 417 417 for p1 := 0 to nPl - 1 do 418 if (p1 <> p) and ((GAlive or GWatching) and (1 shl p1) <> 0) then419 RW[p1].EnemyReport[ p].Tech[ad] := Source;420 end; 421 422 var 423 i: integer;418 if (p1 <> P) and ((GAlive or GWatching) and (1 shl p1) <> 0) then 419 RW[p1].EnemyReport[P].Tech[ad] := Source; 420 end; 421 422 var 423 I: Integer; 424 424 begin 425 425 if ad in FutureTech then 426 426 begin 427 if RW[ p].Tech[ad] < tsApplicable then428 RW[ p].Tech[ad] := 1427 if RW[P].Tech[ad] < tsApplicable then 428 RW[P].Tech[ad] := 1 429 429 else 430 inc(RW[p].Tech[ad]);430 Inc(RW[P].Tech[ad]); 431 431 if ad <> futResearchTechnology then 432 inc(nTech[p], 2);433 inc(Researched[p], 8);434 exit;435 end; 436 437 if RW[ p].Tech[ad] = tsSeen then438 begin 439 inc(nTech[p]);440 inc(Researched[p]);432 Inc(nTech[P], 2); 433 Inc(Researched[P], 8); 434 Exit; 435 end; 436 437 if RW[P].Tech[ad] = tsSeen then 438 begin 439 Inc(nTech[P]); 440 Inc(Researched[P]); 441 441 end 442 442 else 443 443 begin 444 inc(nTech[p], 2);445 inc(Researched[p], 2);446 end; 447 RW[ p].Tech[ad] := tsResearched;448 TellAboutKeyTech( p, tsResearched);449 CheckSpecialModels( p, ad);444 Inc(nTech[P], 2); 445 Inc(Researched[P], 2); 446 end; 447 RW[P].Tech[ad] := tsResearched; 448 TellAboutKeyTech(P, tsResearched); 449 CheckSpecialModels(P, ad); 450 450 if ad = adScience then 451 ResourceMask[ p] := ResourceMask[p] or fSpecial2;451 ResourceMask[P] := ResourceMask[P] or fSpecial2; 452 452 if ad = adMassProduction then 453 ResourceMask[ p] := ResourceMask[p] or fModern;454 455 for i:= 0 to nWonder - 1 do { check whether wonders expired }456 if (GWonder[ i].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and457 (Imp[ i].Expiration = ad) then458 begin 459 GWonder[ i].EffectiveOwner := -1;460 if i= woPyramids then453 ResourceMask[P] := ResourceMask[P] or fModern; 454 455 for I := 0 to nWonder - 1 do { check whether wonders expired } 456 if (GWonder[I].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and 457 (Imp[I].Expiration = ad) then 458 begin 459 GWonder[I].EffectiveOwner := -1; 460 if I = woPyramids then 461 461 FreeSlaves; 462 462 end; 463 463 end; 464 464 465 procedure CheckExpiration(Wonder: integer);465 procedure CheckExpiration(Wonder: Integer); 466 466 // GWonder[Wonder].EffectiveOwner must be set before! 467 467 var 468 p: integer;468 P: Integer; 469 469 begin 470 470 if (Imp[Wonder].Expiration >= 0) and 471 471 (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) then 472 for p:= 0 to nPl - 1 do // check if already expired473 if (1 shl pand GAlive <> 0) and474 (RW[ p].Tech[Imp[Wonder].Expiration] >= tsApplicable) then472 for P := 0 to nPl - 1 do // check if already expired 473 if (1 shl P and GAlive <> 0) and 474 (RW[P].Tech[Imp[Wonder].Expiration] >= tsApplicable) then 475 475 begin 476 476 GWonder[Wonder].EffectiveOwner := -1; … … 484 484 ____________________________________________________________________ 485 485 } 486 function dLoc(Loc, dx, dy: integer): integer;486 function dLoc(Loc, dx, dy: Integer): Integer; 487 487 { relative location, dx in hor and dy in ver direction from Loc } 488 488 var 489 y0: integer;489 y0: Integer; 490 490 begin 491 491 if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then 492 492 raise Exception.Create('Relative location error'); 493 assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));493 Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0)); 494 494 y0 := Loc div lx; 495 result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);496 if ( result < 0) or (result >= MapSize) then497 result := -1;498 end; 499 500 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);495 Result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy); 496 if (Result < 0) or (Result >= MapSize) then 497 Result := -1; 498 end; 499 500 procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer); 501 501 begin 502 502 dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) - … … 505 505 end; 506 506 507 function Distance(Loc0, Loc1: integer): integer;508 var 509 dx, dy: integer;507 function Distance(Loc0, Loc1: Integer): Integer; 508 var 509 dx, dy: Integer; 510 510 begin 511 511 dxdy(Loc0, Loc1, dx, dy); 512 512 dx := abs(dx); 513 513 dy := abs(dy); 514 result := dx + dy + abs(dx - dy) shr 1;515 end; 516 517 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);518 var 519 x0, y0, lx0: integer;514 Result := dx + dy + abs(dx - dy) shr 1; 515 end; 516 517 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 518 var 519 x0, y0, lx0: Integer; 520 520 begin 521 521 lx0 := lx; // put in register! … … 527 527 VicinityLoc[5] := Loc0 - lx0 * 2; 528 528 VicinityLoc[7] := Loc0 + 1; 529 inc(Loc0, y0);529 Inc(Loc0, y0); 530 530 VicinityLoc[0] := Loc0 + lx0; 531 531 VicinityLoc[2] := Loc0 + lx0 - 1; … … 538 538 if x0 = 0 then 539 539 begin 540 inc(VicinityLoc[3], lx0);540 Inc(VicinityLoc[3], lx0); 541 541 if y0 = 0 then 542 542 begin 543 inc(VicinityLoc[2], lx0);544 inc(VicinityLoc[4], lx0);543 Inc(VicinityLoc[2], lx0); 544 Inc(VicinityLoc[4], lx0); 545 545 end; 546 546 end; … … 548 548 else 549 549 begin 550 dec(VicinityLoc[7], lx0);550 Dec(VicinityLoc[7], lx0); 551 551 if y0 = 1 then 552 552 begin 553 dec(VicinityLoc[0], lx0);554 dec(VicinityLoc[6], lx0);555 end; 556 end; 557 end; 558 559 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);560 var 561 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;562 dst: ^ integer;553 Dec(VicinityLoc[0], lx0); 554 Dec(VicinityLoc[6], lx0); 555 end; 556 end; 557 end; 558 559 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 560 var 561 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer; 562 dst: ^Integer; 563 563 begin 564 564 y0 := Loc0 div lx; … … 566 566 xCompSwitch := xComp0 - 1 + y0 and 1; 567 567 if xComp0 < 0 then 568 inc(xComp0, lx);568 Inc(xComp0, lx); 569 569 if xCompSwitch < 0 then 570 inc(xCompSwitch, lx);570 Inc(xCompSwitch, lx); 571 571 xCompSwitch := xCompSwitch xor xComp0; 572 572 yComp := lx * (y0 - 3); … … 583 583 else 584 584 dst^ := -1; 585 inc(xComp);585 Inc(xComp); 586 586 if xComp >= lx then 587 dec(xComp, lx);588 inc(dst);587 Dec(xComp, lx); 588 Inc(dst); 589 589 bit := bit shl 1; 590 590 end; 591 inc(yComp, lx);591 Inc(yComp, lx); 592 592 end; 593 593 end; … … 598 598 } 599 599 var 600 primitive: integer;601 StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }600 primitive: Integer; 601 StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates } 602 602 Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation } 603 ElCount: array [Byte] of integer; { count of elevation occurance }603 ElCount: array [Byte] of Integer; { count of elevation occurance } 604 604 605 605 procedure CalculatePrimitive; 606 606 var 607 i, j: integer;607 I, J: Integer; 608 608 begin 609 609 primitive := 1; 610 i:= 2;611 while i * i<= MapSize + 1 do // test whether prime612 begin 613 if (MapSize + 1) mod i= 0 then610 I := 2; 611 while I * I <= MapSize + 1 do // test whether prime 612 begin 613 if (MapSize + 1) mod I = 0 then 614 614 primitive := 0; 615 inc(i);615 Inc(I); 616 616 end; 617 617 618 618 if primitive > 0 then 619 619 repeat 620 inc(primitive);621 i:= 1;622 j:= 0;620 Inc(primitive); 621 I := 1; 622 J := 0; 623 623 repeat 624 inc(j);625 i := i* primitive mod (MapSize + 1);626 until ( i = 1) or (j= MapSize + 1);627 until j= MapSize;628 end; 629 630 function MapGeneratorAvailable: boolean;631 begin 632 result := (primitive > 0) and (lx >= 20) and (ly >= 40);624 Inc(J); 625 I := I * primitive mod (MapSize + 1); 626 until (I = 1) or (J = MapSize + 1); 627 until J = MapSize; 628 end; 629 630 function MapGeneratorAvailable: Boolean; 631 begin 632 Result := (primitive > 0) and (lx >= 20) and (ly >= 40); 633 633 end; 634 634 635 635 procedure CreateElevation; 636 636 const 637 d= 64;637 D = 64; 638 638 Smooth = 0.049; { causes low amplitude of short waves } 639 639 Detail = 0.095; { causes short period of short waves } … … 642 642 643 643 var 644 sa, ca, f1, f2: array [1 .. d] of single;645 imerge, x, y: integer;646 v, maxv: single;647 648 function Value( x, y: integer): single; { elevation formula }644 sa, ca, f1, f2: array [1 .. D] of Single; 645 imerge, X, Y: Integer; 646 V, maxv: Single; 647 648 function Value(X, Y: Integer): Single; { elevation formula } 649 649 var 650 i: integer;651 begin 652 result := 0;653 for i := 1 to ddo654 result := result + sin(f1[i] * ((x * 2 + y and 1) * sa[i] + y* 1.5 *655 ca[ i])) * f2[i];650 I: Integer; 651 begin 652 Result := 0; 653 for I := 1 to D do 654 Result := Result + sin(f1[I] * ((X * 2 + Y and 1) * sa[I] + Y * 1.5 * 655 ca[I])) * f2[I]; 656 656 { x values effectively multiplied with 2 to get 2 horizantal periods 657 657 of the prime waves } … … 659 659 660 660 begin 661 for x := 1 to ddo { prepare formula parameters }662 begin 663 {$IFNDEF SCR} if x= 1 then664 v:= pi / 2 { first wave goes horizontal }665 else {$ENDIF} v:= DelphiRandom * 2 * pi;666 sa[ x] := sin(v) / lx;667 ca[ x] := cos(v) / ly;668 f1[ x] := 2 * pi * exp(Detail * (x- 1));669 f2[ x] := exp(-x* Smooth);661 for X := 1 to D do { prepare formula parameters } 662 begin 663 {$IFNDEF SCR} if X = 1 then 664 V := pi / 2 { first wave goes horizontal } 665 else {$ENDIF} V := DelphiRandom * 2 * pi; 666 sa[X] := sin(V) / lx; 667 ca[X] := cos(V) / ly; 668 f1[X] := 2 * pi * exp(Detail * (X - 1)); 669 f2[X] := exp(-X * Smooth); 670 670 end; 671 671 … … 673 673 FillChar(ElCount, SizeOf(ElCount), 0); 674 674 maxv := 0; 675 for x:= 0 to lx - 1 do676 for y:= 0 to ly - 1 do677 begin 678 v := Value(x, y);679 if x* 2 < imerge then680 v := (x * 2 * v + (imerge - x * 2) * Value(x + lx, y)) / imerge;681 v := v - sqr(sqr(2 * y/ ly - 1)); { soft cut at poles }682 if v> maxv then683 maxv := v;684 685 if v< -4 then686 Elevation[ x + lx * y] := 0687 else if v> 8.75 then688 Elevation[ x + lx * y] := 255675 for X := 0 to lx - 1 do 676 for Y := 0 to ly - 1 do 677 begin 678 V := Value(X, Y); 679 if X * 2 < imerge then 680 V := (X * 2 * V + (imerge - X * 2) * Value(X + lx, Y)) / imerge; 681 V := V - sqr(sqr(2 * Y / ly - 1)); { soft cut at poles } 682 if V > maxv then 683 maxv := V; 684 685 if V < -4 then 686 Elevation[X + lx * Y] := 0 687 else if V > 8.75 then 688 Elevation[X + lx * Y] := 255 689 689 else 690 Elevation[ x + lx * y] := Round((v+ 4) * 20);691 inc(ElCount[Elevation[x + lx * y]]);690 Elevation[X + lx * Y] := Round((V + 4) * 20); 691 Inc(ElCount[Elevation[X + lx * Y]]); 692 692 end; 693 693 end; … … 695 695 procedure FindContinents; 696 696 697 procedure ReplaceCont( a, b, Stop: integer);697 procedure ReplaceCont(A, B, Stop: Integer); 698 698 { replace continent name a by b } 699 699 // make sure always continent[loc]<=loc 700 700 var 701 i: integer;702 begin 703 if a < bthen704 begin 705 i := a;706 a := b;707 b := i708 end; 709 if a > bthen710 for i := ato Stop do711 if Continent[ i] = athen712 Continent[ i] := b;713 end; 714 715 var 716 x, y, Loc, Wrong: integer;717 begin 718 for y:= 1 to ly - 2 do719 for x:= 0 to lx - 1 do720 begin 721 Loc := x + lx * y;701 I: Integer; 702 begin 703 if A < B then 704 begin 705 I := A; 706 A := B; 707 B := I 708 end; 709 if A > B then 710 for I := A to Stop do 711 if Continent[I] = A then 712 Continent[I] := B; 713 end; 714 715 var 716 X, Y, Loc, Wrong: Integer; 717 begin 718 for Y := 1 to ly - 2 do 719 for X := 0 to lx - 1 do 720 begin 721 Loc := X + lx * Y; 722 722 Continent[Loc] := -1; 723 723 if RealMap[Loc] and fTerrain >= fGrass then 724 724 begin 725 if ( y- 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then725 if (Y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then 726 726 Continent[Loc] := Continent[Loc - 2 * lx]; 727 if ( x - 1 + y and 1 >= 0) and (y- 1 >= 1) and728 (RealMap[Loc - 1 + yand 1 - lx] and fTerrain >= fGrass) then729 Continent[Loc] := Continent[Loc - 1 + yand 1 - lx];730 if ( x + y and 1 < lx) and (y- 1 >= 1) and731 (RealMap[Loc + yand 1 - lx] and fTerrain >= fGrass) then732 Continent[Loc] := Continent[Loc + yand 1 - lx];733 if ( x- 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then727 if (X - 1 + Y and 1 >= 0) and (Y - 1 >= 1) and 728 (RealMap[Loc - 1 + Y and 1 - lx] and fTerrain >= fGrass) then 729 Continent[Loc] := Continent[Loc - 1 + Y and 1 - lx]; 730 if (X + Y and 1 < lx) and (Y - 1 >= 1) and 731 (RealMap[Loc + Y and 1 - lx] and fTerrain >= fGrass) then 732 Continent[Loc] := Continent[Loc + Y and 1 - lx]; 733 if (X - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then 734 734 if Continent[Loc] = -1 then 735 735 Continent[Loc] := Continent[Loc - 1] … … 742 742 743 743 { connect continents due to round earth } 744 for y:= 1 to ly - 2 do745 if RealMap[lx * y] and fTerrain >= fGrass then744 for Y := 1 to ly - 2 do 745 if RealMap[lx * Y] and fTerrain >= fGrass then 746 746 begin 747 747 Wrong := -1; 748 if RealMap[lx - 1 + lx * y] and fTerrain >= fGrass then749 Wrong := Continent[lx - 1 + lx * y];750 if ( y and 1 = 0) and (y- 1 >= 1) and751 (RealMap[lx - 1 + lx * ( y- 1)] and fTerrain >= fGrass) then752 Wrong := Continent[lx - 1 + lx * ( y- 1)];753 if ( y and 1 = 0) and (y+ 1 < ly - 1) and754 (RealMap[lx - 1 + lx * ( y+ 1)] and fTerrain >= fGrass) then755 Wrong := Continent[lx - 1 + lx * ( y+ 1)];748 if RealMap[lx - 1 + lx * Y] and fTerrain >= fGrass then 749 Wrong := Continent[lx - 1 + lx * Y]; 750 if (Y and 1 = 0) and (Y - 1 >= 1) and 751 (RealMap[lx - 1 + lx * (Y - 1)] and fTerrain >= fGrass) then 752 Wrong := Continent[lx - 1 + lx * (Y - 1)]; 753 if (Y and 1 = 0) and (Y + 1 < ly - 1) and 754 (RealMap[lx - 1 + lx * (Y + 1)] and fTerrain >= fGrass) then 755 Wrong := Continent[lx - 1 + lx * (Y + 1)]; 756 756 if Wrong >= 0 then 757 ReplaceCont(Wrong, Continent[lx * y], MapSize - 1);757 ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1); 758 758 end; 759 759 end; … … 763 763 // must be done after FindContinents 764 764 var 765 i, j, Cnt, x, y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,766 RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: integer;767 AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of integer;768 RareLoc: array [0 .. 11] of integer;769 Dist: array [0 .. 11, 0 .. 11] of integer;765 I, J, Cnt, X, Y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater, 766 RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: Integer; 767 AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of Integer; 768 RareLoc: array [0 .. 11] of Integer; 769 Dist: array [0 .. 11, 0 .. 11] of Integer; 770 770 Adjacent: TVicinity8Loc; 771 771 begin … … 773 773 repeat 774 774 FillChar(AreaCount, SizeOf(AreaCount), 0); 775 for y:= 1 to ly - 2 do776 begin 777 yBlock := y* 5 div ly;778 if yBlock = ( y+ 1) * 5 div ly then779 for x:= 0 to lx - 1 do780 begin 781 xBlock := x* 8 div lx;782 if xBlock = ( x+ 1) * 8 div lx then775 for Y := 1 to ly - 2 do 776 begin 777 yBlock := Y * 5 div ly; 778 if yBlock = (Y + 1) * 5 div ly then 779 for X := 0 to lx - 1 do 780 begin 781 xBlock := X * 8 div lx; 782 if xBlock = (X + 1) * 8 div lx then 783 783 begin 784 Loc0 := x + lx * y;784 Loc0 := X + lx * Y; 785 785 if RealMap[Loc0] and fTerrain >= fGrass then 786 786 begin … … 792 792 if (Loc1 >= 0) and (Loc1 < MapSize) and 793 793 (RealMap[Loc1] and fTerrain < fGrass) then 794 inc(Cnt); // count adjacent water794 Inc(Cnt); // count adjacent water 795 795 end; 796 796 if Cnt <= RareMaxWater then // inner land 797 797 begin 798 inc(AreaCount[xBlock, yBlock]);798 Inc(AreaCount[xBlock, yBlock]); 799 799 if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then 800 800 RareByArea[xBlock, yBlock] := Loc0; … … 805 805 end; 806 806 totalrare := 0; 807 for x:= 0 to 7 do808 for y:= 0 to 4 do809 if AreaCount[ x, y] > 0 then810 inc(totalrare);811 inc(RareMaxWater);807 for X := 0 to 7 do 808 for Y := 0 to 4 do 809 if AreaCount[X, Y] > 0 then 810 Inc(totalrare); 811 Inc(RareMaxWater); 812 812 until totalrare >= 12; 813 813 … … 815 815 begin // remove rarebyarea resources too close to each other 816 816 FillChar(RareAdjacent, SizeOf(RareAdjacent), 0); 817 for x:= 0 to 7 do818 for y:= 0 to 4 do819 if AreaCount[ x, y] > 0 then820 begin 821 if (AreaCount[( x + 1) mod 8, y] > 0) and822 (Continent[RareByArea[ x, y]] = Continent823 [RareByArea[( x + 1) mod 8, y]]) then817 for X := 0 to 7 do 818 for Y := 0 to 4 do 819 if AreaCount[X, Y] > 0 then 820 begin 821 if (AreaCount[(X + 1) mod 8, Y] > 0) and 822 (Continent[RareByArea[X, Y]] = Continent 823 [RareByArea[(X + 1) mod 8, Y]]) then 824 824 begin 825 inc(RareAdjacent[x, y]);826 inc(RareAdjacent[(x + 1) mod 8, y]);825 Inc(RareAdjacent[X, Y]); 826 Inc(RareAdjacent[(X + 1) mod 8, Y]); 827 827 end; 828 if y< 4 then828 if Y < 4 then 829 829 begin 830 if (AreaCount[ x, y+ 1] > 0) and831 (Continent[RareByArea[ x, y]] = Continent[RareByArea[x, y+ 1]])830 if (AreaCount[X, Y + 1] > 0) and 831 (Continent[RareByArea[X, Y]] = Continent[RareByArea[X, Y + 1]]) 832 832 then 833 833 begin 834 inc(RareAdjacent[x, y]);835 inc(RareAdjacent[x, y+ 1]);834 Inc(RareAdjacent[X, Y]); 835 Inc(RareAdjacent[X, Y + 1]); 836 836 end; 837 if (AreaCount[( x + 1) mod 8, y+ 1] > 0) and838 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 1) mod 8,839 y+ 1]]) then837 if (AreaCount[(X + 1) mod 8, Y + 1] > 0) and 838 (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 1) mod 8, 839 Y + 1]]) then 840 840 begin 841 inc(RareAdjacent[x, y]);842 inc(RareAdjacent[(x + 1) mod 8, y+ 1]);841 Inc(RareAdjacent[X, Y]); 842 Inc(RareAdjacent[(X + 1) mod 8, Y + 1]); 843 843 end; 844 if (AreaCount[( x + 7) mod 8, y+ 1] > 0) and845 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 7) mod 8,846 y+ 1]]) then844 if (AreaCount[(X + 7) mod 8, Y + 1] > 0) and 845 (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 7) mod 8, 846 Y + 1]]) then 847 847 begin 848 inc(RareAdjacent[x, y]);849 inc(RareAdjacent[(x + 7) mod 8, y+ 1]);848 Inc(RareAdjacent[X, Y]); 849 Inc(RareAdjacent[(X + 7) mod 8, Y + 1]); 850 850 end; 851 851 end; … … 854 854 yworst := 0; 855 855 Cnt := 0; 856 for x:= 0 to 7 do857 for y:= 0 to 4 do858 if AreaCount[ x, y] > 0 then859 begin 860 if (Cnt = 0) or (RareAdjacent[ x, y] > RareAdjacent[xworst, yworst])856 for X := 0 to 7 do 857 for Y := 0 to 4 do 858 if AreaCount[X, Y] > 0 then 859 begin 860 if (Cnt = 0) or (RareAdjacent[X, Y] > RareAdjacent[xworst, yworst]) 861 861 then 862 862 begin 863 xworst := x;864 yworst := y;863 xworst := X; 864 yworst := Y; 865 865 Cnt := 1; 866 866 end 867 else if (RareAdjacent[ x, y] = RareAdjacent[xworst, yworst]) then867 else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then 868 868 begin 869 inc(Cnt);869 Inc(Cnt); 870 870 if DelphiRandom(Cnt) = 0 then 871 871 begin 872 xworst := x;873 yworst := y;872 xworst := X; 873 yworst := Y; 874 874 end; 875 875 end; 876 876 end; 877 877 AreaCount[xworst, yworst] := 0; 878 dec(totalrare);878 Dec(totalrare); 879 879 end; 880 880 881 881 Cnt := 0; 882 for x:= 0 to 7 do883 for y:= 0 to 4 do884 if AreaCount[ x, y] > 0 then885 begin 886 RareLoc[Cnt] := RareByArea[ x, y];887 inc(Cnt);888 end; 889 for i:= 0 to 11 do890 begin 891 RealMap[RareLoc[ i]] := RealMap[RareLoc[i]] and not(fTerrain or fSpecial) or882 for X := 0 to 7 do 883 for Y := 0 to 4 do 884 if AreaCount[X, Y] > 0 then 885 begin 886 RareLoc[Cnt] := RareByArea[X, Y]; 887 Inc(Cnt); 888 end; 889 for I := 0 to 11 do 890 begin 891 RealMap[RareLoc[I]] := RealMap[RareLoc[I]] and not(fTerrain or fSpecial) or 892 892 (fDesert or fDeadLands); 893 893 for dy := -1 to 1 do … … 895 895 if (dx + dy) and 1 = 0 then 896 896 begin 897 Loc1 := dLoc(RareLoc[ i], dx, dy);897 Loc1 := dLoc(RareLoc[I], dx, dy); 898 898 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then 899 899 RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills; 900 900 end; 901 901 end; 902 for i:= 0 to 11 do903 for j:= 0 to 11 do904 Dist[ i, j] := Distance(RareLoc[i], RareLoc[j]);902 for I := 0 to 11 do 903 for J := 0 to 11 do 904 Dist[I, J] := Distance(RareLoc[I], RareLoc[J]); 905 905 906 906 ibest := 0; … … 910 910 begin 911 911 Cnt := 0; 912 for i:= 0 to 11 do913 if RareLoc[ i] >= 0 then914 for j:= 0 to 11 do915 if RareLoc[ j] >= 0 then912 for I := 0 to 11 do 913 if RareLoc[I] >= 0 then 914 for J := 0 to 11 do 915 if RareLoc[J] >= 0 then 916 916 if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then 917 917 begin 918 if Dist[ i, j] >= MinDist then918 if Dist[I, J] >= MinDist then 919 919 begin 920 inc(Cnt);920 Inc(Cnt); 921 921 if DelphiRandom(Cnt) = 0 then 922 922 begin 923 iBest := i;924 jbest := j;923 iBest := I; 924 jbest := J; 925 925 end; 926 926 end; 927 927 end 928 else if (Cnt = 0) or (Dist[ i, j] > Dist[iBest, jbest]) then928 else if (Cnt = 0) or (Dist[I, J] > Dist[iBest, jbest]) then 929 929 begin 930 iBest := i;931 jbest := j;930 iBest := I; 931 jbest := J; 932 932 Cnt := 1; 933 933 end; … … 941 941 end; 942 942 943 function CheckShore(Loc: integer): boolean;944 var 945 Loc1, OldTile, V21: integer;943 function CheckShore(Loc: Integer): Boolean; 944 var 945 Loc1, OldTile, V21: Integer; 946 946 Radius: TVicinity21Loc; 947 947 begin 948 result := false;948 Result := False; 949 949 OldTile := RealMap[Loc]; 950 950 if OldTile and fTerrain < fGrass then … … 961 961 end; 962 962 if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then 963 result := true;964 end; 965 end; 966 967 function ActualSpecialTile(Loc: integer): Cardinal;968 begin 969 result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);970 end; 971 972 procedure CreateMap(preview: boolean);963 Result := True; 964 end; 965 end; 966 967 function ActualSpecialTile(Loc: Integer): Cardinal; 968 begin 969 Result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx); 970 end; 971 972 procedure CreateMap(preview: Boolean); 973 973 const 974 974 ShHiHills = 6; { of land } … … 981 981 hotunification = 50; // min. 25 982 982 983 Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }983 Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution } 984 984 ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35), 985 985 (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3)); 986 986 { Grs Dst Pra Tun - - - For } 987 987 988 function RndLow( y: integer): Cardinal;988 function RndLow(Y: Integer): Cardinal; 989 989 { random lowland appropriate to climate } 990 990 var 991 z0, i: integer;992 p, p0, ZPlus: single;993 begin 994 if ly - 1 - y > ythen995 begin 996 z0 := 6 * ydiv ly;997 ZPlus := 6 * y/ ly - z0;991 z0, I: Integer; 992 P, p0, ZPlus: Single; 993 begin 994 if ly - 1 - Y > Y then 995 begin 996 z0 := 6 * Y div ly; 997 ZPlus := 6 * Y / ly - z0; 998 998 end 999 999 else 1000 1000 begin 1001 z0 := 6 * (ly - 1 - y) div ly;1002 ZPlus := 6 * (ly - 1 - y) / ly - z0;1001 z0 := 6 * (ly - 1 - Y) div ly; 1002 ZPlus := 6 * (ly - 1 - Y) / ly - z0; 1003 1003 end; 1004 1004 p0 := 1; 1005 for i:= 2 to 9 do1006 begin 1007 p := Zone[z0, i] * (1 - ZPlus) + Zone[z0 + 1, i] * ZPlus;1005 for I := 2 to 9 do 1006 begin 1007 P := Zone[z0, I] * (1 - ZPlus) + Zone[z0 + 1, I] * ZPlus; 1008 1008 { weight between zones z0 and z0+1 } 1009 if DelphiRandom * p0 < pthen1010 begin 1011 RndLow := i;1009 if DelphiRandom * p0 < P then 1010 begin 1011 RndLow := I; 1012 1012 Break; 1013 1013 end; 1014 p0 := p0 - p;1015 end; 1016 end; 1017 1018 function RunRiver(Loc0: integer): integer;1014 p0 := p0 - P; 1015 end; 1016 end; 1017 1018 function RunRiver(Loc0: Integer): Integer; 1019 1019 { runs river from start point Loc0; return value: length } 1020 1020 var 1021 Dir, T, Loc, Loc1, Cost: integer;1021 Dir, T, Loc, Loc1, Cost: Integer; 1022 1022 Q: TIPQ; 1023 From: array [0 .. lxmax * lymax - 1] of integer;1024 Time: array [0 .. lxmax * lymax - 1] of integer;1025 OneTileLake: boolean;1023 From: array [0 .. lxmax * lymax - 1] of Integer; 1024 Time: array [0 .. lxmax * lymax - 1] of Integer; 1025 OneTileLake: Boolean; 1026 1026 begin 1027 1027 FillChar(Time, SizeOf(Time), 255); { -1 } … … 1032 1032 if (RealMap[Loc] and fTerrain < fGrass) then 1033 1033 begin 1034 OneTileLake := true;1034 OneTileLake := True; 1035 1035 for Dir := 0 to 3 do 1036 1036 begin 1037 1037 Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1); 1038 1038 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then 1039 OneTileLake := false;1039 OneTileLake := False; 1040 1040 end; 1041 1041 if not OneTileLake then … … 1062 1062 end; 1063 1063 Loc1 := Loc; 1064 result := 0;1064 Result := 0; 1065 1065 while Loc <> Loc0 do 1066 1066 begin 1067 1067 Loc := From[Loc]; 1068 inc(result);1069 end; 1070 if ( result > 1) and ((result >= MinRivLen) or1068 Inc(Result); 1069 end; 1070 if (Result > 1) and ((Result >= MinRivLen) or 1071 1071 (RealMap[Loc1] and fTerrain >= fGrass)) then 1072 1072 begin … … 1082 1082 end 1083 1083 else 1084 result := 0;1084 Result := 0; 1085 1085 FreeAndNil(Q); 1086 1086 end; 1087 1087 1088 1088 var 1089 x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;1090 CopyFrom: array [0 .. lxmax * lymax - 1] of integer;1089 X, Y, N, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: Integer; 1090 CopyFrom: array [0 .. lxmax * lymax - 1] of Integer; 1091 1091 Adjacent: TVicinity8Loc; 1092 1092 … … 1097 1097 while plus < MapSize * LandMass * ShMountains div 10000 do 1098 1098 begin 1099 dec(bMountains);1100 inc(plus, ElCount[bMountains]);1099 Dec(bMountains); 1100 Inc(plus, ElCount[bMountains]); 1101 1101 end; 1102 1102 Count := plus; … … 1105 1105 while plus < MapSize * LandMass * ShHiHills div 10000 do 1106 1106 begin 1107 dec(bHills);1108 inc(plus, ElCount[bHills]);1109 end; 1110 inc(Count, plus);1107 Dec(bHills); 1108 Inc(plus, ElCount[bHills]); 1109 end; 1110 Inc(Count, plus); 1111 1111 bLand := bHills; 1112 1112 while Count < MapSize * LandMass div 100 do 1113 1113 begin 1114 dec(bLand);1115 inc(Count, ElCount[bLand]);1114 Dec(bLand); 1115 Inc(Count, ElCount[bLand]); 1116 1116 end; 1117 1117 … … 1136 1136 (RealMap[Loc1] and fTerrain < fGrass) or 1137 1137 (RealMap[Loc1] and fTerrain = fArctic) then 1138 inc(Count); // count adjacent water1138 Inc(Count); // count adjacent water 1139 1139 end; 1140 1140 if Count = 8 then … … 1148 1148 plus := MapSize; 1149 1149 Loc0 := DelphiRandom(MapSize); 1150 for n:= 0 to plus - 1 do1150 for N := 0 to plus - 1 do 1151 1151 begin 1152 1152 if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and … … 1165 1165 CopyFrom[Loc0] := Loc0; 1166 1166 1167 for n:= 0 to unification * MapSize div 100 do1168 begin 1169 y:= DelphiRandom(ly);1170 if abs( y- (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then1171 if y< ly shr 1 then1172 y := ly shr 1 - y1167 for N := 0 to unification * MapSize div 100 do 1168 begin 1169 Y := DelphiRandom(ly); 1170 if abs(Y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then 1171 if Y < ly shr 1 then 1172 Y := ly shr 1 - Y 1173 1173 else 1174 y := 3 * ly shr 1 - y;1175 Loc0 := lx * y+ DelphiRandom(lx);1174 Y := 3 * ly shr 1 - Y; 1175 Loc0 := lx * Y + DelphiRandom(lx); 1176 1176 if RealMap[Loc0] and fTerrain = fGrass then 1177 1177 begin … … 1226 1226 if Loc1 >= 0 then 1227 1227 if RealMap[Loc1] and fTerrain < fGrass then 1228 inc(Count, 2);1228 Inc(Count, 2); 1229 1229 end; 1230 1230 end; … … 1242 1242 if Loc1 >= 0 then 1243 1243 if RealMap[Loc1] and fTerrain <> fDesert then 1244 inc(Count);1244 Inc(Count); 1245 1245 end; 1246 1246 if Count >= 4 then … … 1250 1250 for Loc0 := 0 to MapSize - 1 do 1251 1251 CheckShore(Loc0); // change ocean to shore 1252 for x:= 0 to lx - 1 do1253 begin 1254 RealMap[ x+ lx * 0] := fArctic;1255 if RealMap[ x+ lx * 1] >= fGrass then1256 RealMap[ x + lx * 1] := RealMap[x+ lx * 1] and not fTerrain or fTundra;1257 if RealMap[ x+ lx * (ly - 2)] >= fGrass then1258 RealMap[ x + lx * (ly - 2)] := RealMap[x+ lx * (ly - 2)] and1252 for X := 0 to lx - 1 do 1253 begin 1254 RealMap[X + lx * 0] := fArctic; 1255 if RealMap[X + lx * 1] >= fGrass then 1256 RealMap[X + lx * 1] := RealMap[X + lx * 1] and not fTerrain or fTundra; 1257 if RealMap[X + lx * (ly - 2)] >= fGrass then 1258 RealMap[X + lx * (ly - 2)] := RealMap[X + lx * (ly - 2)] and 1259 1259 not fTerrain or fTundra; 1260 RealMap[ x+ lx * (ly - 1)] := fArctic;1260 RealMap[X + lx * (ly - 1)] := fArctic; 1261 1261 end; 1262 1262 … … 1279 1279 CountGood: (cgBest, cgFlat, cgLand); 1280 1280 1281 function IsGoodTile(Loc: integer): boolean;1281 function IsGoodTile(Loc: Integer): Boolean; 1282 1282 var 1283 xLoc, yLoc: integer;1283 xLoc, yLoc: Integer; 1284 1284 begin 1285 1285 xLoc := Loc mod lx; 1286 1286 yLoc := Loc div lx; 1287 1287 if RealMap[Loc] and fDeadLands <> 0 then 1288 result := false1288 Result := False 1289 1289 else 1290 1290 case CountGood of 1291 1291 cgBest: 1292 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1292 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1293 1293 fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc + 1294 1294 (yLoc + 1) shr 1); 1295 1295 cgFlat: 1296 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1296 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1297 1297 fSwamp, fForest]); 1298 1298 cgLand: 1299 result := RealMap[Loc] and fTerrain >= fGrass;1299 Result := RealMap[Loc] and fTerrain >= fGrass; 1300 1300 end; 1301 1301 end; … … 1305 1305 1306 1306 var 1307 p1, p2, nAlive, c, Loc, Loc1, CntGood, CntGoodGrass, MinDist, i, j, n,1307 p1, p2, nAlive, C, Loc, Loc1, CntGood, CntGoodGrass, MinDist, I, J, N, 1308 1308 nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc, 1309 FineDistSQR, nRest: integer;1310 ccount: array [0 .. lxmax * lymax - 1] of word;1311 sc, StartLoc0, sccount: array [1 .. nPl] of integer;1312 TestStartLoc: array [0 .. nPl - 1] of integer;1313 CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of integer;1314 nCityLoc: array [1 .. nPl] of integer;1315 RestLoc: array [0 .. MaxCityLoc - 1] of integer;1316 IrrLoc: array [0 .. 20] of integer;1309 FineDistSQR, nRest: Integer; 1310 ccount: array [0 .. lxmax * lymax - 1] of Word; 1311 sc, StartLoc0, sccount: array [1 .. nPl] of Integer; 1312 TestStartLoc: array [0 .. nPl - 1] of Integer; 1313 CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of Integer; 1314 nCityLoc: array [1 .. nPl] of Integer; 1315 RestLoc: array [0 .. MaxCityLoc - 1] of Integer; 1316 IrrLoc: array [0 .. 20] of Integer; 1317 1317 Radius: TVicinity21Loc; 1318 1318 Adjacent: TVicinity8Loc; 1319 ok: boolean;1319 ok: Boolean; 1320 1320 1321 1321 begin … … 1323 1323 for p1 := 0 to nPl - 1 do 1324 1324 if 1 shl p1 and GAlive <> 0 then 1325 inc(nAlive);1325 Inc(nAlive); 1326 1326 if nAlive = 0 then 1327 exit;1327 Exit; 1328 1328 1329 1329 { count good tiles } … … 1332 1332 if RealMap[Loc] and fTerrain = fGrass then 1333 1333 if ActualSpecialTile(Loc) = 1 then 1334 inc(ccount[Continent[Loc]], 3)1334 Inc(ccount[Continent[Loc]], 3) 1335 1335 else 1336 inc(ccount[Continent[Loc]], 2)1336 Inc(ccount[Continent[Loc]], 2) 1337 1337 else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills] 1338 1338 then 1339 inc(ccount[Continent[Loc]]);1339 Inc(ccount[Continent[Loc]]); 1340 1340 1341 1341 Loc := 0; 1342 1342 while ccount[Loc] > 0 do 1343 inc(Loc);1344 for i:= 1 to nAlive do1345 begin 1346 sc[ i] := Loc;1347 sccount[ i] := 11343 Inc(Loc); 1344 for I := 1 to nAlive do 1345 begin 1346 sc[I] := Loc; 1347 sccount[I] := 1 1348 1348 end; 1349 1349 { init with zero size start continents, then search bigger ones } … … 1356 1356 if p1 < nAlive + 1 then 1357 1357 sc[p1] := sc[p1 - 1]; 1358 dec(p1);1358 Dec(p1); 1359 1359 end; 1360 1360 if p1 < nAlive + 1 then … … 1363 1363 nsc := nAlive; 1364 1364 repeat 1365 c:= 1; // search least crowded continent after smallest1366 for i:= 2 to nsc - 1 do1367 if ccount[sc[ i]] * (2 * sccount[c] + 1) > ccount[sc[c]] *1368 (2 * sccount[ i] + 1) then1369 c := i;1370 if ccount[sc[nsc]] * (2 * sccount[ c] + 1) > ccount[sc[c]] then1365 C := 1; // search least crowded continent after smallest 1366 for I := 2 to nsc - 1 do 1367 if ccount[sc[I]] * (2 * sccount[C] + 1) > ccount[sc[C]] * 1368 (2 * sccount[I] + 1) then 1369 C := I; 1370 if ccount[sc[nsc]] * (2 * sccount[C] + 1) > ccount[sc[C]] then 1371 1371 Break; // even least crowded continent is more crowded than smallest 1372 inc(sccount[c]);1373 dec(nsc);1372 Inc(sccount[C]); 1373 Dec(nsc); 1374 1374 until sccount[nsc] > 1; 1375 1375 … … 1377 1377 CountGood := cgBest; 1378 1378 repeat 1379 dec(MinGood);1379 Dec(MinGood); 1380 1380 if (MinGood = 3) and (CountGood < cgLand) then // too demanding! 1381 1381 begin 1382 inc(CountGood);1382 Inc(CountGood); 1383 1383 MinGood := 6; 1384 1384 end; 1385 1385 FillChar(nCityLoc, SizeOf(nCityLoc), 0); 1386 1386 Loc := DelphiRandom(MapSize); 1387 for i:= 0 to MapSize - 1 do1387 for I := 0 to MapSize - 1 do 1388 1388 begin 1389 1389 if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand)) 1390 1390 and IsGoodTile(Loc) then 1391 1391 begin 1392 c:= nsc;1393 while ( c > 0) and (Continent[Loc] <> sc[c]) do1394 dec(c);1395 if ( c > 0) and (nCityLoc[c] < MaxCityLoc) then1392 C := nsc; 1393 while (C > 0) and (Continent[Loc] <> sc[C]) do 1394 Dec(C); 1395 if (C > 0) and (nCityLoc[C] < MaxCityLoc) then 1396 1396 begin 1397 1397 CntGood := 1; … … 1402 1402 Loc1 := Radius[V21]; 1403 1403 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1404 inc(CntGood);1404 Inc(CntGood); 1405 1405 end; 1406 1406 if CntGood >= MinGood then 1407 1407 begin 1408 CityLoc[ c, nCityLoc[c]] := Loc;1409 inc(nCityLoc[c]);1408 CityLoc[C, nCityLoc[C]] := Loc; 1409 Inc(nCityLoc[C]); 1410 1410 end; 1411 1411 end; … … 1414 1414 end; 1415 1415 1416 ok := true;1417 for c:= 1 to nsc do1418 if nCityLoc[ c] < sccount[c] * (8 - MinGood) div (7 - MinGood) then1419 ok := false;1416 ok := True; 1417 for C := 1 to nsc do 1418 if nCityLoc[C] < sccount[C] * (8 - MinGood) div (7 - MinGood) then 1419 ok := False; 1420 1420 until ok; 1421 1421 1422 1422 FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100); 1423 1423 p1 := 1; 1424 for c:= 1 to nsc do1424 for C := 1 to nsc do 1425 1425 begin // for all start continents 1426 if sccount[ c] = 1 then1427 StartLoc0[p1] := CityLoc[ c, DelphiRandom(nCityLoc[c])]1426 if sccount[C] = 1 then 1427 StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])] 1428 1428 else 1429 1429 begin 1430 1430 BestDist := 0; 1431 n := 1 shl sccount[c] * 32; // number of tries to find good distribution1432 if n> 1 shl 12 then1433 n:= 1 shl 12;1434 while ( n> 0) and (BestDist * BestDist < FineDistSQR) do1431 N := 1 shl sccount[C] * 32; // number of tries to find good distribution 1432 if N > 1 shl 12 then 1433 N := 1 shl 12; 1434 while (N > 0) and (BestDist * BestDist < FineDistSQR) do 1435 1435 begin 1436 1436 MinDist := MaxInt; 1437 nRest := nCityLoc[ c];1438 for i:= 0 to nRest - 1 do1439 RestLoc[ i] := CityLoc[c, i];1440 for i := 0 to sccount[c] - 1 do1437 nRest := nCityLoc[C]; 1438 for I := 0 to nRest - 1 do 1439 RestLoc[I] := CityLoc[C, I]; 1440 for I := 0 to sccount[C] - 1 do 1441 1441 begin 1442 1442 if nRest = 0 then 1443 1443 Break; 1444 j:= DelphiRandom(nRest);1445 TestStartLoc[ i] := RestLoc[j];1446 RestLoc[ j] := RestLoc[nRest - 1];1447 dec(nRest);1448 for j := 0 to i- 1 do1444 J := DelphiRandom(nRest); 1445 TestStartLoc[I] := RestLoc[J]; 1446 RestLoc[J] := RestLoc[nRest - 1]; 1447 Dec(nRest); 1448 for J := 0 to I - 1 do 1449 1449 begin 1450 TestDist := Distance(TestStartLoc[ i], TestStartLoc[j]);1450 TestDist := Distance(TestStartLoc[I], TestStartLoc[J]); 1451 1451 if TestDist < MinDist then 1452 1452 MinDist := TestDist; 1453 1453 end; 1454 if i = sccount[c] - 1 then1454 if I = sccount[C] - 1 then 1455 1455 begin 1456 assert(MinDist > BestDist);1456 Assert(MinDist > BestDist); 1457 1457 BestDist := MinDist; 1458 for j := 0 to sccount[c] - 1 do1459 StartLoc0[p1 + j] := TestStartLoc[j];1458 for J := 0 to sccount[C] - 1 do 1459 StartLoc0[p1 + J] := TestStartLoc[J]; 1460 1460 end 1461 1461 else if BestDist > 0 then 1462 1462 begin 1463 j:= 0;1464 while j< nRest do1463 J := 0; 1464 while J < nRest do 1465 1465 begin // remove all locs from rest which have too little distance to this one 1466 TestDist := Distance(TestStartLoc[ i], RestLoc[j]);1466 TestDist := Distance(TestStartLoc[I], RestLoc[J]); 1467 1467 if TestDist <= BestDist then 1468 1468 begin 1469 RestLoc[ j] := RestLoc[nRest - 1];1470 dec(nRest);1469 RestLoc[J] := RestLoc[nRest - 1]; 1470 Dec(nRest); 1471 1471 end 1472 1472 else 1473 inc(j);1473 Inc(J); 1474 1474 end; 1475 1475 end; 1476 1476 end; 1477 dec(n)1478 end; 1479 end; 1480 p1 := p1 + sccount[ c]1477 Dec(N) 1478 end; 1479 end; 1480 p1 := p1 + sccount[C] 1481 1481 end; 1482 1482 … … 1495 1495 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1496 1496 if RealMap[Loc1] and fTerrain = fGrass then 1497 inc(CntGoodGrass)1497 Inc(CntGoodGrass) 1498 1498 else 1499 inc(CntGood);1499 Inc(CntGood); 1500 1500 end; 1501 1501 for V21 := 1 to 26 do … … 1529 1529 begin 1530 1530 IrrLoc[nIrrLoc] := Loc1; 1531 inc(nIrrLoc);1532 end; 1533 end; 1534 i:= 2;1535 if i> nIrrLoc then1536 i:= nIrrLoc;1537 while i> 0 do1538 begin 1539 j:= DelphiRandom(nIrrLoc);1540 RealMap[IrrLoc[ j]] := RealMap[IrrLoc[j]] or tiIrrigation;1541 IrrLoc[ j] := IrrLoc[nIrrLoc - 1];1542 dec(nIrrLoc);1543 dec(i);1531 Inc(nIrrLoc); 1532 end; 1533 end; 1534 I := 2; 1535 if I > nIrrLoc then 1536 I := nIrrLoc; 1537 while I > 0 do 1538 begin 1539 J := DelphiRandom(nIrrLoc); 1540 RealMap[IrrLoc[J]] := RealMap[IrrLoc[J]] or tiIrrigation; 1541 IrrLoc[J] := IrrLoc[nIrrLoc - 1]; 1542 Dec(nIrrLoc); 1543 Dec(I); 1544 1544 end; 1545 1545 end; … … 1550 1550 begin 1551 1551 repeat 1552 i:= DelphiRandom(nAlive) + 11553 until StartLoc0[ i] >= 0;1554 StartLoc[p1] := StartLoc0[ i];1555 StartLoc0[ i] := -11552 I := DelphiRandom(nAlive) + 1 1553 until StartLoc0[I] >= 0; 1554 StartLoc[p1] := StartLoc0[I]; 1555 StartLoc0[I] := -1 1556 1556 end; 1557 1557 SaveMapCenterLoc := StartLoc[0]; … … 1586 1586 StartLoc2[p1] := Loc1; 1587 1587 BestDist := TestDist; 1588 n:= 1;1588 N := 1; 1589 1589 end 1590 1590 else if TestDist = BestDist then 1591 1591 begin 1592 inc(n);1593 if DelphiRandom( n) = 0 then1592 Inc(N); 1593 if DelphiRandom(N) = 0 then 1594 1594 StartLoc2[p1] := Loc1; 1595 1595 end; … … 1598 1598 end; 1599 1599 1600 procedure PredefinedStartPositions(Human: integer);1600 procedure PredefinedStartPositions(Human: Integer); 1601 1601 // use predefined nation start positions 1602 1602 var 1603 i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;1604 StartLoc0: array [0 .. lxmax * lymax - 1] of integer;1605 ishuman: boolean;1603 I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer; 1604 StartLoc0: array [0 .. lxmax * lymax - 1] of Integer; 1605 ishuman: Boolean; 1606 1606 begin 1607 1607 nAlive := 0; 1608 1608 for p1 := 0 to nPl - 1 do 1609 1609 if 1 shl p1 and GAlive <> 0 then 1610 inc(nAlive);1610 Inc(nAlive); 1611 1611 if nAlive = 0 then 1612 exit;1612 Exit; 1613 1613 1614 1614 for I := 0 to Length(StartLoc0) - 1 do … … 1623 1623 StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0]; 1624 1624 StartLoc0[nPrefStartLoc0] := Loc1; 1625 inc(nPrefStartLoc0);1626 inc(nStartLoc0);1625 Inc(nPrefStartLoc0); 1626 Inc(nStartLoc0); 1627 1627 RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos; 1628 1628 end … … 1630 1630 begin 1631 1631 StartLoc0[nStartLoc0] := Loc1; 1632 inc(nStartLoc0);1632 Inc(nStartLoc0); 1633 1633 RealMap[Loc1] := RealMap[Loc1] and not fStartPos; 1634 1634 end; 1635 assert(nStartLoc0 >= nAlive);1635 Assert(nStartLoc0 >= nAlive); 1636 1636 1637 1637 StartLoc[0] := 0; 1638 for ishuman := true downto false do1638 for ishuman := True downto False do 1639 1639 for p1 := 0 to nPl - 1 do 1640 1640 if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman) 1641 1641 then 1642 1642 begin 1643 dec(nStartLoc0);1643 Dec(nStartLoc0); 1644 1644 imax := nStartLoc0; 1645 1645 if nPrefStartLoc0 > 0 then 1646 1646 begin 1647 dec(nPrefStartLoc0);1647 Dec(nPrefStartLoc0); 1648 1648 imax := nPrefStartLoc0; 1649 1649 end; 1650 i:= DelphiRandom(imax + 1);1651 StartLoc[p1] := StartLoc0[ i];1652 StartLoc2[p1] := StartLoc0[ i];1653 StartLoc0[ i] := StartLoc0[imax];1650 I := DelphiRandom(imax + 1); 1651 StartLoc[p1] := StartLoc0[I]; 1652 StartLoc2[p1] := StartLoc0[I]; 1653 StartLoc0[I] := StartLoc0[imax]; 1654 1654 StartLoc0[imax] := StartLoc0[nStartLoc0]; 1655 1655 end; … … 1659 1659 procedure InitGame; 1660 1660 var 1661 i, p, p1, uix, Loc1: integer;1661 I, P, p1, uix, Loc1: Integer; 1662 1662 begin 1663 1663 {$IFDEF FastContact} … … 1683 1683 GTestFlags := 0; 1684 1684 GInitialized := GAlive or GWatching; 1685 for p:= 0 to nPl - 1 do1686 if 1 shl pand GInitialized <> 0 then1687 with RW[ p] do1688 begin 1689 Researched[ p] := 0;1690 Discovered[ p] := 0;1691 TerritoryCount[ p] := 0;1692 nTech[ p] := 0;1693 if Difficulty[ p] = 0 then1694 ResourceMask[ p] := $FFFFFFFF1685 for P := 0 to nPl - 1 do 1686 if 1 shl P and GInitialized <> 0 then 1687 with RW[P] do 1688 begin 1689 Researched[P] := 0; 1690 Discovered[P] := 0; 1691 TerritoryCount[P] := 0; 1692 nTech[P] := 0; 1693 if Difficulty[P] = 0 then 1694 ResourceMask[P] := $FFFFFFFF 1695 1695 else 1696 ResourceMask[ p] := $FFFFFFFF and not(fSpecial2 or fModern);1697 GrWallContinent[ p] := -1;1696 ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern); 1697 GrWallContinent[P] := -1; 1698 1698 1699 1699 GetMem(Map, 4 * MapSize); … … 1713 1713 if 1 shl p1 and GInitialized <> 0 then 1714 1714 begin 1715 FillChar(RWemix[ p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }1716 FillChar(Destroyed[ p, p1], SizeOf(Destroyed[p, p1]), 0);1715 FillChar(RWemix[P, p1], SizeOf(RWemix[P, p1]), 255); { -1 } 1716 FillChar(Destroyed[P, p1], SizeOf(Destroyed[P, p1]), 0); 1717 1717 end; 1718 1718 Attitude[p1] := atNeutral; … … 1722 1722 Tribute[p1] := 0; 1723 1723 TributePaid[p1] := 0; 1724 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1724 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1725 1725 begin // initialize enemy report 1726 1726 GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 * … … 1732 1732 EnemyReport[p1].Attitude := atNeutral; 1733 1733 EnemyReport[p1].Government := gDespotism; 1734 if 1 shl pand GAlive = 0 then1734 if 1 shl P and GAlive = 0 then 1735 1735 Treaty[p1] := trNone // supervisor 1736 1736 end … … 1754 1754 1755 1755 // create initial models and units 1756 for p:= 0 to nPl - 1 do1757 if (1 shl pand GAlive <> 0) then1758 with RW[ p] do1756 for P := 0 to nPl - 1 do 1757 if (1 shl P and GAlive <> 0) then 1758 with RW[P] do 1759 1759 begin 1760 1760 nModel := 0; 1761 for i:= 0 to nSpecialModel - 1 do1762 if SpecialModelPreq[ i] = preNone then1761 for I := 0 to nSpecialModel - 1 do 1762 if SpecialModelPreq[I] = preNone then 1763 1763 begin 1764 Model[nModel] := SpecialModel[ i];1764 Model[nModel] := SpecialModel[I]; 1765 1765 Model[nModel].Status := 0; 1766 1766 Model[nModel].IntroTurn := 0; 1767 1767 Model[nModel].Built := 0; 1768 1768 Model[nModel].Lost := 0; 1769 Model[nModel].ID := pshl 12 + nModel;1769 Model[nModel].ID := P shl 12 + nModel; 1770 1770 SetModelFlags(Model[nModel]); 1771 inc(nModel);1771 Inc(nModel); 1772 1772 end; 1773 1773 nUn := 0; 1774 UnBuilt[ p] := 0;1774 UnBuilt[P] := 0; 1775 1775 for uix := 0 to nStartUn - 1 do 1776 1776 begin 1777 CreateUnit( p, StartUn[uix]);1778 dec(Model[StartUn[uix]].Built);1779 Un[uix].Loc := StartLoc2[ p];1780 PlaceUnit( p, uix);1781 end; 1782 FoundCity( p, StartLoc[p]); // capital1783 Founded[ p] := 1;1777 CreateUnit(P, StartUn[uix]); 1778 Dec(Model[StartUn[uix]].Built); 1779 Un[uix].Loc := StartLoc2[P]; 1780 PlaceUnit(P, uix); 1781 end; 1782 FoundCity(P, StartLoc[P]); // capital 1783 Founded[P] := 1; 1784 1784 with City[0] do 1785 1785 begin 1786 ID := pshl 12;1786 ID := P shl 12; 1787 1787 Flags := chFounded; 1788 1788 end; … … 1798 1798 CalculatePrimitive; 1799 1799 CreateElevation; 1800 CreateMap( false);1800 CreateMap(False); 1801 1801 StartPositions; 1802 1802 InitGame; 1803 1803 end; 1804 1804 1805 procedure InitMapGame(Human: integer);1805 procedure InitMapGame(Human: Integer); 1806 1806 begin 1807 1807 DelphiRandSeed := RND; … … 1813 1813 procedure ReleaseGame; 1814 1814 var 1815 p1, p2: integer;1815 p1, p2: Integer; 1816 1816 begin 1817 1817 for p1 := 0 to nPl - 1 do … … 1835 1835 procedure InitMapEditor; 1836 1836 var 1837 p1: integer;1837 p1: Integer; 1838 1838 begin 1839 1839 CalculatePrimitive; … … 1872 1872 end; 1873 1873 1874 procedure EditTile(Loc, NewTile: integer);1875 var 1876 Loc1, V21: integer;1874 procedure EditTile(Loc, NewTile: Integer); 1875 var 1876 Loc1, V21: Integer; 1877 1877 Radius: TVicinity21Loc; 1878 1878 begin … … 1932 1932 ____________________________________________________________________ 1933 1933 } 1934 function GetTileInfo( p, cix, Loc: integer; var Info: TTileInfo): integer;1934 function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer; 1935 1935 // cix>=0 - known city index of player p -- only core internal! 1936 1936 // cix=-1 - search city, player unknown, only if permission for p 1937 1937 // cix=-2 - don't search city, don't calculate city benefits, just government of player p 1938 1938 var 1939 p0, Tile, special: integer;1939 p0, Tile, special: Integer; 1940 1940 begin 1941 1941 with Info do 1942 1942 begin 1943 p0 := p;1943 p0 := P; 1944 1944 if cix >= 0 then 1945 1945 Tile := RealMap[Loc] 1946 1946 else 1947 1947 begin 1948 Tile := RW[ p].Map[Loc];1948 Tile := RW[P].Map[Loc]; 1949 1949 if Tile and fTerrain = fUNKNOWN then 1950 1950 begin 1951 result := eNoPreq;1952 exit;1951 Result := eNoPreq; 1952 Exit; 1953 1953 end; 1954 1954 end; … … 1956 1956 if (cix = -1) and (UsedByCity[Loc] >= 0) then 1957 1957 begin // search exploiting player and city 1958 SearchCity(UsedByCity[Loc], p, cix);1959 if not(( p= p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and1958 SearchCity(UsedByCity[Loc], P, cix); 1959 if not((P = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and 1960 1960 3 = lObserveSuper)) then 1961 1961 cix := -1 … … 1963 1963 if cix = -1 then 1964 1964 begin 1965 result := eInvalid;1966 exit;1965 Result := eInvalid; 1966 Exit; 1967 1967 end; // no city found here 1968 1968 1969 special := Tile and fSpecial and ResourceMask[ p] shr 5;1969 special := Tile and fSpecial and ResourceMask[P] shr 5; 1970 1970 with Terrain[Tile and fTerrain] do 1971 1971 begin … … 1974 1974 Trade := TradeRes[special]; 1975 1975 if (special > 0) and (Tile and fTerrain <> fGrass) and 1976 (RW[ p].NatBuilt[imSpacePort] > 0) then1976 (RW[P].NatBuilt[imSpacePort] > 0) then 1977 1977 begin // GeoSat effect 1978 1978 Food := 2 * Food - FoodRes[0]; … … 1983 1983 if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or 1984 1984 (Tile and fCity <> 0) then 1985 inc(Food, IrrEff); { irrigation effect }1985 Inc(Food, IrrEff); { irrigation effect } 1986 1986 if Tile and fTerImp = tiMine then 1987 inc(Prod, MineEff); { mining effect }1988 if (Tile and fRiver <> 0) and (RW[ p].Tech[adMapMaking] >= tsApplicable)1987 Inc(Prod, MineEff); { mining effect } 1988 if (Tile and fRiver <> 0) and (RW[P].Tech[adMapMaking] >= tsApplicable) 1989 1989 then 1990 inc(Trade); { river effect }1990 Inc(Trade); { river effect } 1991 1991 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 1992 (RW[ p].Tech[adWheel] >= tsApplicable) then1993 inc(Trade); { road effect }1992 (RW[P].Tech[adWheel] >= tsApplicable) then 1993 Inc(Trade); { road effect } 1994 1994 if (Tile and (fRR or fCity) <> 0) and 1995 (RW[ p].Tech[adRailroad] >= tsApplicable) then1996 inc(Prod, Prod shr 1); { railroad effect }1995 (RW[P].Tech[adRailroad] >= tsApplicable) then 1996 Inc(Prod, Prod shr 1); { railroad effect } 1997 1997 1998 1998 ExplCity := -1; 1999 if (cix >= 0) and ( p= p0) then1999 if (cix >= 0) and (P = p0) then 2000 2000 ExplCity := cix; 2001 2001 if cix >= 0 then … … 2003 2003 begin 2004 2004 if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and 2005 (RW[ p].City[cix].Built[imSupermarket] > 0) then2006 inc(Food, Food shr 1); { farmland effect }2005 (RW[P].City[cix].Built[imSupermarket] > 0) then 2006 Inc(Food, Food shr 1); { farmland effect } 2007 2007 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 2008 (RW[ p].City[cix].Built[imHighways] > 0) then2009 inc(Trade, 1); { superhighway effect }2008 (RW[P].City[cix].Built[imHighways] > 0) then 2009 Inc(Trade, 1); { superhighway effect } 2010 2010 end 2011 2011 else 2012 2012 begin 2013 if RW[ p].City[cix].Built[imHarbor] > 0 then2014 inc(Food); { harbour effect }2015 if RW[ p].City[cix].Built[imPlatform] > 0 then2016 inc(Prod); { oil platform effect }2017 if GWonder[woLighthouse].EffectiveOwner = pthen2018 inc(Prod);2013 if RW[P].City[cix].Built[imHarbor] > 0 then 2014 Inc(Food); { harbour effect } 2015 if RW[P].City[cix].Built[imPlatform] > 0 then 2016 Inc(Prod); { oil platform effect } 2017 if GWonder[woLighthouse].EffectiveOwner = P then 2018 Inc(Prod); 2019 2019 end; 2020 2020 end; 2021 2021 2022 2022 { good government influence } 2023 if (RW[ p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)2023 if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0) 2024 2024 then 2025 inc(Trade);2026 if (RW[ p].Government = gCommunism) and (Prod > 1) then2027 inc(Prod);2028 2029 if RW[ p].Government in [gAnarchy, gDespotism] then2025 Inc(Trade); 2026 if (RW[P].Government = gCommunism) and (Prod > 1) then 2027 Inc(Prod); 2028 2029 if RW[P].Government in [gAnarchy, gDespotism] then 2030 2030 begin { bad government influence } 2031 2031 if Food > 3 then … … 2039 2039 if Tile and (fTerrain or fPoll) > fPoll then 2040 2040 begin { pollution - decrease ressources } 2041 dec(Food, Food shr 1);2042 dec(Prod, Prod shr 1);2043 dec(Trade, Trade shr 1);2041 Dec(Food, Food shr 1); 2042 Dec(Prod, Prod shr 1); 2043 Dec(Trade, Trade shr 1); 2044 2044 end; 2045 2045 2046 2046 if Tile and fCity <> 0 then 2047 2047 Trade := 0 2048 else if (cix >= 0) and (RW[ p].City[cix].Built[imCourt] + RW[p].City[cix]2048 else if (cix >= 0) and (RW[P].City[cix].Built[imCourt] + RW[P].City[cix] 2049 2049 .Built[imPalace] = 0) then 2050 if RW[ p].City[cix].Built[imTownHall] = 0 then2050 if RW[P].City[cix].Built[imTownHall] = 0 then 2051 2051 Trade := 0 2052 2052 else if Trade > 3 then 2053 2053 Trade := 3; 2054 2054 end; 2055 result := eOK;2056 end; 2057 2058 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);2055 Result := eOK; 2056 end; 2057 2058 procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer); 2059 2059 { find strongest defender at Loc } 2060 2060 var 2061 2061 Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost, 2062 Domain: integer;2062 Domain: Integer; 2063 2063 PUn: ^TUn; 2064 2064 PModel: ^TModel; … … 2078 2078 if PUn.Loc = Loc then 2079 2079 begin 2080 inc(Cnt);2080 Inc(Cnt); 2081 2081 if PUn.Master < 0 then 2082 2082 begin … … 2085 2085 TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense; 2086 2086 if RealMap[Loc] and fTerImp = tiFort then 2087 inc(TestBonus, 4);2087 Inc(TestBonus, 4); 2088 2088 if PUn.Flags and unFortified <> 0 then 2089 inc(TestBonus, 2);2089 Inc(TestBonus, 2); 2090 2090 if (PModel.Kind = mkSpecial_TownGuard) and 2091 2091 (RealMap[Loc] and fCity <> 0) then 2092 inc(TestBonus, 4);2092 Inc(TestBonus, 4); 2093 2093 end 2094 2094 else 2095 2095 TestBonus := 4; 2096 inc(TestBonus, PUn.exp div ExpCost);2096 Inc(TestBonus, PUn.exp div ExpCost); 2097 2097 TestStrength := PModel.Defense * TestBonus * PUn.Health; 2098 2098 if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or … … 2104 2104 if PModel.Cap[mcStealth] > 0 then 2105 2105 else if PModel.Cap[mcSub] > 0 then 2106 inc(TestDet, 1 shl 28)2106 Inc(TestDet, 1 shl 28) 2107 2107 else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and 2108 2108 not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then 2109 inc(TestDet, 4 shl 28) // fanatic ground units always defend2109 Inc(TestDet, 4 shl 28) // fanatic ground units always defend 2110 2110 else if PModel.Flags and mdZOC <> 0 then 2111 inc(TestDet, 3 shl 28)2111 Inc(TestDet, 3 shl 28) 2112 2112 else 2113 inc(TestDet, 2 shl 28);2113 Inc(TestDet, 2 shl 28); 2114 2114 TestCost := RW[Defender].Model[PUn.mix].Cost; 2115 2115 if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then … … 2126 2126 end; 2127 2127 2128 function UnitSpeed( p, mix, Health: integer): integer;2129 begin 2130 with RW[ p].Model[mix] do2131 begin 2132 result := Speed;2128 function UnitSpeed(P, mix, Health: Integer): Integer; 2129 begin 2130 with RW[P].Model[mix] do 2131 begin 2132 Result := Speed; 2133 2133 if Domain = dSea then 2134 2134 begin 2135 if GWonder[woMagellan].EffectiveOwner = pthen2136 inc(result, 200);2135 if GWonder[woMagellan].EffectiveOwner = P then 2136 Inc(Result, 200); 2137 2137 if Health < 100 then 2138 result := ((result - 250) * Health div 5000) * 50 + 250;2139 end; 2140 end; 2141 end; 2142 2143 procedure GetUnitReport( p, uix: integer; var UnitReport: TUnitReport);2144 var 2145 TerrOwner: integer;2138 Result := ((Result - 250) * Health div 5000) * 50 + 250; 2139 end; 2140 end; 2141 end; 2142 2143 procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport); 2144 var 2145 TerrOwner: Integer; 2146 2146 PModel: ^TModel; 2147 2147 begin … … 2149 2149 UnitReport.ProdSupport := 0; 2150 2150 UnitReport.ReportFlags := 0; 2151 if RW[ p].Government <> gAnarchy then2152 with RW[ p].Un[uix] do2153 begin 2154 PModel := @RW[ p].Model[mix];2151 if RW[P].Government <> gAnarchy then 2152 with RW[P].Un[uix] do 2153 begin 2154 PModel := @RW[P].Model[mix]; 2155 2155 if (PModel.Kind = mkSettler) 2156 2156 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then 2157 UnitReport.FoodSupport := SettlerFood[RW[ p].Government]2157 UnitReport.FoodSupport := SettlerFood[RW[P].Government] 2158 2158 else if Flags and unConscripts <> 0 then 2159 2159 UnitReport.FoodSupport := 1; 2160 2160 2161 if RW[ p].Government <> gFundamentalism then2161 if RW[P].Government <> gFundamentalism then 2162 2162 begin 2163 2163 if GTestFlags and tfImmImprove = 0 then … … 2174 2174 begin 2175 2175 TerrOwner := RealMap[Loc] shr 27; 2176 case RW[ p].Government of2176 case RW[P].Government of 2177 2177 gRepublic, gFuture: 2178 if (TerrOwner <> p) and (TerrOwner < nPl) and2179 (RW[ p].Treaty[TerrOwner] < trAlliance) then2178 if (TerrOwner <> P) and (TerrOwner < nPl) and 2179 (RW[P].Treaty[TerrOwner] < trAlliance) then 2180 2180 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2181 2181 gDemocracy: 2182 if (TerrOwner >= nPl) or (TerrOwner <> p) and2183 (RW[ p].Treaty[TerrOwner] < trAlliance) then2182 if (TerrOwner >= nPl) or (TerrOwner <> P) and 2183 (RW[P].Treaty[TerrOwner] < trAlliance) then 2184 2184 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2185 2185 end; … … 2189 2189 end; 2190 2190 2191 procedure SearchCity(Loc: integer; var p, cix: integer);2191 procedure SearchCity(Loc: Integer; var P, cix: Integer); 2192 2192 // set p to supposed owner before call 2193 2193 var 2194 i: integer;2194 I: Integer; 2195 2195 begin 2196 2196 if RealMap[Loc] < nPl shl 27 then 2197 p:= RealMap[Loc] shr 27;2198 for i:= 0 to nPl - 1 do2199 begin 2200 if 1 shl pand GAlive <> 0 then2201 with RW[ p] do2197 P := RealMap[Loc] shr 27; 2198 for I := 0 to nPl - 1 do 2199 begin 2200 if 1 shl P and GAlive <> 0 then 2201 with RW[P] do 2202 2202 begin 2203 2203 cix := nCity - 1; 2204 2204 while (cix >= 0) and (City[cix].Loc <> Loc) do 2205 dec(cix);2205 Dec(cix); 2206 2206 if cix >= 0 then 2207 exit;2208 end; 2209 assert(i< nPl - 1);2210 p := (p+ 1) mod nPl;2211 end; 2212 end; 2213 2214 procedure MakeCityInfo( p, cix: integer; var ci: TCityInfo);2215 begin 2216 assert((p >= 0) and (p< nPl));2217 assert((cix >= 0) and (cix < RW[p].nCity));2218 with RW[ p].City[cix] do2207 Exit; 2208 end; 2209 Assert(I < nPl - 1); 2210 P := (P + 1) mod nPl; 2211 end; 2212 end; 2213 2214 procedure MakeCityInfo(P, cix: Integer; var ci: TCityInfo); 2215 begin 2216 Assert((P >= 0) and (P < nPl)); 2217 Assert((cix >= 0) and (cix < RW[P].nCity)); 2218 with RW[P].City[cix] do 2219 2219 begin 2220 2220 ci.Loc := Loc; 2221 2221 ci.ID := ID; 2222 ci.Owner := p;2222 ci.Owner := P; 2223 2223 ci.Size := Size; 2224 2224 ci.Flags := 0; 2225 2225 if Built[imPalace] > 0 then 2226 inc(ci.Flags, ciCapital);2227 if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[ p]) then2228 inc(ci.Flags, ciWalled);2226 Inc(ci.Flags, ciCapital); 2227 if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[P]) then 2228 Inc(ci.Flags, ciWalled); 2229 2229 if Built[imCoastalFort] > 0 then 2230 inc(ci.Flags, ciCoastalFort);2230 Inc(ci.Flags, ciCoastalFort); 2231 2231 if Built[imMissileBat] > 0 then 2232 inc(ci.Flags, ciMissileBat);2232 Inc(ci.Flags, ciMissileBat); 2233 2233 if Built[imBunker] > 0 then 2234 inc(ci.Flags, ciBunker);2234 Inc(ci.Flags, ciBunker); 2235 2235 if Built[imSpacePort] > 0 then 2236 inc(ci.Flags, ciSpacePort);2237 end; 2238 end; 2239 2240 procedure TellAboutModel( p, taOwner, tamix: integer);2241 var 2242 i: integer;2243 begin 2244 if ( p= taOwner) or (Mode < moPlaying) then2245 exit;2246 i:= 0;2247 while ( i < RW[p].nEnemyModel) and ((RW[p].EnemyModel[i].Owner <> taOwner) or2248 (RW[ p].EnemyModel[i].mix <> tamix)) do2249 inc(i);2250 if i = RW[p].nEnemyModel then2251 IntServer(sIntTellAboutModel + pshl 4, taOwner, tamix, nil^);2252 end; 2253 2254 function emixSafe( p, taOwner, tamix: integer): integer;2255 begin 2256 result := RWemix[p, taOwner, tamix];2257 if result < 0 then2236 Inc(ci.Flags, ciSpacePort); 2237 end; 2238 end; 2239 2240 procedure TellAboutModel(P, taOwner, tamix: Integer); 2241 var 2242 I: Integer; 2243 begin 2244 if (P = taOwner) or (Mode < moPlaying) then 2245 Exit; 2246 I := 0; 2247 while (I < RW[P].nEnemyModel) and ((RW[P].EnemyModel[I].Owner <> taOwner) or 2248 (RW[P].EnemyModel[I].mix <> tamix)) do 2249 Inc(I); 2250 if I = RW[P].nEnemyModel then 2251 IntServer(sIntTellAboutModel + P shl 4, taOwner, tamix, nil^); 2252 end; 2253 2254 function emixSafe(P, taOwner, tamix: Integer): Integer; 2255 begin 2256 Result := RWemix[P, taOwner, tamix]; 2257 if Result < 0 then 2258 2258 begin // sIntTellAboutModel comes too late 2259 assert(Mode = moMovie);2260 result := $FFFF;2261 end; 2262 end; 2263 2264 procedure IntroduceEnemy(p1, p2: integer);2259 Assert(Mode = moMovie); 2260 Result := $FFFF; 2261 end; 2262 end; 2263 2264 procedure IntroduceEnemy(p1, p2: Integer); 2265 2265 begin 2266 2266 RW[p1].Treaty[p2] := trNone; … … 2268 2268 end; 2269 2269 2270 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;2271 euix: integer = -2): boolean;2270 function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean; 2271 euix: Integer = -2): Boolean; 2272 2272 // euix = -2: full discover 2273 2273 // euix = -1: unit and city only, append units in EnemyUn 2274 2274 // euix >= 0: unit and city only, replace EnemyUn[euix] 2275 2275 2276 procedure SetContact(p1, p2: integer);2276 procedure SetContact(p1, p2: Integer); 2277 2277 begin 2278 2278 if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then 2279 exit;2279 Exit; 2280 2280 IntServer(sIntTellAboutNation, p1, p2, nil^); 2281 2281 // NewContact[p1,p2]:=true … … 2283 2283 2284 2284 var 2285 i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,2286 cixFoundCity, MinLevel, Loc1, V8: integer;2285 I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity, 2286 cixFoundCity, MinLevel, Loc1, V8: Integer; 2287 2287 Tile, AddFlags: Cardinal; 2288 2288 Adjacent: TVicinity8Loc; … … 2290 2290 mox: ^TModel; 2291 2291 begin 2292 result := false;2292 Result := False; 2293 2293 with RW[pTell] do 2294 2294 begin … … 2306 2306 AddFlags := AddFlags or fGrWall; 2307 2307 if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and 2308 (pTell = p)) then2308 (pTell = P)) then 2309 2309 begin // set fPeace flag? 2310 2310 TerrOwner := Tile shr 27; … … 2333 2333 unx := @RW[Occupant[Loc]].Un[uix]; 2334 2334 mox := @RW[Occupant[Loc]].Model[unx.mix]; 2335 assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));2335 Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0)); 2336 2336 if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and 2337 2337 (Tile and fTerImp <> tiBase) then … … 2349 2349 begin 2350 2350 uix := nEnemyUn; 2351 inc(nEnemyUn);2352 assert(nEnemyUn < neumax);2351 Inc(nEnemyUn); 2352 Assert(nEnemyUn < neumax); 2353 2353 end; 2354 2354 MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]); 2355 2355 if Cnt > 1 then 2356 2356 EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti; 2357 if (mox.Flags and mdZOC <> 0) and (pTell = p) and2357 if (mox.Flags and mdZOC <> 0) and (pTell = P) and 2358 2358 (Treaty[Occupant[Loc]] < trAlliance) then 2359 2359 begin // set fInEnemyZoC flags of surrounding tiles … … 2374 2374 end; 2375 2375 // Level:=lObserveSuper; // don't discover unit twice 2376 if (pTell = p) and2376 if (pTell = P) and 2377 2377 ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then 2378 result := true;2378 Result := True; 2379 2379 end 2380 2380 else … … 2398 2398 while (cixFoundCity >= 0) and 2399 2399 (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do 2400 dec(cixFoundCity);2401 assert(cixFoundCity >= 0);2402 i:= 0;2403 while ( i < nEnemyCity) and (EnemyCity[i].Loc <> Loc) do2404 inc(i);2405 if i= nEnemyCity then2400 Dec(cixFoundCity); 2401 Assert(cixFoundCity >= 0); 2402 I := 0; 2403 while (I < nEnemyCity) and (EnemyCity[I].Loc <> Loc) do 2404 Inc(I); 2405 if I = nEnemyCity then 2406 2406 begin 2407 inc(nEnemyCity);2408 assert(nEnemyCity < necmax);2409 EnemyCity[ i].Status := 0;2410 EnemyCity[ i].SavedStatus := 0;2411 if pTell = pthen2412 result := true;2407 Inc(nEnemyCity); 2408 Assert(nEnemyCity < necmax); 2409 EnemyCity[I].Status := 0; 2410 EnemyCity[I].SavedStatus := 0; 2411 if pTell = P then 2412 Result := True; 2413 2413 end; 2414 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[ i]);2414 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]); 2415 2415 end; 2416 2416 end … … 2421 2421 2422 2422 if Map[Loc] and fTerrain = fUNKNOWN then 2423 inc(Discovered[pTell]);2423 Inc(Discovered[pTell]); 2424 2424 if euix >= -1 then 2425 2425 Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or … … 2440 2440 end; 2441 2441 2442 function Discover9(Loc, p, Level: integer;2443 TellAllied, EnableContact: boolean): boolean;2444 var 2445 V9, Loc1, pTell, OldLevel: integer;2442 function Discover9(Loc, P, Level: Integer; 2443 TellAllied, EnableContact: Boolean): Boolean; 2444 var 2445 V9, Loc1, pTell, OldLevel: Integer; 2446 2446 Radius: TVicinity8Loc; 2447 2447 begin 2448 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2449 result := false;2448 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2449 Result := False; 2450 2450 V8_to_Loc(Loc, Radius); 2451 2451 for V9 := 0 to 8 do … … 2459 2459 begin 2460 2460 for pTell := 0 to nPl - 1 do 2461 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2462 (RW[ p].Treaty[pTell] = trAlliance) then2461 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2462 (RW[P].Treaty[pTell] = trAlliance) then 2463 2463 begin 2464 2464 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2465 2465 if Level > OldLevel then 2466 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2467 or result;2466 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2467 or Result; 2468 2468 end; 2469 2469 end 2470 2470 else 2471 2471 begin 2472 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2472 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2473 2473 if Level > OldLevel then 2474 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2475 end; 2476 end; 2477 end; 2478 2479 function Discover21(Loc, p, AdjacentLevel: integer;2480 TellAllied, EnableContact: boolean): boolean;2481 var 2482 V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: integer;2474 Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result; 2475 end; 2476 end; 2477 end; 2478 2479 function Discover21(Loc, P, AdjacentLevel: Integer; 2480 TellAllied, EnableContact: Boolean): Boolean; 2481 var 2482 V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: Integer; 2483 2483 Radius: TVicinity21Loc; 2484 2484 begin 2485 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2486 result := false;2485 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2486 Result := False; 2487 2487 AdjacentFlags := $00267620 shr 1; 2488 2488 V21_to_Loc(Loc, Radius); … … 2499 2499 begin 2500 2500 for pTell := 0 to nPl - 1 do 2501 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2502 (RW[ p].Treaty[pTell] = trAlliance) then2501 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2502 (RW[P].Treaty[pTell] = trAlliance) then 2503 2503 begin 2504 2504 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2505 2505 if Level > OldLevel then 2506 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2507 or result;2506 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2507 or Result; 2508 2508 end; 2509 2509 end 2510 2510 else 2511 2511 begin 2512 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2512 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2513 2513 if Level > OldLevel then 2514 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2514 Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result; 2515 2515 end; 2516 2516 end; … … 2519 2519 end; 2520 2520 2521 procedure DiscoverAll( p, Level: integer);2521 procedure DiscoverAll(P, Level: Integer); 2522 2522 { player p discovers complete playground (for supervisor) } 2523 2523 var 2524 Loc, OldLevel: integer;2525 begin 2526 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2524 Loc, OldLevel: Integer; 2525 begin 2526 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2527 2527 for Loc := 0 to MapSize - 1 do 2528 2528 begin 2529 OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;2529 OldLevel := ObserveLevel[Loc] shr (2 * P) and 3; 2530 2530 if Level > OldLevel then 2531 DiscoverTile(Loc, p, p, Level, false);2532 end; 2533 end; 2534 2535 procedure DiscoverViewAreas( p: integer);2536 var 2537 pTell, uix, cix, ecix, Loc, RealOwner: integer;2531 DiscoverTile(Loc, P, P, Level, False); 2532 end; 2533 end; 2534 2535 procedure DiscoverViewAreas(P: Integer); 2536 var 2537 pTell, uix, cix, ecix, Loc, RealOwner: Integer; 2538 2538 PModel: ^TModel; 2539 2539 begin // discover unit and city view areas 2540 2540 for pTell := 0 to nPl - 1 do 2541 if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then2541 if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then 2542 2542 begin 2543 2543 for uix := 0 to RW[pTell].nUn - 1 do … … 2547 2547 PModel := @RW[pTell].Model[mix]; 2548 2548 if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then 2549 Discover21(Loc, p, lObserveSuper, false, true)2549 Discover21(Loc, P, lObserveSuper, False, True) 2550 2550 else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or 2551 2551 (PModel.Domain = dAir) then 2552 Discover21(Loc, p, lObserveAll, false, false)2552 Discover21(Loc, P, lObserveAll, False, False) 2553 2553 else if (RealMap[Loc] and fTerrain = fMountains) or 2554 2554 (RealMap[Loc] and fTerImp = tiFort) or 2555 2555 (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0) 2556 2556 then 2557 Discover21(Loc, p, lObserveUnhidden, false,2557 Discover21(Loc, P, lObserveUnhidden, False, 2558 2558 PModel.Domain = dGround) 2559 2559 else 2560 Discover9(Loc, p, lObserveUnhidden, false,2560 Discover9(Loc, P, lObserveUnhidden, False, 2561 2561 PModel.Domain = dGround); 2562 2562 end; 2563 2563 for cix := 0 to RW[pTell].nCity - 1 do 2564 2564 if RW[pTell].City[cix].Loc >= 0 then 2565 Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);2565 Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True); 2566 2566 for ecix := 0 to RW[pTell].nEnemyCity - 1 do 2567 2567 begin // players know territory, so no use in hiding city owner … … 2582 2582 end; 2583 2583 2584 function GetUnitStack( p, Loc: integer): integer;2585 var 2586 uix: integer;2584 function GetUnitStack(P, Loc: Integer): Integer; 2585 var 2586 uix: Integer; 2587 2587 unx: ^TUn; 2588 2588 begin 2589 result := 0;2589 Result := 0; 2590 2590 if Occupant[Loc] < 0 then 2591 exit;2591 Exit; 2592 2592 for uix := 0 to RW[Occupant[Loc]].nUn - 1 do 2593 2593 begin … … 2595 2595 if unx.Loc = Loc then 2596 2596 begin 2597 MakeUnitInfo(Occupant[Loc], unx^, RW[ p].EnemyUn[RW[p].nEnemyUn + result]);2598 TellAboutModel( p, Occupant[Loc], unx.mix);2599 RW[ p].EnemyUn[RW[p].nEnemyUn + result].emix :=2600 RWemix[ p, Occupant[Loc], unx.mix];2601 inc(result);2602 end; 2603 end; 2604 end; 2605 2606 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);2597 MakeUnitInfo(Occupant[Loc], unx^, RW[P].EnemyUn[RW[P].nEnemyUn + Result]); 2598 TellAboutModel(P, Occupant[Loc], unx.mix); 2599 RW[P].EnemyUn[RW[P].nEnemyUn + Result].emix := 2600 RWemix[P, Occupant[Loc], unx.mix]; 2601 Inc(Result); 2602 end; 2603 end; 2604 end; 2605 2606 procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False); 2607 2607 // update maps and enemy units of all players after unit change 2608 2608 var 2609 p, euix, OldLevel: integer;2609 P, euix, OldLevel: Integer; 2610 2610 AddFlags, ClearFlags: Cardinal; 2611 2611 begin 2612 2612 if (Mode = moLoading_Fast) and not CityChange then 2613 exit;2614 for p:= 0 to nPl - 1 do2615 if 1 shl pand (GAlive or GWatching) <> 0 then2616 begin 2617 OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;2613 Exit; 2614 for P := 0 to nPl - 1 do 2615 if 1 shl P and (GAlive or GWatching) <> 0 then 2616 begin 2617 OldLevel := ObserveLevel[Loc] shr (2 * P) and 3; 2618 2618 if OldLevel > lNoObserve then 2619 2619 begin 2620 if RW[ p].Map[Loc] and (fUnit or fOwned) = fUnit then2620 if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then 2621 2621 begin 2622 2622 // replace unit located here in EnemyUn 2623 2623 // do not just set loc:=-1 because total number would be unlimited 2624 euix := RW[ p].nEnemyUn - 1;2624 euix := RW[P].nEnemyUn - 1; 2625 2625 while euix >= 0 do 2626 2626 begin 2627 if RW[ p].EnemyUn[euix].Loc = Loc then2627 if RW[P].EnemyUn[euix].Loc = Loc then 2628 2628 begin 2629 RW[ p].EnemyUn[euix].Loc := -1;2629 RW[P].EnemyUn[euix].Loc := -1; 2630 2630 Break; 2631 2631 end; 2632 dec(euix);2632 Dec(euix); 2633 2633 end; 2634 RW[ p].Map[Loc] := RW[p].Map[Loc] and not fUnit2634 RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit 2635 2635 end 2636 2636 else 2637 2637 begin // look for empty slot in EnemyUn 2638 euix := RW[ p].nEnemyUn - 1;2639 while (euix >= 0) and (RW[ p].EnemyUn[euix].Loc >= 0) do2640 dec(euix);2638 euix := RW[P].nEnemyUn - 1; 2639 while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do 2640 Dec(euix); 2641 2641 end; 2642 2642 if (Occupant[Loc] < 0) and not CityChange then … … 2645 2645 if RealMap[Loc] and fCity = 0 then 2646 2646 ClearFlags := ClearFlags or fOwned; 2647 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;2647 RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags; 2648 2648 end 2649 else if (Occupant[Loc] <> p) or CityChange then2649 else if (Occupant[Loc] <> P) or CityChange then 2650 2650 begin // city or enemy unit update necessary, call DiscoverTile 2651 ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));2652 DiscoverTile(Loc, p, p, OldLevel, false, euix);2651 ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * P)); 2652 DiscoverTile(Loc, P, P, OldLevel, False, euix); 2653 2653 end 2654 2654 else { if (Occupant[Loc]=p) and not CityChange then } … … 2660 2660 else 2661 2661 ClearFlags := ClearFlags or fOwnZoCUnit; 2662 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;2663 end; 2664 end; 2665 end; 2666 end; 2667 2668 procedure RecalcV8ZoC( p, Loc: integer);2662 RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags or AddFlags; 2663 end; 2664 end; 2665 end; 2666 end; 2667 2668 procedure RecalcV8ZoC(P, Loc: Integer); 2669 2669 // recalculate fInEnemyZoC flags around single tile 2670 2670 var 2671 V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;2671 V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer; 2672 2672 Tile1: ^Cardinal; 2673 2673 Adjacent, AdjacentAdjacent: TVicinity8Loc; 2674 2674 begin 2675 2675 if Mode = moLoading_Fast then 2676 exit;2677 ObserveMask := 3 shl (2 * p);2676 Exit; 2677 ObserveMask := 3 shl (2 * P); 2678 2678 V8_to_Loc(Loc, Adjacent); 2679 2679 for V8 := 0 to 7 do … … 2682 2682 if (Loc1 >= 0) and (Loc1 < MapSize) then 2683 2683 begin 2684 Tile1 := @RW[ p].Map[Loc1];2684 Tile1 := @RW[P].Map[Loc1]; 2685 2685 Tile1^ := Tile1^ and not fInEnemyZoC; 2686 2686 V8_to_Loc(Loc1, AdjacentAdjacent); … … 2692 2692 begin 2693 2693 p1 := Occupant[Loc2]; 2694 assert(p1 <> nPl);2695 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2694 Assert(p1 <> nPl); 2695 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2696 2696 begin 2697 2697 Tile1^ := Tile1^ or fInEnemyZoC; … … 2704 2704 end; 2705 2705 2706 procedure RecalcMapZoC( p: integer);2706 procedure RecalcMapZoC(P: Integer); 2707 2707 // recalculate fInEnemyZoC flags for the whole map 2708 2708 var 2709 Loc, Loc1, V8, p1, ObserveMask: integer;2709 Loc, Loc1, V8, p1, ObserveMask: Integer; 2710 2710 Adjacent: TVicinity8Loc; 2711 2711 begin 2712 2712 if Mode = moLoading_Fast then 2713 exit;2714 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));2715 ObserveMask := 3 shl (2 * p);2713 Exit; 2714 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC))); 2715 ObserveMask := 3 shl (2 * P); 2716 2716 for Loc := 0 to MapSize - 1 do 2717 2717 if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then 2718 2718 begin 2719 2719 p1 := Occupant[Loc]; 2720 assert(p1 <> nPl);2721 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2720 Assert(p1 <> nPl); 2721 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2722 2722 begin // this non-allied enemy ZoC unit is known to this player -- set flags! 2723 2723 V8_to_Loc(Loc, Adjacent); … … 2726 2726 Loc1 := Adjacent[V8]; 2727 2727 if (Loc1 >= 0) and (Loc1 < MapSize) then 2728 RW[ p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC;2729 end; 2730 end; 2731 end; 2732 end; 2733 2734 procedure RecalcPeaceMap( p: integer);2728 RW[P].Map[Loc1] := RW[P].Map[Loc1] or fInEnemyZoC; 2729 end; 2730 end; 2731 end; 2732 end; 2733 2734 procedure RecalcPeaceMap(P: Integer); 2735 2735 // recalculate fPeace flags for the whole map 2736 2736 var 2737 Loc, p1: integer;2738 PeacePlayer: array [-1 .. nPl - 1] of boolean;2737 Loc, p1: Integer; 2738 PeacePlayer: array [-1 .. nPl - 1] of Boolean; 2739 2739 begin 2740 2740 if Mode <> moPlaying then 2741 exit;2742 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));2741 Exit; 2742 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace))); 2743 2743 for p1 := -1 to nPl - 1 do 2744 PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)2745 and (RW[ p].Treaty[p1] in [trPeace, TrFriendlyContact]);2744 PeacePlayer[p1] := (p1 >= 0) and (p1 <> P) and (1 shl p1 and GAlive <> 0) 2745 and (RW[P].Treaty[p1] in [trPeace, TrFriendlyContact]); 2746 2746 for Loc := 0 to MapSize - 1 do 2747 if PeacePlayer[RW[ p].Territory[Loc]] then2748 RW[ p].Map[Loc] := RW[p].Map[Loc] or fPeace;2747 if PeacePlayer[RW[P].Territory[Loc]] then 2748 RW[P].Map[Loc] := RW[P].Map[Loc] or fPeace; 2749 2749 end; 2750 2750 … … 2756 2756 BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal; 2757 2757 2758 procedure ChangeTerritory(Loc, p: integer);2759 var 2760 p1: integer;2761 begin 2762 Assert( p>= 0); // no player's territory indicated by p=nPl2758 procedure ChangeTerritory(Loc, P: Integer); 2759 var 2760 p1: Integer; 2761 begin 2762 Assert(P >= 0); // no player's territory indicated by p=nPl 2763 2763 Dec(TerritoryCount[RealMap[Loc] shr 27]); 2764 Inc(TerritoryCount[ p]);2765 RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal( p) shl 27;2766 if p= $F then2767 p:= -1;2764 Inc(TerritoryCount[P]); 2765 RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(P) shl 27; 2766 if P = $F then 2767 P := -1; 2768 2768 for p1 := 0 to nPl - 1 do 2769 2769 if 1 shl p1 and (GAlive or GWatching) <> 0 then 2770 2770 if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then 2771 2771 begin 2772 RW[p1].Territory[Loc] := p;2773 if ( p < nPl) and (p <> p1) and (1 shl pand GAlive <> 0) and2774 (RW[p1].Treaty[ p] in [trPeace, TrFriendlyContact]) then2772 RW[p1].Territory[Loc] := P; 2773 if (P < nPl) and (P <> p1) and (1 shl P and GAlive <> 0) and 2774 (RW[p1].Treaty[P] in [trPeace, TrFriendlyContact]) then 2775 2775 RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace 2776 2776 else … … 2779 2779 end; 2780 2780 2781 procedure ExpandTerritory(OriginLoc: integer);2782 var 2783 i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;2781 procedure ExpandTerritory(OriginLoc: Integer); 2782 var 2783 I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer; 2784 2784 begin 2785 2785 if OriginLoc = -1 then 2786 2786 raise Exception.Create('Location error'); 2787 i:= 0;2787 I := 0; 2788 2788 dyMax := 0; 2789 2789 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2790 inc(dyMax);2790 Inc(dyMax); 2791 2791 for dy := -dyMax to dyMax do 2792 2792 begin … … 2794 2794 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2795 2795 CountryRadius do 2796 inc(dxMax, 2);2796 Inc(dxMax, 2); 2797 2797 for dx := -dxMax to dxMax do 2798 2798 if (dy + dx) and 1 = 0 then 2799 2799 begin 2800 NewOwner := BorderChanges[ i div 8] shr (imod 8 * 4) and $F;2800 NewOwner := BorderChanges[I div 8] shr (I mod 8 * 4) and $F; 2801 2801 Loc := dLoc(OriginLoc, dx, dy); 2802 2802 if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then 2803 2803 ChangeTerritory(Loc, NewOwner); 2804 inc(i);2805 end; 2806 end; 2807 end; 2808 2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);2804 Inc(I); 2805 end; 2806 end; 2807 end; 2808 2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer); 2810 2810 // OriginLoc: only changes in CountryRadius around this location possible, 2811 2811 // -1 for complete map, -2 for double-check (no more changes allowed) … … 2813 2813 // player's territory, -1 for full border recalculation 2814 2814 var 2815 i, r, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;2815 I, R, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer; 2816 2816 NewOwner: Cardinal; 2817 2817 Adjacent: TVicinity8Loc; 2818 AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;2818 AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean; 2819 2819 Country, FormerCountry, { to who's country a tile belongs } 2820 2820 Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt; … … 2828 2828 StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0; 2829 2829 2830 for r:= 1 to CountryRadius shr 1 do2831 begin 2832 move(StolenDist, FormerDist, MapSize);2830 for R := 1 to CountryRadius shr 1 do 2831 begin 2832 Move(StolenDist, FormerDist, MapSize); 2833 2833 for Loc := 0 to MapSize - 1 do 2834 2834 if (FormerDist[Loc] <= CountryRadius - 2) … … 2862 2862 end; 2863 2863 2864 for r:= 1 to CountryRadius shr 1 do2865 begin 2866 move(Country, FormerCountry, MapSize);2867 move(Dist, FormerDist, MapSize);2864 for R := 1 to CountryRadius shr 1 do 2865 begin 2866 Move(Country, FormerCountry, MapSize); 2867 Move(Dist, FormerDist, MapSize); 2868 2868 for Loc := 0 to MapSize - 1 do 2869 2869 if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above! … … 2871 2871 (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then 2872 2872 begin 2873 assert(FormerCountry[Loc] >= 0);2873 Assert(FormerCountry[Loc] >= 0); 2874 2874 V8_to_Loc(Loc, Adjacent); 2875 2875 for V8 := 0 to 7 do … … 2886 2886 end; 2887 2887 2888 FillChar(AtPeace, SizeOf(AtPeace), false);2888 FillChar(AtPeace, SizeOf(AtPeace), False); 2889 2889 for p1 := 0 to nPl - 1 do 2890 2890 if 1 shl p1 and GAlive <> 0 then … … 2892 2892 if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and 2893 2893 (RW[p1].Treaty[p2] >= trPeace) then 2894 AtPeace[p1, p2] := true;2894 AtPeace[p1, p2] := True; 2895 2895 2896 2896 if OriginLoc >= 0 then 2897 2897 begin // update area only 2898 i:= 0;2898 I := 0; 2899 2899 FillChar(BorderChanges, SizeOf(BorderChanges), 0); 2900 2900 dyMax := 0; 2901 2901 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2902 inc(dyMax);2902 Inc(dyMax); 2903 2903 for dy := -dyMax to dyMax do 2904 2904 begin … … 2906 2906 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2907 2907 CountryRadius do 2908 inc(dxMax, 2);2908 Inc(dxMax, 2); 2909 2909 for dx := -dxMax to dxMax do 2910 2910 if (dy + dx) and 1 = 0 then … … 2922 2922 else 2923 2923 ChangeTerritory(Loc, NewOwner); 2924 BorderChanges[ i shr 3] := BorderChanges[ishr 3] or2925 ((NewOwner shl (( iand 7) * 4)) and $ffffffff);2924 BorderChanges[I shr 3] := BorderChanges[I shr 3] or 2925 ((NewOwner shl ((I and 7) * 4)) and $ffffffff); 2926 2926 end; 2927 inc(i);2927 Inc(I); 2928 2928 end; 2929 2929 end; … … 2938 2938 then 2939 2939 begin 2940 assert(OriginLoc <> -2); // test if border saving works2940 Assert(OriginLoc <> -2); // test if border saving works 2941 2941 ChangeTerritory(Loc, NewOwner); 2942 2942 end; … … 2947 2947 end; 2948 2948 2949 procedure LogCheckBorders( p, cix, PlayerLosingCity: integer);2950 begin 2951 CheckBorders(RW[ p].City[cix].Loc, PlayerLosingCity);2952 IntServer(sIntExpandTerritory, p, cix, BorderChanges);2949 procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer); 2950 begin 2951 CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity); 2952 IntServer(sIntExpandTerritory, P, cix, BorderChanges); 2953 2953 end; 2954 2954 … … 2958 2958 } 2959 2959 2960 procedure CreateUnit( p, mix: integer);2961 begin 2962 with RW[ p] do2960 procedure CreateUnit(P, mix: Integer); 2961 begin 2962 with RW[P] do 2963 2963 begin 2964 2964 Un[nUn].mix := mix; 2965 2965 with Un[nUn] do 2966 2966 begin 2967 ID := UnBuilt[ p];2968 inc(UnBuilt[p]);2967 ID := UnBuilt[P]; 2968 Inc(UnBuilt[P]); 2969 2969 Status := 0; 2970 2970 SavedStatus := 0; 2971 inc(Model[mix].Built);2971 Inc(Model[mix].Built); 2972 2972 Home := -1; 2973 2973 Health := 100; … … 2985 2985 Master := -1; 2986 2986 end; 2987 inc(nUn);2987 Inc(nUn); 2988 2988 end 2989 2989 end; 2990 2990 2991 procedure FreeUnit( p, uix: integer);2991 procedure FreeUnit(P, uix: Integer); 2992 2992 // loc or master should be set after call 2993 2993 // implementation is critical for loading performance, change carefully 2994 2994 var 2995 Loc0, uix1: integer;2996 Occ, ZoC: boolean;2997 begin 2998 with RW[ p].Un[uix] do2995 Loc0, uix1: Integer; 2996 Occ, ZoC: Boolean; 2997 begin 2998 with RW[P].Un[uix] do 2999 2999 begin 3000 3000 Job := jNone; … … 3004 3004 if Occupant[Loc0] >= 0 then 3005 3005 begin 3006 assert(Occupant[Loc0] = p);3007 Occ := false;3008 ZoC := false;3009 for uix1 := 0 to RW[ p].nUn - 1 do3010 with RW[ p].Un[uix1] do3006 Assert(Occupant[Loc0] = P); 3007 Occ := False; 3008 ZoC := False; 3009 for uix1 := 0 to RW[P].nUn - 1 do 3010 with RW[P].Un[uix1] do 3011 3011 if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then 3012 3012 begin 3013 Occ := true;3014 if RW[ p].Model[mix].Flags and mdZOC <> 0 then3013 Occ := True; 3014 if RW[P].Model[mix].Flags and mdZOC <> 0 then 3015 3015 begin 3016 ZoC := true;3016 ZoC := True; 3017 3017 Break; 3018 3018 end; … … 3025 3025 end; 3026 3026 3027 procedure PlaceUnit( p, uix: integer);3028 begin 3029 with RW[ p].Un[uix] do3030 begin 3031 Occupant[Loc] := p;3032 if RW[ p].Model[mix].Flags and mdZOC <> 0 then3027 procedure PlaceUnit(P, uix: Integer); 3028 begin 3029 with RW[P].Un[uix] do 3030 begin 3031 Occupant[Loc] := P; 3032 if RW[P].Model[mix].Flags and mdZOC <> 0 then 3033 3033 ZoCMap[Loc] := 1; 3034 3034 end; 3035 3035 end; 3036 3036 3037 procedure CountLost( p, mix, Enemy: integer);3038 begin 3039 Inc(RW[ p].Model[mix].Lost);3040 TellAboutModel(Enemy, p, mix);3041 Inc(Destroyed[Enemy, p, mix]);3042 end; 3043 3044 procedure RemoveUnit( p, uix: integer; Enemy: integer = -1);3037 procedure CountLost(P, mix, Enemy: Integer); 3038 begin 3039 Inc(RW[P].Model[mix].Lost); 3040 TellAboutModel(Enemy, P, mix); 3041 Inc(Destroyed[Enemy, P, mix]); 3042 end; 3043 3044 procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1); 3045 3045 // use enemy only from inside sMoveUnit if attack 3046 3046 var 3047 uix1: integer;3048 begin 3049 with RW[ p].Un[uix] do3050 begin 3051 assert((Loc >= 0) or (RW[p].Model[mix].Kind = mkDiplomat));3047 uix1: Integer; 3048 begin 3049 with RW[P].Un[uix] do 3050 begin 3051 Assert((Loc >= 0) or (RW[P].Model[mix].Kind = mkDiplomat)); 3052 3052 // already freed when spy mission 3053 3053 if Loc >= 0 then 3054 FreeUnit( p, uix);3054 FreeUnit(P, uix); 3055 3055 if Master >= 0 then 3056 if RW[ p].Model[mix].Domain = dAir then3057 dec(RW[p].Un[Master].AirLoad)3056 if RW[P].Model[mix].Domain = dAir then 3057 Dec(RW[P].Un[Master].AirLoad) 3058 3058 else 3059 dec(RW[p].Un[Master].TroopLoad);3059 Dec(RW[P].Un[Master].TroopLoad); 3060 3060 if (TroopLoad > 0) or (AirLoad > 0) then 3061 for uix1 := 0 to RW[ p].nUn - 1 do3062 if (RW[ p].Un[uix1].Loc >= 0) and (RW[p].Un[uix1].Master = uix) then3061 for uix1 := 0 to RW[P].nUn - 1 do 3062 if (RW[P].Un[uix1].Loc >= 0) and (RW[P].Un[uix1].Master = uix) then 3063 3063 { unit mastered by removed unit -- remove too } 3064 3064 begin 3065 RW[ p].Un[uix1].Loc := -1;3065 RW[P].Un[uix1].Loc := -1; 3066 3066 if Enemy >= 0 then 3067 CountLost( p, RW[p].Un[uix1].mix, Enemy);3067 CountLost(P, RW[P].Un[uix1].mix, Enemy); 3068 3068 end; 3069 3069 Loc := -1; 3070 3070 if Enemy >= 0 then 3071 CountLost( p, mix, Enemy);3072 end; 3073 end; 3074 3075 procedure RemoveUnit_UpdateMap( p, uix: integer);3071 CountLost(P, mix, Enemy); 3072 end; 3073 end; 3074 3075 procedure RemoveUnit_UpdateMap(P, uix: Integer); 3076 3076 var 3077 3077 Loc0: Integer; 3078 3078 begin 3079 Loc0 := RW[ p].Un[uix].Loc;3080 RemoveUnit( p, uix);3079 Loc0 := RW[P].Un[uix].Loc; 3080 RemoveUnit(P, uix); 3081 3081 if Mode > moLoading_Fast then 3082 3082 UpdateUnitMap(Loc0); 3083 3083 end; 3084 3084 3085 procedure RemoveAllUnits( p, Loc: integer; Enemy: integer = -1);3086 var 3087 uix: integer;3088 begin 3089 for uix := 0 to RW[ p].nUn - 1 do3090 if RW[ p].Un[uix].Loc = Loc then3085 procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1); 3086 var 3087 uix: Integer; 3088 begin 3089 for uix := 0 to RW[P].nUn - 1 do 3090 if RW[P].Un[uix].Loc = Loc then 3091 3091 begin 3092 3092 if Enemy >= 0 then 3093 CountLost( p, RW[p].Un[uix].mix, Enemy);3094 RW[ p].Un[uix].Loc := -1;3093 CountLost(P, RW[P].Un[uix].mix, Enemy); 3094 RW[P].Un[uix].Loc := -1; 3095 3095 end; 3096 3096 Occupant[Loc] := -1; … … 3098 3098 end; 3099 3099 3100 procedure RemoveDomainUnits( d, p, Loc: integer);3101 var 3102 uix: integer;3103 begin 3104 for uix := 0 to RW[ p].nUn - 1 do3105 if (RW[ p].Model[RW[p].Un[uix].mix].Domain = d) and (RW[p].Un[uix].Loc = Loc)3100 procedure RemoveDomainUnits(D, P, Loc: Integer); 3101 var 3102 uix: Integer; 3103 begin 3104 for uix := 0 to RW[P].nUn - 1 do 3105 if (RW[P].Model[RW[P].Un[uix].mix].Domain = D) and (RW[P].Un[uix].Loc = Loc) 3106 3106 then 3107 RemoveUnit( p, uix);3108 end; 3109 3110 procedure FoundCity( p, FoundLoc: integer);3111 var 3112 p1, cix1, V21, dx, dy: integer;3113 begin 3114 if RW[ p].nCity = ncmax then3115 exit;3116 inc(RW[p].nCity);3117 with RW[ p].City[RW[p].nCity - 1] do3107 RemoveUnit(P, uix); 3108 end; 3109 3110 procedure FoundCity(P, FoundLoc: Integer); 3111 var 3112 p1, cix1, V21, dx, dy: Integer; 3113 begin 3114 if RW[P].nCity = ncmax then 3115 Exit; 3116 Inc(RW[P].nCity); 3117 with RW[P].City[RW[P].nCity - 1] do 3118 3118 begin 3119 3119 Size := 2; … … 3131 3131 if UsedByCity[FoundLoc] >= 0 then 3132 3132 begin { central tile is exploited - toggle in exploiting city } 3133 p1 := p;3133 p1 := P; 3134 3134 SearchCity(UsedByCity[FoundLoc], p1, cix1); 3135 3135 dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy); … … 3142 3142 (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity; 3143 3143 3144 ChangeTerritory(Loc, p);3145 end; 3146 end; 3147 3148 procedure StealCity( p, cix: integer; SaveUnits: boolean);3149 var 3150 i, j, uix1, cix1, nearest: integer;3151 begin 3152 for i:= 0 to nWonder - 1 do3153 if RW[ p].City[cix].Built[i] = 1 then3154 begin 3155 GWonder[ i].EffectiveOwner := -1;3156 if i= woPyramids then3144 ChangeTerritory(Loc, P); 3145 end; 3146 end; 3147 3148 procedure StealCity(P, cix: Integer; SaveUnits: Boolean); 3149 var 3150 I, J, uix1, cix1, nearest: Integer; 3151 begin 3152 for I := 0 to nWonder - 1 do 3153 if RW[P].City[cix].Built[I] = 1 then 3154 begin 3155 GWonder[I].EffectiveOwner := -1; 3156 if I = woPyramids then 3157 3157 FreeSlaves; 3158 if i= woEiffel then // deactivate expired wonders3159 for j:= 0 to nWonder - 1 do3160 if GWonder[ j].EffectiveOwner = pthen3161 CheckExpiration( j);3162 end; 3163 for i:= nWonder to nImp - 1 do3164 if (Imp[ i].Kind <> ikCommon) and (RW[p].City[cix].Built[i] > 0) then3158 if I = woEiffel then // deactivate expired wonders 3159 for J := 0 to nWonder - 1 do 3160 if GWonder[J].EffectiveOwner = P then 3161 CheckExpiration(J); 3162 end; 3163 for I := nWonder to nImp - 1 do 3164 if (Imp[I].Kind <> ikCommon) and (RW[P].City[cix].Built[I] > 0) then 3165 3165 begin { destroy national projects } 3166 RW[ p].NatBuilt[i] := 0;3167 if i= imGrWall then3168 GrWallContinent[ p] := -1;3169 end; 3170 3171 for uix1 := 0 to RW[ p].nUn - 1 do3172 with RW[ p].Un[uix1] do3166 RW[P].NatBuilt[I] := 0; 3167 if I = imGrWall then 3168 GrWallContinent[P] := -1; 3169 end; 3170 3171 for uix1 := 0 to RW[P].nUn - 1 do 3172 with RW[P].Un[uix1] do 3173 3173 if (Loc >= 0) and (Home = cix) then 3174 3174 if SaveUnits then 3175 3175 begin // support units by nearest other city 3176 3176 nearest := -1; 3177 for cix1 := 0 to RW[ p].nCity - 1 do3178 if (cix1 <> cix) and (RW[ p].City[cix1].Loc >= 0) and3179 ((nearest < 0) or (Distance(RW[ p].City[cix1].Loc, Loc) <3180 Distance(RW[ p].City[nearest].Loc, Loc))) then3177 for cix1 := 0 to RW[P].nCity - 1 do 3178 if (cix1 <> cix) and (RW[P].City[cix1].Loc >= 0) and 3179 ((nearest < 0) or (Distance(RW[P].City[cix1].Loc, Loc) < 3180 Distance(RW[P].City[nearest].Loc, Loc))) then 3181 3181 nearest := cix1; 3182 3182 Home := nearest; 3183 3183 end 3184 3184 else 3185 RemoveUnit( p, uix1); // destroy supported units3186 end; 3187 3188 procedure DestroyCity( p, cix: integer; SaveUnits: boolean);3189 var 3190 i, V21: integer;3185 RemoveUnit(P, uix1); // destroy supported units 3186 end; 3187 3188 procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean); 3189 var 3190 I, V21: Integer; 3191 3191 Radius: TVicinity21Loc; 3192 3192 begin 3193 StealCity( p, cix, SaveUnits);3194 with RW[ p].City[cix] do begin3195 for i:= 0 to nWonder - 1 do3196 if Built[ i] > 0 then3197 GWonder[ i].CityID := WonderDestroyed;3193 StealCity(P, cix, SaveUnits); 3194 with RW[P].City[cix] do begin 3195 for I := 0 to nWonder - 1 do 3196 if Built[I] > 0 then 3197 GWonder[I].CityID := WonderDestroyed; 3198 3198 V21_to_Loc(Loc, Radius); 3199 3199 for V21 := 1 to 26 do … … 3201 3201 UsedByCity[Radius[V21]] := -1; 3202 3202 RealMap[Loc] := RealMap[Loc] and not fCity; 3203 Loc := -1 3204 end; 3205 end; 3206 3207 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);3208 var 3209 i, j, cix1, Loc1, V21: integer;3203 Loc := -1; 3204 end; 3205 end; 3206 3207 procedure ChangeCityOwner(pOld, cixOld, pNew: Integer); 3208 var 3209 I, J, cix1, Loc1, V21: Integer; 3210 3210 Radius: TVicinity21Loc; 3211 3211 begin 3212 inc(RW[pNew].nCity);3212 Inc(RW[pNew].nCity); 3213 3213 RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld]; 3214 StealCity(pOld, cixOld, false);3214 StealCity(pOld, cixOld, False); 3215 3215 RW[pOld].City[cixOld].Loc := -1; 3216 3216 with RW[pNew].City[(RW[pNew].nCity - 1)] do … … 3231 3231 begin 3232 3232 Loc1 := Radius[V21]; 3233 assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));3233 Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc)); 3234 3234 if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and 3235 3235 (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then … … 3243 3243 Built[imTownHall] := 0; 3244 3244 Built[imCourt] := 0; 3245 for i:= nWonder to nImp - 1 do3246 if Imp[ i].Kind <> ikCommon then3247 Built[ i] := 0; { destroy national projects }3248 for i:= 0 to nWonder - 1 do3249 if Built[ i] = 1 then3245 for I := nWonder to nImp - 1 do 3246 if Imp[I].Kind <> ikCommon then 3247 Built[I] := 0; { destroy national projects } 3248 for I := 0 to nWonder - 1 do 3249 if Built[I] = 1 then 3250 3250 begin // new wonder owner! 3251 GWonder[ i].EffectiveOwner := pNew;3252 if i= woEiffel then // reactivate expired wonders3253 begin 3254 for j:= 0 to nWonder - 1 do3255 if Imp[ j].Expiration >= 0 then3251 GWonder[I].EffectiveOwner := pNew; 3252 if I = woEiffel then // reactivate expired wonders 3253 begin 3254 for J := 0 to nWonder - 1 do 3255 if Imp[J].Expiration >= 0 then 3256 3256 for cix1 := 0 to (RW[pNew].nCity - 1) do 3257 if RW[pNew].City[cix1].Built[ j] = 1 then3258 GWonder[ j].EffectiveOwner := pNew;3257 if RW[pNew].City[cix1].Built[J] = 1 then 3258 GWonder[J].EffectiveOwner := pNew; 3259 3259 end 3260 3260 else 3261 CheckExpiration( i);3262 case iof3261 CheckExpiration(I); 3262 case I of 3263 3263 woLighthouse: 3264 3264 CheckSpecialModels(pNew, preLighthouse); … … 3274 3274 cix1 := RW[pNew].nEnemyCity - 1; 3275 3275 while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do 3276 dec(cix1);3277 assert(cix1 >= 0);3276 Dec(cix1); 3277 Assert(cix1 >= 0); 3278 3278 RW[pNew].EnemyCity[cix1].Loc := -1; 3279 3279 … … 3282 3282 end; 3283 3283 3284 procedure CompleteJob( p, Loc, Job: integer);3285 var 3286 ChangedTerrain, p1: integer;3287 begin 3288 assert(Job <> jCity);3284 procedure CompleteJob(P, Loc, Job: Integer); 3285 var 3286 ChangedTerrain, p1: Integer; 3287 begin 3288 Assert(Job <> jCity); 3289 3289 ChangedTerrain := -1; 3290 3290 case Job of … … 3328 3328 if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then 3329 3329 begin 3330 RemoveDomainUnits(dSea, p, Loc);3330 RemoveDomainUnits(dSea, P, Loc); 3331 3331 RealMap[Loc] := RealMap[Loc] and not fCanal; 3332 3332 end; … … 3340 3340 begin 3341 3341 if RealMap[Loc] and fTerImp = tiBase then 3342 RemoveDomainUnits(dAir, p, Loc);3342 RemoveDomainUnits(dAir, P, Loc); 3343 3343 RealMap[Loc] := RealMap[Loc] and not fTerImp 3344 3344 end 3345 3345 else if RealMap[Loc] and fCanal <> 0 then 3346 3346 begin 3347 RemoveDomainUnits(dSea, p, Loc);3347 RemoveDomainUnits(dSea, P, Loc); 3348 3348 RealMap[Loc] := RealMap[Loc] and not fCanal 3349 3349 end … … 3381 3381 ____________________________________________________________________ 3382 3382 } 3383 procedure GiveCivilReport( p, pAbout: integer);3384 begin 3385 with RW[ p].EnemyReport[pAbout]^ do3383 procedure GiveCivilReport(P, pAbout: Integer); 3384 begin 3385 with RW[P].EnemyReport[pAbout]^ do 3386 3386 begin 3387 3387 // general info 3388 3388 TurnOfCivilReport := LastValidStat[pAbout]; 3389 move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));3389 Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty)); 3390 3390 Government := RW[pAbout].Government; 3391 3391 Money := RW[pAbout].Money; … … 3396 3396 if ResearchDone > 100 then 3397 3397 ResearchDone := 100; 3398 move(RW[pAbout].Tech, Tech, nAdv);3399 end; 3400 end; 3401 3402 procedure GiveMilReport( p, pAbout: integer);3403 var 3404 uix, mix: integer;3405 begin 3406 with RW[ p].EnemyReport[pAbout]^ do3398 Move(RW[pAbout].Tech, Tech, nAdv); 3399 end; 3400 end; 3401 3402 procedure GiveMilReport(P, pAbout: Integer); 3403 var 3404 uix, mix: Integer; 3405 begin 3406 with RW[P].EnemyReport[pAbout]^ do 3407 3407 begin 3408 3408 TurnOfMilReport := LastValidStat[pAbout]; … … 3410 3410 for mix := 0 to RW[pAbout].nModel - 1 do 3411 3411 begin 3412 TellAboutModel( p, pAbout, mix);3412 TellAboutModel(P, pAbout, mix); 3413 3413 UnCount[mix] := 0 3414 3414 end; 3415 3415 for uix := 0 to RW[pAbout].nUn - 1 do 3416 3416 if RW[pAbout].Un[uix].Loc >= 0 then 3417 inc(UnCount[RW[pAbout].Un[uix].mix]);3418 end; 3419 end; 3420 3421 procedure ShowPrice(pSender, pTarget, Price: integer);3417 Inc(UnCount[RW[pAbout].Un[uix].mix]); 3418 end; 3419 end; 3420 3421 procedure ShowPrice(pSender, pTarget, Price: Integer); 3422 3422 begin 3423 3423 case Price and opMask of … … 3434 3434 end; 3435 3435 3436 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;3437 var 3438 i: integer;3436 function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean; 3437 var 3438 I: Integer; 3439 3439 rSender, rTarget: ^TEnemyReport; 3440 3440 begin // copy third nation civil report 3441 result := false;3441 Result := False; 3442 3442 if RW[pTarget].Treaty[pAbout] = trNoContact then 3443 3443 IntroduceEnemy(pTarget, pAbout); 3444 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3445 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3444 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3445 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3446 3446 if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then 3447 3447 begin // only if newer than current information … … 3452 3452 rTarget.ResearchTech := rSender.ResearchTech; 3453 3453 rTarget.ResearchDone := rSender.ResearchDone; 3454 result := true;3455 end; 3456 for i:= 0 to nAdv - 1 do3457 if rTarget.Tech[ i] < rSender.Tech[i] then3458 begin 3459 rTarget.Tech[ i] := rSender.Tech[i];3460 result := true;3461 end; 3462 end; 3463 3464 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;3465 var 3466 mix: integer;3454 Result := True; 3455 end; 3456 for I := 0 to nAdv - 1 do 3457 if rTarget.Tech[I] < rSender.Tech[I] then 3458 begin 3459 rTarget.Tech[I] := rSender.Tech[I]; 3460 Result := True; 3461 end; 3462 end; 3463 3464 function CopyMilReport(pSender, pTarget, pAbout: Integer): Boolean; 3465 var 3466 mix: Integer; 3467 3467 rSender, rTarget: ^TEnemyReport; 3468 3468 begin // copy third nation military report 3469 result := false;3469 Result := False; 3470 3470 if RW[pTarget].Treaty[pAbout] = trNoContact then 3471 3471 IntroduceEnemy(pTarget, pAbout); 3472 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3473 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3472 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3473 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3474 3474 if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then 3475 3475 begin // only if newer than current information 3476 3476 rTarget.TurnOfMilReport := rSender.TurnOfMilReport; 3477 3477 rTarget.nModelCounted := rSender.nModelCounted; 3478 move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);3478 Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted); 3479 3479 for mix := 0 to rTarget.nModelCounted - 1 do 3480 3480 TellAboutModel(pTarget, pAbout, mix); 3481 result := true;3482 end; 3483 end; 3484 3485 procedure CopyModel(pSender, pTarget, mix: integer);3486 var 3487 i: integer;3481 Result := True; 3482 end; 3483 end; 3484 3485 procedure CopyModel(pSender, pTarget, mix: Integer); 3486 var 3487 I: Integer; 3488 3488 miSender, miTarget: TModelInfo; 3489 ok: boolean;3489 ok: Boolean; 3490 3490 begin 3491 3491 // only if target doesn't already have a model like this 3492 3492 ok := RW[pTarget].nModel < nmmax; 3493 3493 MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender); 3494 for i:= 0 to RW[pTarget].nModel - 1 do3495 begin 3496 MakeModelInfo(pTarget, i, RW[pTarget].Model[i], miTarget);3494 for I := 0 to RW[pTarget].nModel - 1 do 3495 begin 3496 MakeModelInfo(pTarget, I, RW[pTarget].Model[I], miTarget); 3497 3497 if IsSameModel(miSender, miTarget) then 3498 ok := false;3498 ok := False; 3499 3499 end; 3500 3500 if ok then … … 3511 3511 Lost := 0; 3512 3512 end; 3513 inc(RW[pTarget].nModel);3514 inc(Researched[pTarget]);3513 Inc(RW[pTarget].nModel); 3514 Inc(Researched[pTarget]); 3515 3515 TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1); 3516 3516 end; 3517 3517 end; 3518 3518 3519 procedure CopyMap(pSender, pTarget: integer);3520 var 3521 Loc, i, cix: integer;3519 procedure CopyMap(pSender, pTarget: Integer); 3520 var 3521 Loc, I, cix: Integer; 3522 3522 Tile: Cardinal; 3523 3523 begin … … 3529 3529 if Tile and fCity <> 0 then 3530 3530 begin 3531 i:= 0;3532 while ( i< RW[pTarget].nEnemyCity) and3533 (RW[pTarget].EnemyCity[ i].Loc <> Loc) do3534 inc(i);3535 if i= RW[pTarget].nEnemyCity then3536 begin 3537 inc(RW[pTarget].nEnemyCity);3538 assert(RW[pTarget].nEnemyCity < necmax);3539 RW[pTarget].EnemyCity[ i].Status := 0;3540 RW[pTarget].EnemyCity[ i].SavedStatus := 0;3531 I := 0; 3532 while (I < RW[pTarget].nEnemyCity) and 3533 (RW[pTarget].EnemyCity[I].Loc <> Loc) do 3534 Inc(I); 3535 if I = RW[pTarget].nEnemyCity then 3536 begin 3537 Inc(RW[pTarget].nEnemyCity); 3538 Assert(RW[pTarget].nEnemyCity < necmax); 3539 RW[pTarget].EnemyCity[I].Status := 0; 3540 RW[pTarget].EnemyCity[I].SavedStatus := 0; 3541 3541 end; 3542 3542 if Tile and fOwned <> 0 then … … 3544 3544 cix := RW[pSender].nCity - 1; 3545 3545 while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do 3546 dec(cix);3547 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[ i]);3546 Dec(cix); 3547 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]); 3548 3548 end 3549 3549 else // city not owned by sender -- copy old info … … 3551 3551 cix := RW[pSender].nEnemyCity - 1; 3552 3552 while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do 3553 dec(cix);3554 RW[pTarget].EnemyCity[ i] := RW[pSender].EnemyCity[cix];3553 Dec(cix); 3554 RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix]; 3555 3555 end; 3556 3556 end … … 3566 3566 3567 3567 if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then 3568 inc(Discovered[pTarget]);3568 Inc(Discovered[pTarget]); 3569 3569 RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC 3570 3570 // always preserve this flag! … … 3582 3582 end; 3583 3583 3584 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;3585 var 3586 pSubject, i, n, NewTreaty: integer;3587 begin 3588 result := true;3584 function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean; 3585 var 3586 pSubject, I, N, NewTreaty: Integer; 3587 begin 3588 Result := True; 3589 3589 case Price and opMask of 3590 3590 opCivilReport: // + turn + concerned player shl 16 … … 3592 3592 pSubject := Price shr 16 and $F; 3593 3593 if pTarget = pSubject then 3594 result := false3594 Result := False 3595 3595 else if pSender = pSubject then 3596 3596 begin … … 3599 3599 end 3600 3600 else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then 3601 result := false3601 Result := False 3602 3602 else if execute then 3603 3603 CopyCivilReport(pSender, pTarget, pSubject); … … 3607 3607 pSubject := Price shr 16 and $F; 3608 3608 if pTarget = pSubject then 3609 result := false3609 Result := False 3610 3610 else if pSender = pSubject then 3611 3611 begin … … 3614 3614 end 3615 3615 else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then 3616 result := false3616 Result := False 3617 3617 else if execute then 3618 3618 CopyMilReport(pSender, pTarget, pSubject); … … 3629 3629 begin // agreed treaty end 3630 3630 if execute then 3631 CancelTreaty(pSender, pTarget, false);3631 CancelTreaty(pSender, pTarget, False); 3632 3632 end 3633 3633 else … … 3640 3640 NewTreaty := trPeace; 3641 3641 if NewTreaty < 0 then 3642 result := false3642 Result := False 3643 3643 else if execute then 3644 3644 begin 3645 assert(NewTreaty > RW[pSender].Treaty[pTarget]);3645 Assert(NewTreaty > RW[pSender].Treaty[pTarget]); 3646 3646 RW[pSender].Treaty[pTarget] := NewTreaty; 3647 3647 RW[pTarget].Treaty[pSender] := NewTreaty; … … 3672 3672 opShipParts: // + number + part type shl 16 3673 3673 begin 3674 n:= Price and $FFFF; // number3675 i:= Price shr 16 and $F; // type3676 if ( i < nShipPart) and (GShip[pSender].Parts[i] >= n) then3674 N := Price and $FFFF; // number 3675 I := Price shr 16 and $F; // type 3676 if (I < nShipPart) and (GShip[pSender].Parts[I] >= N) then 3677 3677 begin 3678 3678 if execute then 3679 3679 begin 3680 dec(GShip[pSender].Parts[i], n);3681 RW[pSender].Ship[pSender].Parts[ i] := GShip[pSender].Parts[i];3682 RW[pTarget].Ship[pSender].Parts[ i] := GShip[pSender].Parts[i];3680 Dec(GShip[pSender].Parts[I], N); 3681 RW[pSender].Ship[pSender].Parts[I] := GShip[pSender].Parts[I]; 3682 RW[pTarget].Ship[pSender].Parts[I] := GShip[pSender].Parts[I]; 3683 3683 if RW[pTarget].NatBuilt[imSpacePort] > 0 then 3684 3684 begin // space ship control requires space port 3685 inc(GShip[pTarget].Parts[i], n);3686 RW[pSender].Ship[pTarget].Parts[ i] := GShip[pTarget].Parts[i];3687 RW[pTarget].Ship[pTarget].Parts[ i] := GShip[pTarget].Parts[i];3685 Inc(GShip[pTarget].Parts[I], N); 3686 RW[pSender].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I]; 3687 RW[pTarget].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I]; 3688 3688 end; 3689 3689 end; 3690 3690 end 3691 3691 else 3692 result := false;3692 Result := False; 3693 3693 end; 3694 3694 opMoney: // + value … … 3698 3698 if execute then 3699 3699 begin 3700 dec(RW[pSender].Money, Price - opMoney);3701 inc(RW[pTarget].Money, Price - opMoney);3700 Dec(RW[pSender].Money, Price - opMoney); 3701 Inc(RW[pTarget].Money, Price - opMoney); 3702 3702 end; 3703 3703 end 3704 3704 else 3705 result := false;3705 Result := False; 3706 3706 opTribute: // + value 3707 3707 if execute then … … 3718 3718 end 3719 3719 else 3720 result := false;3720 Result := False; 3721 3721 opAllTech: 3722 3722 if execute then 3723 for i:= 0 to nAdv - 1 do3724 if (RW[pSender].Tech[ i] >= tsApplicable) and3725 (RW[pTarget].Tech[ i] = tsNA) then3723 for I := 0 to nAdv - 1 do 3724 if (RW[pSender].Tech[I] >= tsApplicable) and 3725 (RW[pTarget].Tech[I] = tsNA) then 3726 3726 begin 3727 SeeTech(pTarget, i);3728 RW[pSender].EnemyReport[pTarget].Tech[ i] := tsSeen;3729 RW[pTarget].EnemyReport[pSender].Tech[ i] := tsApplicable;3727 SeeTech(pTarget, I); 3728 RW[pSender].EnemyReport[pTarget].Tech[I] := tsSeen; 3729 RW[pTarget].EnemyReport[pSender].Tech[I] := tsApplicable; 3730 3730 end; 3731 3731 opModel: // + model index … … 3736 3736 end 3737 3737 else 3738 result := false;3738 Result := False; 3739 3739 opAllModel: 3740 3740 if execute then 3741 for i:= 0 to RW[pSender].nModel - 1 do3742 begin 3743 TellAboutModel(pTarget, pSender, i);3744 CopyModel(pSender, pTarget, i);3741 for I := 0 to RW[pSender].nModel - 1 do 3742 begin 3743 TellAboutModel(pTarget, pSender, I); 3744 CopyModel(pSender, pTarget, I); 3745 3745 end; 3746 3746 { opCity: // + city ID 3747 3747 begin 3748 result:=false3748 Result:=False 3749 3749 end; } 3750 3750 end; 3751 3751 end; 3752 3752 3753 procedure CancelTreaty( p, pWith: integer; DecreaseCredibility: boolean);3753 procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean); 3754 3754 // side effect: PeaceEnded := bitarray of players with which peace treaty was canceled 3755 3755 var 3756 p1, OldTreaty: integer;3757 begin 3758 OldTreaty := RW[ p].Treaty[pWith];3756 p1, OldTreaty: Integer; 3757 begin 3758 OldTreaty := RW[P].Treaty[pWith]; 3759 3759 PeaceEnded := 0; 3760 3760 if OldTreaty >= trPeace then 3761 RW[ p].LastCancelTreaty[pWith] := GTurn;3761 RW[P].LastCancelTreaty[pWith] := GTurn; 3762 3762 if DecreaseCredibility then 3763 3763 begin … … 3765 3765 trPeace: 3766 3766 begin 3767 RW[ p].Credibility := RW[p].Credibility shr 1;3768 if RW[ p].MaxCredibility > 0 then3769 dec(RW[p].MaxCredibility, 10);3770 if RW[ p].Credibility > RW[p].MaxCredibility then3771 RW[ p].Credibility := RW[p].MaxCredibility;3767 RW[P].Credibility := RW[P].Credibility shr 1; 3768 if RW[P].MaxCredibility > 0 then 3769 Dec(RW[P].MaxCredibility, 10); 3770 if RW[P].Credibility > RW[P].MaxCredibility then 3771 RW[P].Credibility := RW[P].MaxCredibility; 3772 3772 end; 3773 3773 trAlliance: 3774 RW[ p].Credibility := RW[p].Credibility * 3 div 4;3775 end; 3776 RW[pWith].EnemyReport[ p].Credibility := RW[p].Credibility;3774 RW[P].Credibility := RW[P].Credibility * 3 div 4; 3775 end; 3776 RW[pWith].EnemyReport[P].Credibility := RW[P].Credibility; 3777 3777 end; 3778 3778 … … 3780 3780 begin 3781 3781 for p1 := 0 to nPl - 1 do 3782 if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and3783 (RW[pWith].Treaty[p1] = trAlliance) and (RW[ p].Treaty[p1] >= trPeace)3782 if (p1 = pWith) or DecreaseCredibility and (p1 <> P) and 3783 (RW[pWith].Treaty[p1] = trAlliance) and (RW[P].Treaty[p1] >= trPeace) 3784 3784 then 3785 3785 begin 3786 RW[ p].Treaty[p1] := trNone;3787 RW[p1].Treaty[ p] := trNone;3788 RW[ p].EvaStart[p1] := -PeaceEvaTurns - 1;3789 RW[p1].EvaStart[ p] := -PeaceEvaTurns - 1;3790 inc(PeaceEnded, 1 shl p1);3786 RW[P].Treaty[p1] := trNone; 3787 RW[p1].Treaty[P] := trNone; 3788 RW[P].EvaStart[p1] := -PeaceEvaTurns - 1; 3789 RW[p1].EvaStart[P] := -PeaceEvaTurns - 1; 3790 Inc(PeaceEnded, 1 shl p1); 3791 3791 end; 3792 3792 CheckBorders(-1); 3793 3793 if (Mode > moLoading_Fast) and (PeaceEnded > 0) then 3794 RecalcMapZoC( p);3794 RecalcMapZoC(P); 3795 3795 end 3796 3796 else 3797 3797 begin 3798 RW[ p].Treaty[pWith] := OldTreaty - 1;3799 RW[pWith].Treaty[ p] := OldTreaty - 1;3798 RW[P].Treaty[pWith] := OldTreaty - 1; 3799 RW[pWith].Treaty[P] := OldTreaty - 1; 3800 3800 if OldTreaty = TrFriendlyContact then 3801 3801 begin // necessary for loading 3802 GiveCivilReport( p, pWith);3803 GiveCivilReport(pWith, p);3802 GiveCivilReport(P, pWith); 3803 GiveCivilReport(pWith, P); 3804 3804 end 3805 3805 else if OldTreaty = trAlliance then 3806 3806 begin // necessary for loading 3807 GiveMilReport( p, pWith);3808 GiveMilReport(pWith, p);3807 GiveMilReport(P, pWith); 3808 GiveMilReport(pWith, P); 3809 3809 end; 3810 3810 if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then 3811 3811 begin 3812 RecalcMapZoC( p);3812 RecalcMapZoC(P); 3813 3813 RecalcMapZoC(pWith); 3814 3814 end; … … 3816 3816 if OldTreaty in [trPeace, trAlliance] then 3817 3817 begin 3818 RecalcPeaceMap( p);3818 RecalcPeaceMap(P); 3819 3819 RecalcPeaceMap(pWith); 3820 3820 end; 3821 3821 end; 3822 3822 3823 function DoSpyMission( p, pCity, cix, Mission: integer): Cardinal;3824 var 3825 p1: integer;3826 begin 3827 result := 0;3823 function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal; 3824 var 3825 p1: Integer; 3826 begin 3827 Result := 0; 3828 3828 case Mission of 3829 3829 smSabotageProd: … … 3832 3832 smStealMap: 3833 3833 begin 3834 CopyMap(pCity, p);3835 RecalcPeaceMap( p);3834 CopyMap(pCity, P); 3835 RecalcPeaceMap(P); 3836 3836 end; 3837 3837 smStealCivilReport: 3838 3838 begin 3839 if RW[ p].Treaty[pCity] = trNoContact then3840 IntroduceEnemy( p, pCity);3841 GiveCivilReport( p, pCity);3839 if RW[P].Treaty[pCity] = trNoContact then 3840 IntroduceEnemy(P, pCity); 3841 GiveCivilReport(P, pCity); 3842 3842 end; 3843 3843 smStealMilReport: 3844 3844 begin 3845 if RW[ p].Treaty[pCity] = trNoContact then3846 IntroduceEnemy( p, pCity);3847 GiveMilReport( p, pCity);3845 if RW[P].Treaty[pCity] = trNoContact then 3846 IntroduceEnemy(P, pCity); 3847 GiveMilReport(P, pCity); 3848 3848 end; 3849 3849 smStealForeignReports: 3850 3850 begin 3851 3851 for p1 := 0 to nPl - 1 do 3852 if (p1 <> p) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)3852 if (p1 <> P) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil) 3853 3853 then 3854 3854 begin 3855 3855 if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then 3856 if CopyCivilReport(pCity, p, p1) then3857 result := result or (1 shl (2 * p1));3856 if CopyCivilReport(pCity, P, p1) then 3857 Result := Result or (1 shl (2 * p1)); 3858 3858 if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then 3859 if CopyMilReport(pCity, p, p1) then3860 result := result or (2 shl (2 * p1));3859 if CopyMilReport(pCity, P, p1) then 3860 Result := Result or (2 shl (2 * p1)); 3861 3861 end; 3862 3862 end; … … 3868 3868 ____________________________________________________________________ 3869 3869 } 3870 procedure ClearTestFlags(ClearFlags: integer);3871 var 3872 p1: integer;3870 procedure ClearTestFlags(ClearFlags: Integer); 3871 var 3872 p1: Integer; 3873 3873 begin 3874 3874 GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or … … 3879 3879 end; 3880 3880 3881 procedure SetTestFlags( p, SetFlags: integer);3882 var 3883 i, p1, p2, MoreFlags: integer;3881 procedure SetTestFlags(P, SetFlags: Integer); 3882 var 3883 I, p1, p2, MoreFlags: Integer; 3884 3884 begin 3885 3885 MoreFlags := SetFlags and not GTestFlags; … … 3905 3905 if 1 shl p1 and GAlive <> 0 then 3906 3906 begin 3907 for i:= 0 to nAdv - 1 do // give all techs to player p13908 if not( i in FutureTech) and (RW[p1].Tech[i] < tsApplicable) then3907 for I := 0 to nAdv - 1 do // give all techs to player p1 3908 if not(I in FutureTech) and (RW[p1].Tech[I] < tsApplicable) then 3909 3909 begin 3910 RW[p1].Tech[ i] := tsCheat;3911 CheckSpecialModels(p1, i);3910 RW[p1].Tech[I] := tsCheat; 3911 CheckSpecialModels(p1, I); 3912 3912 end; 3913 3913 for p2 := 0 to nPl - 1 do 3914 3914 if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then 3915 for i:= 1 to 3 do3916 if RW[p2].EnemyReport[p1].Tech[AgePreq[ i]] < tsApplicable then3917 RW[p2].EnemyReport[p1].Tech[AgePreq[ i]] := tsCheat;3915 for I := 1 to 3 do 3916 if RW[p2].EnemyReport[p1].Tech[AgePreq[I]] < tsApplicable then 3917 RW[p2].EnemyReport[p1].Tech[AgePreq[I]] := tsCheat; 3918 3918 end; 3919 3919 end; … … 3921 3921 if MoreFlags and tfUncover <> 0 then 3922 3922 begin 3923 DiscoverAll( p, lObserveSuper);3923 DiscoverAll(P, lObserveSuper); 3924 3924 for p1 := 0 to nPl - 1 do 3925 3925 if 1 shl p1 and GAlive <> 0 then 3926 3926 begin 3927 3927 ResourceMask[p1] := $FFFFFFFF; 3928 if p1 <> pthen3929 begin 3930 GiveCivilReport( p, p1);3931 GiveMilReport( p, p1);3928 if p1 <> P then 3929 begin 3930 GiveCivilReport(P, p1); 3931 GiveMilReport(P, p1); 3932 3932 end; 3933 3933 end; … … 3939 3939 ____________________________________________________________________ 3940 3940 } 3941 procedure IntServer(Command, Player, Subject: integer; var Data);3942 var 3943 i, p1: integer;3941 procedure IntServer(Command, Player, Subject: Integer; var Data); 3942 var 3943 I, p1: Integer; 3944 3944 begin 3945 3945 if Mode = moPlaying then … … 3951 3951 begin 3952 3952 {$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutNation P%d+P%d', [Player, Subject]); {$ENDIF} 3953 assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and3953 Assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and 3954 3954 (Subject < nPl)); 3955 3955 IntroduceEnemy(Player, Subject); … … 3959 3959 begin 3960 3960 {$IFDEF TEXTLOG}CmdInfo := Format('IntHaveContact P%d+P%d', [Player, Subject]); {$ENDIF} 3961 assert(RW[Player].Treaty[Subject] > trNoContact);3961 Assert(RW[Player].Treaty[Subject] > trNoContact); 3962 3962 RW[Player].EnemyReport[Subject].TurnOfContact := GTurn; 3963 3963 RW[Subject].EnemyReport[Player].TurnOfContact := GTurn; … … 3981 3981 p1 := (Command - sIntTellAboutModel) shr 4; // told player 3982 3982 {$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutModel P%d about P%d Mod%d', [p1, Player, Subject]); {$ENDIF} 3983 assert((Player >= 0) and (Player < nPl));3984 assert((Subject >= 0) and (Subject < RW[Player].nModel));3983 Assert((Player >= 0) and (Player < nPl)); 3984 Assert((Subject >= 0) and (Subject < RW[Player].nModel)); 3985 3985 MakeModelInfo(Player, Subject, RW[Player].Model[Subject], 3986 3986 RW[p1].EnemyModel[RW[p1].nEnemyModel]); 3987 3987 RWemix[p1, Player, Subject] := RW[p1].nEnemyModel; 3988 inc(RW[p1].nEnemyModel);3989 assert(RW[p1].nEnemyModel < nemmax);3988 Inc(RW[p1].nEnemyModel); 3989 Assert(RW[p1].nEnemyModel < nemmax); 3990 3990 end; 3991 3991 3992 3992 sIntDiscoverZOC: 3993 3993 begin 3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, integer(Data)]); {$ENDIF}3995 Discover9( integer(Data), Player, lObserveUnhidden, true, false);3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, Integer(Data)]); {$ENDIF} 3995 Discover9(Integer(Data), Player, lObserveUnhidden, True, False); 3996 3996 end; 3997 3997 … … 4000 4000 begin 4001 4001 {$IFDEF TEXTLOG}CmdInfo := Format('IntExpandTerritory P%d Loc%d', [Player, RW[Player].City[Subject].Loc]); {$ENDIF} 4002 move(Data, BorderChanges, SizeOf(BorderChanges));4002 Move(Data, BorderChanges, SizeOf(BorderChanges)); 4003 4003 ExpandTerritory(RW[Player].City[Subject].Loc); 4004 4004 end; … … 4007 4007 with RW[Player].City[Subject] do 4008 4008 begin 4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, integer(Data)]); {$ENDIF}4010 dec(RW[Player].Money, integer(Data));4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, Integer(Data)]); {$ENDIF} 4010 Dec(RW[Player].Money, Integer(Data)); 4011 4011 if (GWonder[woMich].EffectiveOwner = Player) and (Project and cpImp <> 0) 4012 4012 then 4013 inc(Prod, integer(Data) div 2)4013 Inc(Prod, Integer(Data) div 2) 4014 4014 else 4015 inc(Prod, integer(Data) div 4);4015 Inc(Prod, Integer(Data) div 4); 4016 4016 if Project0 and not cpAuto <> Project and not cpAuto then 4017 4017 Project0 := Project; … … 4022 4022 begin 4023 4023 {$IFDEF TEXTLOG}CmdInfo := Format('IntPayPrices P%d+P%d', [Player, Subject]); {$ENDIF} 4024 for i:= 0 to TOffer(Data).nDeliver - 1 do4025 PayPrice(Player, Subject, TOffer(Data).Price[ i], true);4026 for i:= 0 to TOffer(Data).nCost - 1 do4024 for I := 0 to TOffer(Data).nDeliver - 1 do 4025 PayPrice(Player, Subject, TOffer(Data).Price[I], True); 4026 for I := 0 to TOffer(Data).nCost - 1 do 4027 4027 PayPrice(Subject, Player, TOffer(Data).Price[TOffer(Data).nDeliver 4028 + i], true);4029 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do4030 if TOffer(Data).Price[ i] = opTreaty + trAlliance then4028 + I], True); 4029 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 4030 if TOffer(Data).Price[I] = opTreaty + trAlliance then 4031 4031 begin // add view area of allied player 4032 4032 DiscoverViewAreas(Player); … … 4045 4045 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetModelStatus P%d', [Player]); 4046 4046 {$ENDIF} 4047 RW[Player].Model[Subject].Status := integer(Data);4047 RW[Player].Model[Subject].Status := Integer(Data); 4048 4048 end; 4049 4049 … … 4053 4053 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetUnitStatus P%d', [Player]); 4054 4054 {$ENDIF} 4055 RW[Player].Un[Subject].Status := integer(Data);4055 RW[Player].Un[Subject].Status := Integer(Data); 4056 4056 end; 4057 4057 … … 4061 4061 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetCityStatus P%d', [Player]); 4062 4062 {$ENDIF} 4063 RW[Player].City[Subject].Status := integer(Data);4063 RW[Player].City[Subject].Status := Integer(Data); 4064 4064 end; 4065 4065 … … 4069 4069 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetECityStatus P%d', [Player]); 4070 4070 {$ENDIF} 4071 RW[Player].EnemyCity[Subject].Status := integer(Data);4071 RW[Player].EnemyCity[Subject].Status := Integer(Data); 4072 4072 end; 4073 4073 end; -
trunk/Direct.pas
r423 r447 29 29 Gone: Boolean; 30 30 Quick: Boolean; 31 procedure SetInfo( x: string);32 procedure SetState( x: integer);31 procedure SetInfo(X: string); 32 procedure SetState(X: Integer); 33 33 procedure OnGo(var Msg: TMessage); message WM_GO; 34 34 procedure OnChangeClient(var Msg: TMessage); message WM_CHANGECLIENT; … … 57 57 // hMem: Cardinal; 58 58 // p: pointer; 59 s: string;59 S: string; 60 60 Begin 61 61 case ID of … … 72 72 if visible then 73 73 begin 74 s:= Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]);75 while BiColorTextWidth(Canvas, s) + 64 > ClientWidth do76 Delete( s, Length(s), 1);77 SetInfo( s);74 S := Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]); 75 while BiColorTextWidth(Canvas, S) + 64 > ClientWidth do 76 Delete(S, Length(S), 1); 77 SetInfo(S); 78 78 end; 79 79 ntCreateWorld: … … 111 111 hMem := GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE, 112 112 Length(NotifyMessage)); 113 p:= GlobalLock(hMem);114 if p<> nil then115 move(NotifyMessage[1], p^, Length(NotifyMessage));113 P := GlobalLock(hMem); 114 if P <> nil then 115 Move(NotifyMessage[1], P^, Length(NotifyMessage)); 116 116 GlobalUnlock(hMem); 117 117 SetClipboardData(CF_TEXT, hMem); … … 198 198 begin 199 199 PostMessage(Handle, WM_GO, 0, 0); 200 Gone := true;200 Gone := True; 201 201 end; 202 202 end; … … 209 209 procedure TDirectDlg.OnGo(var Msg: TMessage); 210 210 var 211 i: integer;212 s: string;211 I: Integer; 212 S: string; 213 213 FileName: string; 214 214 begin … … 220 220 Exit; 221 221 end; 222 Quick := false;222 Quick := False; 223 223 if ParamCount > 0 then 224 224 begin 225 s:= ParamStr(1);226 if ( s[1] = '-') {$IFDEF WINDOWS}or (s[1] = '/'){$ENDIF} then225 S := ParamStr(1); 226 if (S[1] = '-') {$IFDEF WINDOWS}or (S[1] = '/'){$ENDIF} then 227 227 begin // special mode 228 Delete( s, 1, 1);229 for i := 1 to Length(s) do230 if s[i] in ['a' .. 'z'] then231 dec(s[i], 32);232 if s= 'MAN' then228 Delete(S, 1, 1); 229 for I := 1 to Length(S) do 230 if S[I] in ['a' .. 'z'] then 231 Dec(S[I], 32); 232 if S = 'MAN' then 233 233 begin 234 Quick := true;234 Quick := True; 235 235 DirectHelp(cHelpOnly); 236 236 Close; … … 242 242 Quick := True; 243 243 if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1) 244 ), -1, false) then begin244 ), -1, False) then begin 245 245 SimpleMessage(Phrases.Lookup('LOADERR')); 246 246 Close; … … 297 297 end; 298 298 299 procedure TDirectDlg.SetInfo( x: string);300 begin 301 Info := x;299 procedure TDirectDlg.SetInfo(X: string); 300 begin 301 Info := X; 302 302 Invalidate; 303 303 Update; … … 307 307 end; 308 308 309 procedure TDirectDlg.SetState( x: integer);310 begin 311 if ( x< 0) <> (State < 0) then begin312 State := x;309 procedure TDirectDlg.SetState(X: Integer); 310 begin 311 if (X < 0) <> (State < 0) then begin 312 State := X; 313 313 Invalidate; 314 314 Update; 315 315 end 316 else if x<> State then begin317 State := x;316 else if X <> State then begin 317 State := X; 318 318 PaintProgressBar(Canvas, 6, ClientWidth div 2 - 64, 40, State, 128 - State, 319 319 128, MainTexture); -
trunk/GameServer.pas
r442 r447 49 49 // PARAMETERS 50 50 PlayersBrain: TBrains; { brain of the players view } 51 Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty;51 Difficulty: array [0 .. nPl - 1] of Integer absolute Database.Difficulty; 52 52 { difficulty } 53 53 … … 70 70 71 71 procedure StartNewGame(const Path, FileName, Map: string; 72 Newlx, Newly, NewLandMass, NewMaxTurn: integer);73 function LoadGame(const Path, FileName: string; Turn: integer;74 MovieMode: boolean): boolean;75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);76 procedure DirectHelp(Command: integer);72 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 73 function LoadGame(const Path, FileName: string; Turn: Integer; 74 MovieMode: Boolean): Boolean; 75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer); 76 procedure DirectHelp(Command: Integer); 77 77 78 78 procedure ChangeClient; 79 79 procedure NextPlayer; 80 function PreviewMap(lm: integer): pointer;80 function PreviewMap(lm: Integer): Pointer; 81 81 82 82 … … 112 112 MapField: ^Cardinal; // predefined map 113 113 LastOffer: TOffer; 114 CCData: array [0 .. 14] of integer;114 CCData: array [0 .. 14] of Integer; 115 115 bix: TBrains; { brain of the players } 116 116 DevModelTurn: array [0 .. nPl - 1] of Integer; { turn of last call to sResetModel } 117 117 OriginalDataVersion: array [0 .. nPl - 1] of Integer; 118 118 SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal; 119 SavedData: array [0 .. nPl - 1] of pointer;119 SavedData: array [0 .. nPl - 1] of Pointer; 120 120 LogFileName: string; 121 121 SavePath: string; { name of file for saving the current game } … … 135 135 PreviewRND = 41601260; { randseed for preview map } 136 136 137 function Server(Command, Player, Subject: integer; var Data): integer;137 function Server(Command, Player, Subject: Integer; var Data): Integer; 138 138 stdcall; forward; 139 139 140 procedure CallPlayer(Command, p: integer; var Data);140 procedure CallPlayer(Command, P: Integer; var Data); 141 141 begin 142 if ((Mode <> moMovie) or ( p= 0)) then142 if ((Mode <> moMovie) or (P = 0)) then 143 143 begin 144 144 {$IFOPT O-} 145 HandoverStack[nHandoverStack] := p;145 HandoverStack[nHandoverStack] := P; 146 146 HandoverStack[nHandoverStack + 1] := Command; 147 inc(nHandoverStack, 2);148 bix[ p].Client(Command, p, Data);149 dec(nHandoverStack, 2);147 Inc(nHandoverStack, 2); 148 bix[P].Client(Command, P, Data); 149 Dec(nHandoverStack, 2); 150 150 {$ELSE} 151 151 try 152 bix[ p].Client(Command, p, Data);152 bix[P].Client(Command, P, Data); 153 153 except 154 Notify(ntException + bix[ p]);154 Notify(ntException + bix[P]); 155 155 end; 156 156 {$ENDIF} … … 167 167 end; 168 168 169 procedure CallClient(bix, Command: integer; var Data);169 procedure CallClient(bix, Command: Integer; var Data); 170 170 begin 171 171 if ((Mode <> moMovie) or (bix = Brains.IndexOf(GameServer.bix[0]))) then … … 174 174 HandoverStack[nHandoverStack] := bix; 175 175 HandoverStack[nHandoverStack + 1] := Command; 176 inc(nHandoverStack, 2);176 Inc(nHandoverStack, 2); 177 177 Brains[bix].Client(Command, -1, Data); 178 dec(nHandoverStack, 2);178 Dec(nHandoverStack, 2); 179 179 {$ELSE} 180 180 try … … 189 189 procedure Init(NotifyFunction: TNotifyFunction); 190 190 var 191 f: TSearchRec;191 F: TSearchRec; 192 192 BasePath: string; 193 193 NewBrain: TBrain; … … 195 195 begin 196 196 Notify := NotifyFunction; 197 PreviewElevation := false;197 PreviewElevation := False; 198 198 PlayersBrain := TBrains.Create(False); 199 199 PlayersBrain.Count := nPl; … … 246 246 end; 247 247 248 if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then248 if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, F) = 0 then 249 249 repeat 250 BasePath := GetAiDir + DirectorySeparator + f.Name;251 if ( f.Name <> '.') and (f.Name <> '..') and DirectoryExists(BasePath) then begin250 BasePath := GetAiDir + DirectorySeparator + F.Name; 251 if (F.Name <> '.') and (F.Name <> '..') and DirectoryExists(BasePath) then begin 252 252 NewBrain := Brains.AddNew; 253 253 NewBrain.Kind := btAI; … … 258 258 end else Brains.Delete(Brains.Count - 1); 259 259 end; 260 until FindNext( f) <> 0;260 until FindNext(F) <> 0; 261 261 FindClose(F); 262 262 … … 281 281 end; 282 282 283 function PreviewMap(lm: integer): pointer;283 function PreviewMap(lm: Integer): Pointer; 284 284 begin 285 285 lx := lxmax; … … 291 291 begin 292 292 CreateElevation; 293 PreviewElevation := true;293 PreviewElevation := True; 294 294 end; 295 CreateMap( true);295 CreateMap(True); 296 296 Result := @RealMap; 297 297 end; 298 298 299 procedure ChangeClientWhenDone(Command, Player: integer; var Data;300 DataSize: integer);299 procedure ChangeClientWhenDone(Command, Player: Integer; var Data; 300 DataSize: Integer); 301 301 begin 302 302 CCCommand := Command; 303 303 CCPlayer := Player; 304 304 if DataSize > 0 then 305 move(Data, CCData, DataSize);305 Move(Data, CCData, DataSize); 306 306 Notify(ntChangeClient); 307 307 end; 308 308 309 procedure PutMessage(Level: integer; Text: string);309 procedure PutMessage(Level: Integer; Text: string); 310 310 begin 311 bix[0].Client(cDebugMessage, Level, pchar(Text)^);311 bix[0].Client(cDebugMessage, Level, PChar(Text)^); 312 312 end; 313 313 … … 336 336 // hand over control to other client (as specified by CC...) 337 337 var 338 p: integer;338 P: Integer; 339 339 T: TDateTime; 340 340 begin … … 346 346 [CCPlayer, bix[CCPlayer].Name])); 347 347 if CCCommand = cTurn then 348 for p:= 0 to nPl - 1 do349 if ( p <> CCPlayer) and (1 shl pand GWatching <> 0) then350 CallPlayer(cShowTurnChange, p, CCPlayer);351 352 p:= CCPlayer;348 for P := 0 to nPl - 1 do 349 if (P <> CCPlayer) and (1 shl P and GWatching <> 0) then 350 CallPlayer(cShowTurnChange, P, CCPlayer); 351 352 P := CCPlayer; 353 353 CCPlayer := -1; 354 CallPlayer(CCCommand, p, CCData);355 if (Mode = moPlaying) and (bix[ p].Flags and aiThreaded = 0) and354 CallPlayer(CCCommand, P, CCData); 355 if (Mode = moPlaying) and (bix[P].Flags and aiThreaded = 0) and 356 356 (CCPlayer < 0) then 357 357 begin 358 Notify(ntDeactivationMissing, p);358 Notify(ntDeactivationMissing, P); 359 359 ForceClientDeactivation; 360 360 end; 361 361 end; 362 362 363 procedure Inform( p: integer);363 procedure Inform(P: Integer); 364 364 var 365 i, p1: integer;365 I, p1: Integer; 366 366 begin 367 RW[ p].Turn := GTurn;368 if (GTurn = MaxTurn) and ( p = pTurn) and (p= 0) then369 RW[ p].Happened := RW[p].Happened or phTimeUp;370 if (GWinner > 0) and ( p = pTurn) and (p= 0) then371 RW[ p].Happened := RW[p].Happened or phShipComplete;372 RW[ p].Alive := GAlive;373 move(GWonder, RW[p].Wonder, SizeOf(GWonder));374 move(GShip, RW[p].Ship, SizeOf(GShip));367 RW[P].Turn := GTurn; 368 if (GTurn = MaxTurn) and (P = pTurn) and (P = 0) then 369 RW[P].Happened := RW[P].Happened or phTimeUp; 370 if (GWinner > 0) and (P = pTurn) and (P = 0) then 371 RW[P].Happened := RW[P].Happened or phShipComplete; 372 RW[P].Alive := GAlive; 373 Move(GWonder, RW[P].Wonder, SizeOf(GWonder)); 374 Move(GShip, RW[P].Ship, SizeOf(GShip)); 375 375 for p1 := 0 to nPl - 1 do 376 if (p1 <> p) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then377 RW[ p].EnemyReport[p1].Credibility := RW[p1].Credibility;376 if (p1 <> P) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then 377 RW[P].EnemyReport[p1].Credibility := RW[p1].Credibility; 378 378 for p1 := 0 to nPl - 1 do 379 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then379 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 380 380 begin 381 if (GTestFlags and tfUncover <> 0) or (Difficulty[ p] = 0) or382 (RW[ p].Treaty[p1] >= trFriendlyContact) then383 GiveCivilReport( p, p1);384 if (GTestFlags and tfUncover <> 0) or (Difficulty[ p] = 0) or385 (RW[ p].Treaty[p1] = trAlliance) then386 GiveMilReport( p, p1)381 if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or 382 (RW[P].Treaty[p1] >= trFriendlyContact) then 383 GiveCivilReport(P, p1); 384 if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or 385 (RW[P].Treaty[p1] = trAlliance) then 386 GiveMilReport(P, p1) 387 387 end; 388 for i := 0 to RW[p].nEnemyModel - 1 do389 with RW[ p].EnemyModel[i] do390 Lost := Destroyed[ p, Owner, mix];388 for I := 0 to RW[P].nEnemyModel - 1 do 389 with RW[P].EnemyModel[I] do 390 Lost := Destroyed[P, Owner, mix]; 391 391 end; 392 392 393 393 procedure LogChanges; 394 394 var 395 p, ix: integer;395 P, ix: Integer; 396 396 begin 397 for p:= 0 to nPl - 1 do398 if (1 shl p and GWatching <> 0) and ProcessClientData[p] then397 for P := 0 to nPl - 1 do 398 if (1 shl P and GWatching <> 0) and ProcessClientData[P] then 399 399 begin 400 400 // log unit status changes 401 for ix := 0 to RW[ p].nUn - 1 do402 with RW[ p].Un[ix] do401 for ix := 0 to RW[P].nUn - 1 do 402 with RW[P].Un[ix] do 403 403 if (Loc >= 0) and (SavedStatus <> Status) then 404 404 begin 405 CL.Put(sIntSetUnitStatus, p, ix, @Status);405 CL.Put(sIntSetUnitStatus, P, ix, @Status); 406 406 SavedStatus := Status; 407 407 end; 408 408 // log city status changes 409 for ix := 0 to RW[ p].nCity - 1 do410 with RW[ p].City[ix] do409 for ix := 0 to RW[P].nCity - 1 do 410 with RW[P].City[ix] do 411 411 if (Loc >= 0) and (SavedStatus <> Status) then 412 412 begin 413 CL.Put(sIntSetCityStatus, p, ix, @Status);413 CL.Put(sIntSetCityStatus, P, ix, @Status); 414 414 SavedStatus := Status; 415 415 end; 416 416 // log model status changes 417 for ix := 0 to RW[ p].nModel - 1 do418 with RW[ p].Model[ix] do417 for ix := 0 to RW[P].nModel - 1 do 418 with RW[P].Model[ix] do 419 419 if SavedStatus <> Status then 420 420 begin 421 CL.Put(sIntSetModelStatus, p, ix, @Status);421 CL.Put(sIntSetModelStatus, P, ix, @Status); 422 422 SavedStatus := Status; 423 423 end; 424 424 // log enemy city status changes 425 for ix := 0 to RW[ p].nEnemyCity - 1 do426 with RW[ p].EnemyCity[ix] do425 for ix := 0 to RW[P].nEnemyCity - 1 do 426 with RW[P].EnemyCity[ix] do 427 427 if (Loc >= 0) and (SavedStatus <> Status) then 428 428 begin 429 CL.Put(sIntSetECityStatus, p, ix, @Status);429 CL.Put(sIntSetECityStatus, P, ix, @Status); 430 430 SavedStatus := Status; 431 431 end; 432 432 // log data changes 433 if bix[ p].DataSize > 0 then434 begin 435 CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data,436 bix[ p].DataSize);437 Move(RW[ p].Data^, SavedData[p]^, bix[p].DataSize * 4);433 if bix[P].DataSize > 0 then 434 begin 435 CL.PutDataChanges(sIntDataChange, P, SavedData[P], RW[P].Data, 436 bix[P].DataSize); 437 Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4); 438 438 end; 439 439 end; … … 442 442 procedure NoLogChanges; 443 443 var 444 p, ix: integer;444 P, ix: Integer; 445 445 begin 446 for p:= 0 to nPl - 1 do447 if (1 shl p and GWatching <> 0) and ProcessClientData[p] then446 for P := 0 to nPl - 1 do 447 if (1 shl P and GWatching <> 0) and ProcessClientData[P] then 448 448 begin 449 for ix := 0 to RW[ p].nUn - 1 do450 with RW[ p].Un[ix] do449 for ix := 0 to RW[P].nUn - 1 do 450 with RW[P].Un[ix] do 451 451 SavedStatus := Status; 452 for ix := 0 to RW[ p].nCity - 1 do453 with RW[ p].City[ix] do452 for ix := 0 to RW[P].nCity - 1 do 453 with RW[P].City[ix] do 454 454 SavedStatus := Status; 455 for ix := 0 to RW[ p].nModel - 1 do456 with RW[ p].Model[ix] do455 for ix := 0 to RW[P].nModel - 1 do 456 with RW[P].Model[ix] do 457 457 SavedStatus := Status; 458 for ix := 0 to RW[ p].nEnemyCity - 1 do459 with RW[ p].EnemyCity[ix] do458 for ix := 0 to RW[P].nEnemyCity - 1 do 459 with RW[P].EnemyCity[ix] do 460 460 SavedStatus := Status; 461 if bix[ p].DataSize > 0 then462 Move(RW[ p].Data^, SavedData[p]^, bix[p].DataSize * 4);461 if bix[P].DataSize > 0 then 462 Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4); 463 463 end; 464 464 end; 465 465 466 function HasChanges( p: integer): boolean;466 function HasChanges(P: Integer): Boolean; 467 467 type 468 468 TDWordList = array [0 .. INFIN] of Cardinal; 469 469 PDWortList = ^TDWordList; 470 470 var 471 ix: integer;471 ix: Integer; 472 472 begin 473 473 Result := False; 474 for ix := 0 to RW[ p].nUn - 1 do475 with RW[ p].Un[ix] do474 for ix := 0 to RW[P].nUn - 1 do 475 with RW[P].Un[ix] do 476 476 if (Loc >= 0) and (SavedStatus <> Status) then 477 477 Result := True; 478 for ix := 0 to RW[ p].nCity - 1 do479 with RW[ p].City[ix] do478 for ix := 0 to RW[P].nCity - 1 do 479 with RW[P].City[ix] do 480 480 if (Loc >= 0) and (SavedStatus <> Status) then 481 481 Result := True; 482 for ix := 0 to RW[ p].nModel - 1 do483 with RW[ p].Model[ix] do482 for ix := 0 to RW[P].nModel - 1 do 483 with RW[P].Model[ix] do 484 484 if SavedStatus <> Status then 485 485 Result := True; 486 for ix := 0 to RW[ p].nEnemyCity - 1 do487 with RW[ p].EnemyCity[ix] do486 for ix := 0 to RW[P].nEnemyCity - 1 do 487 with RW[P].EnemyCity[ix] do 488 488 if (Loc >= 0) and (SavedStatus <> Status) then 489 489 Result := True; 490 if RW[ p].Data <> nil then491 for ix := 0 to bix[ p].DataSize - 1 do492 if PDWortList(SavedData[ p])[ix] <> PDWortList(RW[p].Data)[ix] then490 if RW[P].Data <> nil then 491 for ix := 0 to bix[P].DataSize - 1 do 492 if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then 493 493 Result := True; 494 494 end; … … 498 498 InitModuleData: TInitModuleData; 499 499 begin 500 assert(bix.Kind <> btSuperVirtual);500 Assert(bix.Kind <> btSuperVirtual); 501 501 with bix do begin 502 502 if Initialized then 503 exit;503 Exit; 504 504 if Kind = btAI then 505 505 begin { get client function } … … 509 509 else 510 510 begin 511 hm := LoadLibrary( pchar(DLLName));511 hm := LoadLibrary(PChar(DLLName)); 512 512 if hm = 0 then 513 513 begin … … 525 525 if @Client <> nil then 526 526 begin 527 Initialized := true;527 Initialized := True; 528 528 InitModuleData.Server := @Server; 529 529 InitModuleData.DataVersion := 0; … … 542 542 procedure SaveMap(FileName: string); 543 543 var 544 i: integer;544 I: Integer; 545 545 MapFile: TFileStream; 546 s: string[255];546 S: string[255]; 547 547 begin 548 548 MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName, … … 550 550 try 551 551 MapFile.Position := 0; 552 s:= 'cEvoMap'#0;553 MapFile.write( s[1], 8); { file id }554 i:= 0;555 MapFile.write( i, 4); { format id }552 S := 'cEvoMap'#0; 553 MapFile.write(S[1], 8); { file id } 554 I := 0; 555 MapFile.write(I, 4); { format id } 556 556 MapFile.write(MaxTurn, 4); 557 557 MapFile.write(lx, 4); … … 563 563 end; 564 564 565 function LoadMap(FileName: string): boolean;565 function LoadMap(FileName: string): Boolean; 566 566 var 567 i, Loc1: integer;567 I, Loc1: Integer; 568 568 MapFile: TFileStream; 569 s: string[255];569 S: string[255]; 570 570 begin 571 result := false;571 Result := False; 572 572 MapFile := nil; 573 573 try 574 574 MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive); 575 575 MapFile.Position := 0; 576 MapFile.read( s[1], 8); { file id }577 MapFile.read( i, 4); { format id }578 if i= 0 then576 MapFile.read(S[1], 8); { file id } 577 MapFile.read(I, 4); { format id } 578 if I = 0 then 579 579 begin 580 MapFile.read( i, 4); // MaxTurn580 MapFile.read(I, 4); // MaxTurn 581 581 MapFile.read(lx, 4); 582 582 MapFile.read(ly, 4); … … 600 600 or fDesert; 601 601 end; 602 result := true;602 Result := True; 603 603 end; 604 604 FreeAndNil(MapFile); … … 609 609 end; 610 610 611 procedure SaveGame(FileName: string; auto: boolean);611 procedure SaveGame(FileName: string; auto: Boolean); 612 612 var 613 x, y, i, zero, Tile, nLocal: integer;613 X, Y, I, zero, Tile, nLocal: Integer; 614 614 LogFile: TFileStream; 615 s: string[255];615 S: string[255]; 616 616 SaveMap: array [0 .. lxmax * lymax - 1] of Byte; 617 617 begin 618 618 nLocal := 0; 619 for i:= 0 to nPl - 1 do620 if Assigned(bix[ i]) and (bix[i].Kind = btTerm) then621 inc(nLocal);619 for I := 0 to nPl - 1 do 620 if Assigned(bix[I]) and (bix[I].Kind = btTerm) then 621 Inc(nLocal); 622 622 if Difficulty[0] = 0 then 623 623 nLocal := 0; 624 624 if nLocal <= 1 then 625 for y:= 0 to ly - 1 do626 for x:= 0 to lx - 1 do627 begin 628 Tile := RW[0].Map[( x + SaveMapCenterLoc + lx shr 1) mod lx + lx * y];629 SaveMap[ x + lx * y] := Tile and fTerrain + Tile and625 for Y := 0 to ly - 1 do 626 for X := 0 to lx - 1 do 627 begin 628 Tile := RW[0].Map[(X + SaveMapCenterLoc + lx shr 1) mod lx + lx * Y]; 629 SaveMap[X + lx * Y] := Tile and fTerrain + Tile and 630 630 (fCity or fUnit or fOwned) shr 16; 631 631 end; … … 640 640 zero := 0; 641 641 LogFile.Position := 0; 642 s:= 'cEvoBook';643 LogFile.write( s[1], 8); { file id }644 i:= CevoVersion;645 LogFile.write( i, 4); { c-evo version }642 S := 'cEvoBook'; 643 LogFile.write(S[1], 8); { file id } 644 I := CevoVersion; 645 LogFile.write(I, 4); { c-evo version } 646 646 LogFile.write(ExeInfo.Time, 4); 647 647 LogFile.write(lx, 4); … … 656 656 if nLocal > 1 then // multiplayer game -- no quick view 657 657 begin 658 i:= $80;659 LogFile.write( i, 4);658 I := $80; 659 LogFile.write(I, 4); 660 660 end 661 661 else 662 662 LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4); 663 for i:= 0 to nPl - 1 do664 if not Assigned(bix[ i]) then663 for I := 0 to nPl - 1 do 664 if not Assigned(bix[I]) then 665 665 LogFile.write(zero, 4) 666 666 else 667 667 begin 668 if PlayersBrain[ i].Kind in [btRandom, btAI] then669 s := bix[i].FileName670 else 671 s := PlayersBrain[i].FileName;672 move(zero, s[Length(s) + 1], 4);673 LogFile.write( s, (Length(s) div 4 + 1) * 4);674 LogFile.write(OriginalDataVersion[ i], 4);675 s:= ''; { behavior }676 move(zero, s[Length(s) + 1], 4);677 LogFile.write( s, (Length(s) div 4 + 1) * 4);678 LogFile.write(Difficulty[ i], 4);668 if PlayersBrain[I].Kind in [btRandom, btAI] then 669 S := bix[I].FileName 670 else 671 S := PlayersBrain[I].FileName; 672 Move(zero, S[Length(S) + 1], 4); 673 LogFile.write(S, (Length(S) div 4 + 1) * 4); 674 LogFile.write(OriginalDataVersion[I], 4); 675 S := ''; { behavior } 676 Move(zero, S[Length(S) + 1], 4); 677 LogFile.write(S, (Length(S) div 4 + 1) * 4); 678 LogFile.write(Difficulty[I], 4); 679 679 end; 680 680 … … 687 687 begin 688 688 AutoSaveState := CL.State; 689 AutoSaveExists := true;689 AutoSaveExists := True; 690 690 end 691 691 end; … … 693 693 procedure StartGame; 694 694 var 695 i, p, p1, Human, nAlive, bixUni: integer;695 I, P, p1, Human, nAlive, bixUni: Integer; 696 696 Game: TNewGameData; 697 697 // GameEx: TNewGameExData; … … 722 722 723 723 BrainUsed := []; 724 for p:= 0 to nPl - 1 do725 if Assigned(bix[ p]) and ((Mode <> moMovie) or (p= 0)) then724 for P := 0 to nPl - 1 do 725 if Assigned(bix[P]) and ((Mode <> moMovie) or (P = 0)) then 726 726 begin { initiate selected control module } 727 AIInfo[ p] := bix[p].Name + #0;728 InitBrain(bix[ p]);727 AIInfo[P] := bix[P].Name + #0; 728 InitBrain(bix[P]); 729 729 if Mode = moPlaying then 730 730 begin // new game, this data version is original 731 OriginalDataVersion[ p] := bix[p].DataVersion;732 ProcessClientData[ p] := true;731 OriginalDataVersion[P] := bix[P].DataVersion; 732 ProcessClientData[P] := True; 733 733 end 734 734 else // loading game, compare with data version read from file 735 ProcessClientData[ p] := ProcessClientData[p] and736 (OriginalDataVersion[ p] = bix[p].DataVersion);737 if @bix[ p].Client = nil then // client function not found735 ProcessClientData[P] := ProcessClientData[P] and 736 (OriginalDataVersion[P] = bix[P].DataVersion); 737 if @bix[P].Client = nil then // client function not found 738 738 if bix[0].Kind = btNoTerm then 739 bix[ p] := nil739 bix[P] := nil 740 740 else 741 741 begin 742 bix[ p] := BrainTerm;743 OriginalDataVersion[ p] := -1;744 ProcessClientData[ p] := false;742 bix[P] := BrainTerm; 743 OriginalDataVersion[P] := -1; 744 ProcessClientData[P] := False; 745 745 end; 746 if Assigned(bix[ p]) then747 include(BrainUsed, Brains.IndexOf(bix[p]));746 if Assigned(bix[P]) then 747 Include(BrainUsed, Brains.IndexOf(bix[P])); 748 748 end; 749 749 … … 760 760 begin 761 761 if Mode <> moMovie then 762 inc(GWatching, 1 shl p1);762 Inc(GWatching, 1 shl p1); 763 763 if bix[p1].Kind = btAI then 764 inc(GAI, 1 shl p1);764 Inc(GAI, 1 shl p1); 765 765 if Difficulty[p1] > 0 then 766 766 begin 767 inc(GAlive, 1 shl p1);768 inc(nAlive);767 Inc(GAlive, 1 shl p1); 768 Inc(nAlive); 769 769 end; 770 770 ServerVersion[p1] := bix[p1].ServerVersion; … … 779 779 780 780 GTurn := 0; 781 for i:= 0 to nWonder - 1 do782 with GWonder[ i] do781 for I := 0 to nWonder - 1 do 782 with GWonder[I] do 783 783 begin 784 784 CityID := -1; … … 787 787 FillChar(GShip, SizeOf(GShip), 0); 788 788 789 for p:= 0 to nPl - 1 do790 if 1 shl pand (GAlive or GWatching) <> 0 then791 with RW[ p] do789 for P := 0 to nPl - 1 do 790 if 1 shl P and (GAlive or GWatching) <> 0 then 791 with RW[P] do 792 792 begin 793 793 Government := gDespotism; … … 799 799 AnarchyStart := -AnarchyTurns - 1; 800 800 Happened := 0; 801 LastValidStat[ p] := -1;802 Worked[ p] := 0;803 Founded[ p] := 0;804 DevModelTurn[ p] := -1;801 LastValidStat[P] := -1; 802 Worked[P] := 0; 803 Founded[P] := 0; 804 DevModelTurn[P] := -1; 805 805 OracleIncome := 0; 806 806 807 if bix[ p].DataSize > 0 then807 if bix[P].DataSize > 0 then 808 808 begin 809 GetMem(SavedData[ p], bix[p].DataSize * 4);810 GetMem(Data, bix[ p].DataSize * 4);811 FillChar(SavedData[ p]^, bix[p].DataSize * 4, 0);812 FillChar(Data^, bix[ p].DataSize * 4, 0);809 GetMem(SavedData[P], bix[P].DataSize * 4); 810 GetMem(Data, bix[P].DataSize * 4); 811 FillChar(SavedData[P]^, bix[P].DataSize * 4, 0); 812 FillChar(Data^, bix[P].DataSize * 4, 0); 813 813 end 814 814 else 815 815 begin 816 816 Data := nil; 817 SavedData[ p] := nil;817 SavedData[P] := nil; 818 818 end; 819 819 nBattleHistory := 0; … … 825 825 end 826 826 else } BorderHelper := nil; 827 for i:= 0 to nStat - 1 do828 GetMem(Stat[ i, p], 4 * (MaxTurn + 1));829 if bix[ p].Flags and fDotNet <> 0 then827 for I := 0 to nStat - 1 do 828 GetMem(Stat[I, P], 4 * (MaxTurn + 1)); 829 if bix[P].Flags and fDotNet <> 0 then 830 830 begin 831 GetMem(RW[ p].DefaultDebugMap, MapSize * 4);832 FillChar(RW[ p].DefaultDebugMap^, MapSize * 4, 0);833 DebugMap[ p] := RW[p].DefaultDebugMap;831 GetMem(RW[P].DefaultDebugMap, MapSize * 4); 832 FillChar(RW[P].DefaultDebugMap^, MapSize * 4, 0); 833 DebugMap[P] := RW[P].DefaultDebugMap; 834 834 end 835 835 else 836 RW[ p].DefaultDebugMap := nil;836 RW[P].DefaultDebugMap := nil; 837 837 838 838 { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); } … … 842 842 begin // random map 843 843 InitRandomGame; 844 PreviewElevation := false;844 PreviewElevation := False; 845 845 MapField := nil; 846 846 end … … 850 850 LoadMap(MapFileName); // new game -- load map from file 851 851 GetMem(MapField, MapSize * 4); 852 move(RealMap, MapField^, MapSize * 4);852 Move(RealMap, MapField^, MapSize * 4); 853 853 Human := 0; 854 854 for p1 := 0 to nPl - 1 do 855 855 if Assigned(bix[p1]) and (bix[p1].Kind = btTerm) then 856 inc(Human, 1 shl p1);856 Inc(Human, 1 shl p1); 857 857 InitMapGame(Human); 858 858 end; 859 859 CityProcessing.InitGame; 860 860 UnitProcessing.InitGame; 861 for p:= 0 to nPl - 1 do862 if 1 shl pand (GAlive or GWatching) <> 0 then863 Inform( p);861 for P := 0 to nPl - 1 do 862 if 1 shl P and (GAlive or GWatching) <> 0 then 863 Inform(P); 864 864 865 865 pTurn := -1; … … 870 870 Game.LandMass := LandMass; 871 871 Game.MaxTurn := MaxTurn; 872 move(Difficulty, Game.Difficulty, SizeOf(Difficulty));872 Move(Difficulty, Game.Difficulty, SizeOf(Difficulty)); 873 873 // GameEx.lx:=lx; GameEx.ly:=ly; GameEx.LandMass:=LandMass; 874 874 // GameEx.MaxTurn:=MaxTurn; GameEx.RND:=RND; 875 875 // move(Difficulty,GameEx.Difficulty,SizeOf(Difficulty)); 876 876 AICredits := ''; 877 for i:= 0 to Brains.Count - 1 do877 for I := 0 to Brains.Count - 1 do 878 878 with Brains[I] do begin 879 879 if Initialized then 880 if iin BrainUsed then880 if I in BrainUsed then 881 881 begin 882 882 if Kind = btAI then 883 883 Notify(ntInitPlayers); 884 for p:= 0 to nPl - 1 do884 for P := 0 to nPl - 1 do 885 885 begin 886 if Brains.IndexOf(bix[ p]) = ithen887 Game.RO[ p] := @RW[p]886 if Brains.IndexOf(bix[P]) = I then 887 Game.RO[P] := @RW[P] 888 888 else 889 Game.RO[ p] := nil;890 if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[ p]) then891 Game.SuperVisorRO[ p] := @RW[p]889 Game.RO[P] := nil; 890 if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[P]) then 891 Game.SuperVisorRO[P] := @RW[P] 892 892 else 893 Game.SuperVisorRO[ p] := nil;893 Game.SuperVisorRO[P] := nil; 894 894 end; 895 895 if Flags and fDotNet > 0 then 896 896 begin 897 897 Path := DLLName; 898 move(Path[1], Game.AssemblyPath, Length(Path));898 Move(Path[1], Game.AssemblyPath, Length(Path)); 899 899 Game.AssemblyPath[Length(Path)] := #0; 900 900 end … … 903 903 case Mode of 904 904 moLoading, moLoading_Fast: 905 CallClient( i, cLoadGame, Game);905 CallClient(I, cLoadGame, Game); 906 906 moMovie: 907 CallClient( i, cMovie, Game);907 CallClient(I, cMovie, Game); 908 908 moPlaying: 909 CallClient( i, cNewGame, Game);909 CallClient(I, cNewGame, Game); 910 910 end; 911 911 if (Kind = btAI) and (Credits <> '') then … … 917 917 else 918 918 begin { module no longer used -- unload } 919 CallClient( i, cReleaseModule, nil^);919 CallClient(I, cReleaseModule, nil^); 920 920 if Kind = btAI then 921 921 begin … … 924 924 Client := nil; 925 925 end; 926 Initialized := false;926 Initialized := False; 927 927 end; 928 928 end; … … 952 952 CheckBorders(-1); 953 953 {$IFOPT O-}InvalidTreatyMap := 0; {$ENDIF} 954 AutoSaveExists := false;954 AutoSaveExists := False; 955 955 pDipActive := -1; 956 956 pTurn := 0; … … 962 962 procedure EndGame; 963 963 var 964 i, p1: integer;964 I, p1: Integer; 965 965 begin 966 966 if LandMass = 0 then … … 969 969 if Assigned(bix[p1]) then 970 970 begin 971 for i:= 0 to nStat - 1 do972 FreeMem(Stat[ i, p1]);971 for I := 0 to nStat - 1 do 972 FreeMem(Stat[I, p1]); 973 973 if RW[p1].BattleHistory <> nil then 974 974 FreeMem(RW[p1].BattleHistory); … … 985 985 end; 986 986 987 procedure GenerateStat( p: integer);987 procedure GenerateStat(P: Integer); 988 988 var 989 cix, uix: integer;989 cix, uix: Integer; 990 990 begin 991 if Difficulty[ p] > 0 then992 with RW[ p] do991 if Difficulty[P] > 0 then 992 with RW[P] do 993 993 begin 994 Stat[stPop, p, GTurn] := 0;994 Stat[stPop, P, GTurn] := 0; 995 995 for cix := 0 to nCity - 1 do 996 996 if City[cix].Loc >= 0 then 997 inc(Stat[stPop, p, GTurn], City[cix].Size);998 Stat[stScience, p, GTurn] := Researched[p] * 50;999 if (RW[ p].ResearchTech >= 0) and (RW[p].ResearchTech <> adMilitary) then1000 inc(Stat[stScience, p, GTurn], Research * 100 div TechBaseCost(nTech[p],1001 Difficulty[ p]));1002 Stat[stMil, p, GTurn] := 0;997 Inc(Stat[stPop, P, GTurn], City[cix].Size); 998 Stat[stScience, P, GTurn] := Researched[P] * 50; 999 if (RW[P].ResearchTech >= 0) and (RW[P].ResearchTech <> adMilitary) then 1000 Inc(Stat[stScience, P, GTurn], Research * 100 div TechBaseCost(nTech[P], 1001 Difficulty[P])); 1002 Stat[stMil, P, GTurn] := 0; 1003 1003 for uix := 0 to nUn - 1 do 1004 1004 if Un[uix].Loc >= 0 then … … 1006 1006 begin 1007 1007 if (Kind <= mkEnemyDeveloped) and (Un[uix].mix <> 1) then 1008 inc(Stat[stMil, p, GTurn], Weight * MStrength *1008 Inc(Stat[stMil, P, GTurn], Weight * MStrength * 1009 1009 Un[uix].Health div 100) 1010 1010 else if Domain = dGround then 1011 inc(Stat[stMil, p, GTurn], (Attack + 2 * Defense) *1011 Inc(Stat[stMil, P, GTurn], (Attack + 2 * Defense) * 1012 1012 Un[uix].Health div 100) 1013 1013 else 1014 inc(Stat[stMil, p, GTurn], (Attack + Defense) *1014 Inc(Stat[stMil, P, GTurn], (Attack + Defense) * 1015 1015 Un[uix].Health div 100); 1016 1016 case Kind of 1017 1017 mkSlaves: 1018 inc(Stat[stPop, p, GTurn]);1018 Inc(Stat[stPop, P, GTurn]); 1019 1019 mkSettler: 1020 inc(Stat[stPop, p, GTurn], 2);1020 Inc(Stat[stPop, P, GTurn], 2); 1021 1021 end; 1022 1022 end; 1023 Stat[stMil, p, GTurn] := Stat[stMil, p, GTurn] div 16;1024 Stat[stExplore, p, GTurn] := Discovered[p];1025 Stat[stTerritory, p, GTurn] := TerritoryCount[p];1026 Stat[stWork, p, GTurn] := Worked[p];1027 LastValidStat[ p] := GTurn;1023 Stat[stMil, P, GTurn] := Stat[stMil, P, GTurn] div 16; 1024 Stat[stExplore, P, GTurn] := Discovered[P]; 1025 Stat[stTerritory, P, GTurn] := TerritoryCount[P]; 1026 Stat[stWork, P, GTurn] := Worked[P]; 1027 LastValidStat[P] := GTurn; 1028 1028 end; 1029 1029 end; … … 1031 1031 procedure LogCityTileChanges; 1032 1032 var 1033 cix: integer;1033 cix: Integer; 1034 1034 begin 1035 1035 for cix := 0 to RW[pTurn].nCity - 1 do … … 1052 1052 procedure NoLogCityTileChanges; 1053 1053 var 1054 cix: integer;1054 cix: Integer; 1055 1055 begin 1056 1056 for cix := 0 to RW[pTurn].nCity - 1 do … … 1063 1063 end; 1064 1064 1065 function HasCityTileChanges: boolean;1065 function HasCityTileChanges: Boolean; 1066 1066 var 1067 cix: integer;1067 cix: Integer; 1068 1068 begin 1069 result := false;1069 Result := False; 1070 1070 for cix := 0 to RW[pTurn].nCity - 1 do 1071 1071 with RW[pTurn].City[cix] do … … 1074 1074 // if SavedResourceWeights[cix]<>ResourceWeights then result:=true; 1075 1075 if SavedTiles[cix] <> Tiles then 1076 result := true;1076 Result := True; 1077 1077 end; 1078 1078 end; … … 1080 1080 procedure BeforeTurn0; 1081 1081 var 1082 p1, uix: integer;1082 p1, uix: Integer; 1083 1083 begin 1084 1084 for uix := 0 to RW[pTurn].nUn - 1 do { init movement points for first turn } … … 1101 1101 end; 1102 1102 1103 function LoadGame(const Path, FileName: string; Turn: integer;1104 MovieMode: boolean): boolean;1103 function LoadGame(const Path, FileName: string; Turn: Integer; 1104 MovieMode: Boolean): Boolean; 1105 1105 var 1106 1106 J: TBrain; 1107 i, ix, d, p1, Command, Subject: integer;1107 I, ix, D, p1, Command, Subject: Integer; 1108 1108 K: Integer; 1109 {$IFDEF TEXTLOG}LoadPos0: integer; {$ENDIF}1110 Data: pointer;1109 {$IFDEF TEXTLOG}LoadPos0: Integer; {$ENDIF} 1110 Data: Pointer; 1111 1111 LogFile: TFileStream; 1112 1112 FormerCLState: TCmdListState; 1113 s: string[255];1113 S: string[255]; 1114 1114 SaveMap: array [0 .. lxmax * lymax - 1] of Byte; 1115 Started, StatRequest: boolean;1115 Started, StatRequest: Boolean; 1116 1116 begin 1117 1117 SavePath := Path; … … 1121 1121 fmShareExclusive); 1122 1122 LogFile.Position := 0; 1123 LogFile.Read( s[1], 8); { file id }1124 LogFile.Read( i, 4); { c-evo version }1123 LogFile.Read(S[1], 8); { file id } 1124 LogFile.Read(I, 4); { c-evo version } 1125 1125 LogFile.Read(J, 4); { exe time } 1126 1126 1127 if ( i >= FirstBookCompatibleVersion) and (i<= CevoVersion) then1127 if (I >= FirstBookCompatibleVersion) and (I <= CevoVersion) then 1128 1128 begin 1129 result := true;1129 Result := True; 1130 1130 LogFile.Read(lx, 4); 1131 1131 LogFile.Read(ly, 4); … … 1142 1142 for p1 := 0 to nPl - 1 do 1143 1143 begin 1144 LogFile.Read( s[0], 4);1145 if s[0] = #0 then1144 LogFile.Read(S[0], 4); 1145 if S[0] = #0 then 1146 1146 PlayersBrain[p1] := nil 1147 1147 else 1148 1148 begin 1149 LogFile.Read( s[4], Byte(s[0]) div 4 * 4);1149 LogFile.Read(S[4], Byte(S[0]) div 4 * 4); 1150 1150 LogFile.Read(OriginalDataVersion[p1], 4); 1151 LogFile.Read( d, 4); { behavior }1151 LogFile.Read(D, 4); { behavior } 1152 1152 LogFile.Read(Difficulty[p1], 4); 1153 1153 J := Brains.Last; 1154 while Assigned(J) and (AnsiCompareFileName(J.FileName, s) <> 0) do begin1154 while Assigned(J) and (AnsiCompareFileName(J.FileName, S) <> 0) do begin 1155 1155 K := Brains.IndexOf(J) - 1; 1156 1156 if K >= 0 then J := Brains[K] … … 1159 1159 if not Assigned(J) then 1160 1160 begin // ai not found -- replace by local player 1161 ProcessClientData[p1] := false;1162 NotifyMessage := s;1161 ProcessClientData[p1] := False; 1162 NotifyMessage := S; 1163 1163 Notify(ntAIError); 1164 1164 J := BrainTerm; 1165 1165 end 1166 1166 else 1167 ProcessClientData[p1] := true;1168 if j.Kind = btNoTerm then1169 j:= BrainSuperVirtual;1167 ProcessClientData[p1] := True; 1168 if J.Kind = btNoTerm then 1169 J := BrainSuperVirtual; 1170 1170 // crashed tournament -- load as supervisor 1171 PlayersBrain[p1] := j;1171 PlayersBrain[p1] := J; 1172 1172 end; 1173 1173 end; 1174 1174 end 1175 1175 else 1176 Result := false;1176 Result := False; 1177 1177 1178 1178 if Result then begin … … 1181 1181 end; 1182 1182 FreeAndNil(LogFile); 1183 if not result then1183 if not Result then 1184 1184 Exit; 1185 1185 … … 1195 1195 {$IFDEF TEXTLOG}AssignFile(TextLog, SavePath + LogFileName + '.txt'); 1196 1196 Rewrite(TextLog); {$ENDIF} 1197 LoadOK := true;1197 LoadOK := True; 1198 1198 StartGame; 1199 1199 if MovieMode then … … 1205 1205 Notify(ntLoadBegin); 1206 1206 1207 started := false;1208 StatRequest := false;1209 MovieStopped := false;1207 started := False; 1208 StatRequest := False; 1209 MovieStopped := False; 1210 1210 {$IFDEF LOADPERF}QueryPerformanceCounter(time_total0); 1211 1211 time_a := 0; … … 1222 1222 begin 1223 1223 GenerateStat(pTurn); 1224 StatRequest := false;1224 StatRequest := False; 1225 1225 end; 1226 1226 // complete all internal commands following an sTurn before generating statistics … … 1237 1237 CallPlayer(cMovieTurn, 0, nil^); 1238 1238 end; 1239 StatRequest := true;1240 started := true;1239 StatRequest := True; 1240 started := True; 1241 1241 end 1242 1242 else if (Command = sTurn) and (pTurn = 0) and (GTurn = LoadTurn) then 1243 1243 begin 1244 assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn1244 Assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn 1245 1245 CL.State := FormerCLState; 1246 1246 CL.Cut; … … 1278 1278 EndGame; 1279 1279 Notify(ntStartGo); 1280 result := false;1281 exit;1280 Result := False; 1281 Exit; 1282 1282 end; 1283 1283 1284 1284 if StatRequest then 1285 1285 GenerateStat(pTurn); 1286 assert(started);1286 Assert(started); 1287 1287 {$IFDEF TEXTLOG}CloseFile(TextLog); {$ENDIF} 1288 1288 {$IFDEF LOADPERF}QueryPerformanceCounter(time_total); { time in s is: (time_total-time_total0)/PerfFreq }{$ENDIF} … … 1328 1328 procedure InsertTerritoryUpdateCommands; 1329 1329 var 1330 p1, Command, Subject: integer;1331 Data: pointer;1330 p1, Command, Subject: Integer; 1331 Data: Pointer; 1332 1332 FormerCLState: TCmdListState; 1333 1333 begin … … 1351 1351 1352 1352 procedure StartNewGame(const Path, FileName, Map: string; 1353 Newlx, Newly, NewLandMass, NewMaxTurn: integer);1353 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 1354 1354 var 1355 1355 I: Integer; … … 1395 1395 end; 1396 1396 1397 procedure DirectHelp(Command: integer);1397 procedure DirectHelp(Command: Integer); 1398 1398 begin 1399 1399 InitBrain(BrainTerm); … … 1402 1402 end; 1403 1403 1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer); 1405 1405 var 1406 p1, Loc1: integer;1406 p1, Loc1: Integer; 1407 1407 Game: TNewGameData; 1408 1408 begin … … 1446 1446 end; 1447 1447 1448 procedure DestroySpacePort_TellPlayers( p, pCapturer: integer);1448 procedure DestroySpacePort_TellPlayers(P, pCapturer: Integer); 1449 1449 var 1450 cix, i, p1: integer;1450 cix, I, p1: Integer; 1451 1451 ShowShipChange: TShowShipChange; 1452 1452 begin 1453 1453 // stop ship part production 1454 for cix := 0 to RW[ p].nCity - 1 do1455 with RW[ p].City[cix] do1454 for cix := 0 to RW[P].nCity - 1 do 1455 with RW[P].City[cix] do 1456 1456 if (Loc >= 0) and (Project and cpImp <> 0) and 1457 1457 ((Project and cpIndex = woMIR) or 1458 1458 (Imp[Project and cpIndex].Kind = ikShipPart)) then 1459 1459 begin 1460 inc(RW[p].Money, Prod0);1460 Inc(RW[P].Money, Prod0); 1461 1461 Prod := 0; 1462 1462 Prod0 := 0; … … 1466 1466 1467 1467 // destroy ship 1468 with GShip[ p] do1468 with GShip[P] do 1469 1469 if Parts[0] + Parts[1] + Parts[2] > 0 then 1470 1470 begin 1471 for i:= 0 to nShipPart - 1 do1472 begin 1473 ShowShipChange.Ship1Change[ i] := -Parts[i];1471 for I := 0 to nShipPart - 1 do 1472 begin 1473 ShowShipChange.Ship1Change[I] := -Parts[I]; 1474 1474 if pCapturer >= 0 then 1475 1475 begin 1476 ShowShipChange.Ship2Change[ i] := Parts[i];1477 inc(GShip[pCapturer].Parts[i], Parts[i]);1476 ShowShipChange.Ship2Change[I] := Parts[I]; 1477 Inc(GShip[pCapturer].Parts[I], Parts[I]); 1478 1478 end; 1479 Parts[ i] := 0;1479 Parts[I] := 0; 1480 1480 end; 1481 1481 if Mode >= moMovie then … … 1485 1485 else 1486 1486 ShowShipChange.Reason := scrDestruction; 1487 ShowShipChange.Ship1Owner := p;1487 ShowShipChange.Ship1Owner := P; 1488 1488 ShowShipChange.Ship2Owner := pCapturer; 1489 1489 for p1 := 0 to nPl - 1 do 1490 1490 if 1 shl p1 and (GAlive or GWatching) <> 0 then 1491 1491 begin 1492 move(GShip, RW[p1].Ship, SizeOf(GShip));1492 Move(GShip, RW[p1].Ship, SizeOf(GShip)); 1493 1493 if 1 shl p1 and GWatching <> 0 then 1494 1494 CallPlayer(cShowShipChange, p1, ShowShipChange); … … 1498 1498 end; 1499 1499 1500 procedure DestroyCity_TellPlayers( p, cix: integer; SaveUnits: boolean);1500 procedure DestroyCity_TellPlayers(P, cix: Integer; SaveUnits: Boolean); 1501 1501 begin 1502 if RW[ p].City[cix].built[imSpacePort] > 0 then1503 DestroySpacePort_TellPlayers( p, -1);1504 DestroyCity( p, cix, SaveUnits);1502 if RW[P].City[cix].built[imSpacePort] > 0 then 1503 DestroySpacePort_TellPlayers(P, -1); 1504 DestroyCity(P, cix, SaveUnits); 1505 1505 end; 1506 1506 1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: integer);1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: Integer); 1508 1508 begin 1509 1509 if RW[pOld].City[cixOld].built[imSpacePort] > 0 then … … 1515 1515 end; 1516 1516 1517 procedure CheckWin( p: integer);1517 procedure CheckWin(P: Integer); 1518 1518 var 1519 i: integer;1520 ShipComplete: boolean;1519 I: Integer; 1520 ShipComplete: Boolean; 1521 1521 begin 1522 ShipComplete := true;1523 for i:= 0 to nShipPart - 1 do1524 if GShip[ p].Parts[i] < ShipNeed[i] then1525 ShipComplete := false;1522 ShipComplete := True; 1523 for I := 0 to nShipPart - 1 do 1524 if GShip[P].Parts[I] < ShipNeed[I] then 1525 ShipComplete := False; 1526 1526 if ShipComplete then 1527 GWinner := GWinner or 1 shl p; // game won!1527 GWinner := GWinner or 1 shl P; // game won! 1528 1528 end; 1529 1529 1530 1530 procedure BeforeTurn; 1531 1531 var 1532 i, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,1533 SiegedTiles, nUpdateLoc: integer;1534 UpdateLoc: array [0 .. numax - 1] of integer;1532 I, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc, 1533 SiegedTiles, nUpdateLoc: Integer; 1534 UpdateLoc: array [0 .. numax - 1] of Integer; 1535 1535 Radius: TVicinity21Loc; 1536 1536 ShowShipChange: TShowShipChange; 1537 TribeExtinct, JobDone, MirBuilt: boolean;1537 TribeExtinct, JobDone, MirBuilt: Boolean; 1538 1538 begin 1539 {$IFOPT O-} assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}1540 assert(1 shl pTurn and (GAlive or GWatching) <> 0);1539 {$IFOPT O-}Assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF} 1540 Assert(1 shl pTurn and (GAlive or GWatching) <> 0); 1541 1541 if (1 shl pTurn and GAlive = 0) and (Difficulty[pTurn] > 0) then 1542 exit;1542 Exit; 1543 1543 1544 1544 if (GWonder[woGrLibrary].EffectiveOwner = pTurn) and (GWinner = 0) then … … 1547 1547 for p1 := 0 to nPl - 1 do 1548 1548 if 1 shl p1 and GAlive <> 0 then 1549 inc(nAlive);1549 Inc(nAlive); 1550 1550 ad := 0; 1551 1551 while ad <= (nAdv - 5) do begin … … 1556 1556 if (p1 <> pTurn) and (1 shl p1 and GAlive <> 0) and 1557 1557 (RW[p1].Tech[ad] >= tsApplicable) then 1558 inc(nAppliers);1558 Inc(nAppliers); 1559 1559 if nAppliers * 2 > nAlive then 1560 1560 begin 1561 1561 SeeTech(pTurn, ad); 1562 inc(nTech[pTurn]);1562 Inc(nTech[pTurn]); 1563 1563 if Mode >= moMovie then 1564 1564 CallPlayer(cShowGreatLibTech, pTurn, ad); … … 1577 1577 RW[pTurn].nEnemyUn := 0; 1578 1578 1579 MirBuilt := false;1579 MirBuilt := False; 1580 1580 if (Difficulty[pTurn] > 0) and (GWinner = 0) then 1581 1581 with RW[pTurn] do … … 1600 1600 begin // transport unload 1601 1601 if Model[mix].Domain = dAir then 1602 dec(Un[Master].AirLoad)1602 Dec(Un[Master].AirLoad) 1603 1603 else 1604 dec(Un[Master].TroopLoad);1604 Dec(Un[Master].TroopLoad); 1605 1605 Master := -1; 1606 1606 end … … 1622 1622 if Mode >= moMovie then 1623 1623 FillChar(ShowShipChange, SizeOf(ShowShipChange), 0); 1624 TribeExtinct := true;1624 TribeExtinct := True; 1625 1625 nUpdateLoc := 0; 1626 1626 for cix := 0 to nCity - 1 do … … 1638 1638 begin 1639 1639 Loc1 := Radius[V21]; 1640 assert((Loc1 >= 0) and (Loc1 < MapSize) and1640 Assert((Loc1 >= 0) and (Loc1 < MapSize) and 1641 1641 (UsedByCity[Loc1] = Loc)); 1642 1642 p1 := RealMap[Loc1] shr 27; … … 1649 1649 UsedByCity[Loc1] := -1; 1650 1650 Flags := Flags or chSiege; 1651 inc(SiegedTiles);1651 Inc(SiegedTiles); 1652 1652 end; 1653 1653 end; … … 1656 1656 if not AddBestCityTile(pTurn, cix) then 1657 1657 Break; 1658 dec(SiegedTiles);1658 Dec(SiegedTiles); 1659 1659 end; 1660 1660 … … 1664 1664 1665 1665 if CityTurn(pTurn, cix) then 1666 TribeExtinct := false1666 TribeExtinct := False 1667 1667 else 1668 1668 begin // city is erased … … 1671 1671 Map[Loc] := Map[Loc] and not fCity; // !!! do this in inner core 1672 1672 UpdateLoc[nUpdateLoc] := Loc; 1673 inc(nUpdateLoc);1674 DestroyCity_TellPlayers(pTurn, cix, true);1673 Inc(nUpdateLoc); 1674 DestroyCity_TellPlayers(pTurn, cix, True); 1675 1675 end; 1676 1676 … … 1679 1679 begin 1680 1680 if Project0 and cpIndex = woMIR then // MIR completed 1681 MirBuilt := true1681 MirBuilt := True 1682 1682 else if Project0 and cpIndex = woManhattan then 1683 1683 GColdWarStart := GTurn 1684 1684 else if Imp[Project0 and cpIndex].Kind = ikShipPart 1685 1685 then { ship parts produced } 1686 inc(ShowShipChange.Ship1Change[Project0 and cpIndex -1686 Inc(ShowShipChange.Ship1Change[Project0 and cpIndex - 1687 1687 imShipComp]); 1688 1688 end; … … 1692 1692 begin 1693 1693 CheckBorders(-1, pTurn); 1694 for i:= 0 to nUpdateLoc - 1 do1695 UpdateUnitMap(UpdateLoc[ i], true);1694 for I := 0 to nUpdateLoc - 1 do 1695 UpdateUnitMap(UpdateLoc[I], True); 1696 1696 if Mode >= moMovie then 1697 1697 for p1 := 0 to nPl - 1 do 1698 1698 if (1 shl p1 and GWatching <> 0) and (p1 <> pTurn) then 1699 for i:= 0 to nUpdateLoc - 1 do1700 if ObserveLevel[UpdateLoc[ i]] shr (2 * p1) and 3 >= lObserveUnhidden1699 for I := 0 to nUpdateLoc - 1 do 1700 if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden 1701 1701 then 1702 CallPlayer(cShowCityChanged, p1, UpdateLoc[ i]);1702 CallPlayer(cShowCityChanged, p1, UpdateLoc[I]); 1703 1703 end; 1704 1704 … … 1718 1718 Movement := UnitSpeed(pTurn, mix, Health); { refresh movement } 1719 1719 1720 assert(Loc >= 0);1720 Assert(Loc >= 0); 1721 1721 if Model[mix].Kind <> mkDiplomat then 1722 1722 begin // check treaty violation … … 1762 1762 begin 1763 1763 AddBestCityTile(pTurn, RW[pTurn].nCity - 1); 1764 UpdateUnitMap(Loc1, true);1764 UpdateUnitMap(Loc1, True); 1765 1765 if Mode >= moMovie then // tell enemies 1766 1766 for p1 := 0 to nPl - 1 do … … 1824 1824 DiscoverTech(pTurn, ResearchTech); 1825 1825 1826 dec(Research, Cost);1826 Dec(Research, Cost); 1827 1827 Happened := Happened or phTech; 1828 1828 ResearchTech := -1; … … 1839 1839 (Treaty[p1] >= trPeace) then 1840 1840 begin 1841 inc(Credibility);1841 Inc(Credibility); 1842 1842 Break; 1843 1843 end; … … 1856 1856 if (p1 <> pTurn) and (1 shl p1 and (GAlive or GWatching) <> 0) then 1857 1857 begin 1858 move(GShip, RW[p1].Ship, SizeOf(GShip));1858 Move(GShip, RW[p1].Ship, SizeOf(GShip)); 1859 1859 if 1 shl p1 and GWatching <> 0 then 1860 1860 CallPlayer(cShowShipChange, p1, ShowShipChange); … … 1871 1871 if (p1 <> pTurn) and ((GAlive or GWatching) and (1 shl p1) <> 0) then 1872 1872 RW[p1].EnemyReport[pTurn].Government := gDespotism; 1873 inc(Happened, phChangeGov);1873 Inc(Happened, phChangeGov); 1874 1874 end; 1875 1875 end; // if Difficulty[pTurn]>0 … … 1912 1912 procedure AfterTurn; 1913 1913 var 1914 cix, uix, p1, Loc1, Job0: integer;1915 JobDone: boolean;1914 cix, uix, p1, Loc1, Job0: Integer; 1915 JobDone: Boolean; 1916 1916 begin 1917 1917 with RW[pTurn] do … … 1925 1925 end; 1926 1926 1927 inc(Money, OracleIncome);1927 Inc(Money, OracleIncome); 1928 1928 OracleIncome := 0; 1929 1929 if GWonder[woOracle].EffectiveOwner = pTurn then … … 1935 1935 if (RW[p1].City[cix].Loc >= 0) and 1936 1936 (RW[p1].City[cix].built[imTemple] > 0) then 1937 inc(OracleIncome);1937 Inc(OracleIncome); 1938 1938 end; 1939 1939 … … 1962 1962 begin 1963 1963 AddBestCityTile(pTurn, RW[pTurn].nCity - 1); 1964 UpdateUnitMap(Loc1, true);1964 UpdateUnitMap(Loc1, True); 1965 1965 if Mode >= moMovie then // tell enemies 1966 1966 for p1 := 0 to nPl - 1 do … … 1993 1993 else 1994 1994 begin 1995 dec(Fuel);1995 Dec(Fuel); 1996 1996 if Fuel < 0 then 1997 1997 begin … … 2013 2013 Flags := Flags and not unWithdrawn; 2014 2014 if (Loc >= 0) and (Model[mix].Domain = dGround) and (Master < 0) and 2015 (( integer(Movement) = Model[mix].Speed) or2015 ((Integer(Movement) = Model[mix].Speed) or 2016 2016 (Model[mix].Cap[mcAcademy] > 0) and (Movement * 2 >= Model[mix].Speed)) 2017 2017 then … … 2049 2049 end; 2050 2050 2051 function ExecuteMove( p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;2052 ShowMove: TShowMove): integer;2051 function ExecuteMove(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo; 2052 ShowMove: TShowMove): Integer; 2053 2053 var 2054 i, p1, FromLoc, uix1, nUpdateLoc: integer;2054 I, p1, FromLoc, uix1, nUpdateLoc: Integer; 2055 2055 MinLevel, MissionResult: Cardinal; 2056 2056 PModel: ^TModel; 2057 UpdateLoc: array [0 .. numax - 1] of integer;2058 SeeFrom, SeeTo, ExtDiscover: boolean;2057 UpdateLoc: array [0 .. numax - 1] of Integer; 2058 SeeFrom, SeeTo, ExtDiscover: Boolean; 2059 2059 begin 2060 result := 0;2061 with RW[ p], Un[uix] do2060 Result := 0; 2061 with RW[P], Un[uix] do 2062 2062 begin 2063 2063 PModel := @Model[mix]; … … 2065 2065 2066 2066 if Master < 0 then 2067 FreeUnit( p, uix);2067 FreeUnit(P, uix); 2068 2068 if (MoveInfo.MoveType in [mtMove, mtCapture]) and MoveInfo.MountainDelay 2069 2069 then … … 2073 2073 Loc := -2; 2074 2074 if TroopLoad + AirLoad > 0 then 2075 for i:= 0 to nUn - 1 do2076 if (Un[ i].Loc >= 0) and (Un[i].Master = uix) then2077 Un[ i].Loc := -2;2075 for I := 0 to nUn - 1 do 2076 if (Un[I].Loc >= 0) and (Un[I].Master = uix) then 2077 Un[I].Loc := -2; 2078 2078 UpdateUnitMap(FromLoc); 2079 2079 … … 2093 2093 ShowMove.Flags := ShowMove.Flags or umShipLoading; 2094 2094 for p1 := 0 to nPl - 1 do 2095 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2095 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2096 2096 then 2097 2097 begin … … 2102 2102 else 2103 2103 MinLevel := lObserveUnhidden; 2104 SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and2104 SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and 2105 2105 3 >= MinLevel); 2106 SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and2106 SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and 2107 2107 3 >= MinLevel); 2108 2108 if SeeFrom and SeeTo then 2109 2109 begin 2110 TellAboutModel(p1, p, mix);2111 if p1 = pthen2110 TellAboutModel(p1, P, mix); 2111 if p1 = P then 2112 2112 ShowMove.emix := -1 2113 2113 else 2114 ShowMove.emix := emixSafe(p1, p, mix);2114 ShowMove.emix := emixSafe(p1, P, mix); 2115 2115 if MoveInfo.MoveType = mtCapture then 2116 2116 CallPlayer(cShowCapturing, p1, ShowMove) … … 2126 2126 Loc := ToLoc; 2127 2127 if TroopLoad + AirLoad > 0 then 2128 for i:= 0 to nUn - 1 do2129 if Un[ i].Loc = -2 then2130 Un[ i].Loc := ToLoc;2131 2132 ExtDiscover := false;2128 for I := 0 to nUn - 1 do 2129 if Un[I].Loc = -2 then 2130 Un[I].Loc := ToLoc; 2131 2132 ExtDiscover := False; 2133 2133 nUpdateLoc := 0; 2134 2134 if MoveInfo.MoveType = mtCapture then 2135 2135 begin 2136 assert(Occupant[ToLoc] < 0);2136 Assert(Occupant[ToLoc] < 0); 2137 2137 for uix1 := 0 to RW[MoveInfo.Defender].nUn - 1 do 2138 2138 with RW[MoveInfo.Defender].Un[uix1] do … … 2140 2140 begin 2141 2141 UpdateLoc[nUpdateLoc] := Loc; 2142 inc(nUpdateLoc);2142 Inc(nUpdateLoc); 2143 2143 end; 2144 2144 // unit will be removed -- remember position and update for all players … … 2147 2147 then 2148 2148 begin // city captured 2149 ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, p);2149 ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, P); 2150 2150 City[nCity - 1].Flags := CaptureTurns shl 16; 2151 CityShrink( p, nCity - 1);2151 CityShrink(P, nCity - 1); 2152 2152 if Mode = moPlaying then 2153 with RW[ p].City[nCity - 1] do2153 with RW[P].City[nCity - 1] do 2154 2154 begin 2155 2155 // SavedResourceWeights[nCity-1]:=ResourceWeights; 2156 2156 SavedTiles[nCity - 1] := Tiles; 2157 2157 end; 2158 ExtDiscover := true;2158 ExtDiscover := True; 2159 2159 2160 2160 // Temple of Zeus effect 2161 if GWonder[woZeus].EffectiveOwner = pthen2161 if GWonder[woZeus].EffectiveOwner = P then 2162 2162 begin 2163 GiveCivilReport( p, MoveInfo.Defender);2164 for i:= 0 to nAdv - 1 do2165 if not( i in FutureTech) and (RW[p].Tech[i] < tsSeen) and2166 (RW[MoveInfo.Defender].Tech[ i] >= tsApplicable) then2163 GiveCivilReport(P, MoveInfo.Defender); 2164 for I := 0 to nAdv - 1 do 2165 if not(I in FutureTech) and (RW[P].Tech[I] < tsSeen) and 2166 (RW[MoveInfo.Defender].Tech[I] >= tsApplicable) then 2167 2167 begin 2168 2168 Happened := Happened or phStealTech; … … 2172 2172 end; 2173 2173 if Mode = moPlaying then 2174 LogCheckBorders( p, nCity - 1, MoveInfo.Defender);2174 LogCheckBorders(P, nCity - 1, MoveInfo.Defender); 2175 2175 {$IFOPT O-} if Mode < moPlaying then 2176 InvalidTreatyMap := not(1 shl p); {$ENDIF}2176 InvalidTreatyMap := not(1 shl P); {$ENDIF} 2177 2177 // territory should not be considered for the rest of the command 2178 2178 // execution, because during loading a game it's incorrect before … … 2181 2181 else // city destroyed 2182 2182 begin 2183 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);2183 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False); 2184 2184 CheckBorders(ToLoc, MoveInfo.Defender); 2185 2185 end; 2186 RecalcPeaceMap( p);2186 RecalcPeaceMap(P); 2187 2187 if Mode >= moMovie then 2188 move(GWonder, Wonder, SizeOf(GWonder));2188 Move(GWonder, Wonder, SizeOf(GWonder)); 2189 2189 end; { if MoveInfo.MoveType=mtCapture } 2190 2190 2191 2191 if MoveInfo.MoveType = mtSpyMission then 2192 2192 begin 2193 MissionResult := DoSpyMission( p, MoveInfo.Defender, MoveInfo.Dcix,2193 MissionResult := DoSpyMission(P, MoveInfo.Defender, MoveInfo.Dcix, 2194 2194 SpyMission); 2195 2195 if (Mode = moPlaying) and (SpyMission = smStealForeignReports) then 2196 CallPlayer(cShowMissionResult, p, MissionResult);2196 CallPlayer(cShowMissionResult, P, MissionResult); 2197 2197 end; 2198 2198 2199 2199 Health := MoveInfo.EndHealth; 2200 dec(Movement, MoveInfo.Cost);2200 Dec(Movement, MoveInfo.Cost); 2201 2201 // transport unload 2202 2202 if Master >= 0 then 2203 2203 begin 2204 2204 if PModel.Domain = dAir then 2205 dec(Un[Master].AirLoad)2206 else 2207 begin 2208 dec(Un[Master].TroopLoad);2209 assert(Movement <= 0);2205 Dec(Un[Master].AirLoad) 2206 else 2207 begin 2208 Dec(Un[Master].TroopLoad); 2209 Assert(Movement <= 0); 2210 2210 end; 2211 2211 Master := -1; … … 2213 2213 2214 2214 if (Health <= 0) or (MoveInfo.MoveType = mtSpyMission) then 2215 RemoveUnit( p, uix) // spy mission or victim of HostileDamage2215 RemoveUnit(P, uix) // spy mission or victim of HostileDamage 2216 2216 else 2217 2217 begin // transport load … … 2220 2220 begin 2221 2221 if PModel.Domain = dAir then 2222 inc(Un[MoveInfo.ToMaster].AirLoad)2222 Inc(Un[MoveInfo.ToMaster].AirLoad) 2223 2223 else 2224 inc(Un[MoveInfo.ToMaster].TroopLoad);2224 Inc(Un[MoveInfo.ToMaster].TroopLoad); 2225 2225 end 2226 2226 else 2227 PlaceUnit( p, uix);2227 PlaceUnit(P, uix); 2228 2228 end; 2229 2229 2230 2230 if (MoveInfo.MoveType = mtCapture) and (nUpdateLoc > 0) then 2231 RecalcMapZoC( p);2231 RecalcMapZoC(P); 2232 2232 UpdateUnitMap(ToLoc, MoveInfo.MoveType = mtCapture); 2233 for i:= 0 to nUpdateLoc - 1 do2234 UpdateUnitMap(UpdateLoc[ i]);2233 for I := 0 to nUpdateLoc - 1 do 2234 UpdateUnitMap(UpdateLoc[I]); 2235 2235 // tell about lost units of defender 2236 2236 … … 2242 2242 (RealMap[ToLoc] and fTerImp = tiFort) or 2243 2243 (RealMap[ToLoc] and fTerImp = tiBase) then 2244 ExtDiscover := true;2244 ExtDiscover := True; 2245 2245 if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then 2246 i:= lObserveSuper2246 I := lObserveSuper 2247 2247 else if (PModel.Domain = dAir) or 2248 2248 (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) then 2249 i:= lObserveAll2250 else 2251 i:= lObserveUnhidden;2249 I := lObserveAll 2250 else 2251 I := lObserveUnhidden; 2252 2252 if ExtDiscover then 2253 2253 begin 2254 if Discover21(ToLoc, p, i, true, PModel.Domain = dGround) then2255 result := result or rEnemySpotted;2254 if Discover21(ToLoc, P, I, True, PModel.Domain = dGround) then 2255 Result := Result or rEnemySpotted; 2256 2256 end 2257 2257 else 2258 2258 begin 2259 if Discover9(ToLoc, p, i, true, PModel.Domain = dGround) then2260 result := result or rEnemySpotted;2259 if Discover9(ToLoc, P, I, True, PModel.Domain = dGround) then 2260 Result := Result or rEnemySpotted; 2261 2261 end; 2262 2262 end; … … 2264 2264 if Mode >= moMovie then { show after-move in interface modules } 2265 2265 for p1 := 0 to nPl - 1 do 2266 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2266 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2267 2267 then 2268 2268 begin … … 2273 2273 else 2274 2274 MinLevel := lObserveUnhidden; 2275 SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and2275 SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and 2276 2276 3 >= MinLevel); 2277 SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and2277 SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and 2278 2278 3 >= MinLevel); 2279 2279 if SeeTo and (MoveInfo.MoveType = mtCapture) then … … 2283 2283 else if (MoveInfo.MoveType <> mtSpyMission) and SeeTo then 2284 2284 CallPlayer(cShowUnitChanged, p1, ToLoc); 2285 for i:= 0 to nUpdateLoc - 1 do2286 if ObserveLevel[UpdateLoc[ i]] shr (2 * p1) and 3 >= lObserveUnhidden2285 for I := 0 to nUpdateLoc - 1 do 2286 if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden 2287 2287 then 2288 CallPlayer(cShowUnitChanged, p1, UpdateLoc[ i]);2288 CallPlayer(cShowUnitChanged, p1, UpdateLoc[I]); 2289 2289 end; 2290 2290 end; 2291 2291 end; 2292 2292 2293 function ExecuteAttack( p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;2294 ShowMove: TShowMove): integer;2293 function ExecuteAttack(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo; 2294 ShowMove: TShowMove): Integer; 2295 2295 2296 2296 procedure WriteBattleHistory(ToLoc, FromLoc, Attacker, Defender, mixAttacker, 2297 mixDefender: integer; AttackerLost, DefenderLost: boolean);2297 mixDefender: Integer; AttackerLost, DefenderLost: Boolean); 2298 2298 var 2299 2299 AttackerBattle, DefenderBattle: ^TBattle; … … 2307 2307 ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle))); 2308 2308 AttackerBattle := @BattleHistory[nBattleHistory]; 2309 inc(nBattleHistory);2309 Inc(nBattleHistory); 2310 2310 end; 2311 2311 with RW[Defender] do … … 2317 2317 ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle))); 2318 2318 DefenderBattle := @BattleHistory[nBattleHistory]; 2319 inc(nBattleHistory);2319 Inc(nBattleHistory); 2320 2320 end; 2321 2321 AttackerBattle.Enemy := Defender; … … 2346 2346 2347 2347 var 2348 i, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: integer;2348 I, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: Integer; 2349 2349 PModel: ^TModel; 2350 UpdateLoc: array [0 .. numax - 1] of integer;2351 LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: boolean;2350 UpdateLoc: array [0 .. numax - 1] of Integer; 2351 LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: Boolean; 2352 2352 begin 2353 result := 0;2354 with RW[ p].Un[uix] do2353 Result := 0; 2354 with RW[P].Un[uix] do 2355 2355 begin 2356 PModel := @RW[ p].Model[mix];2356 PModel := @RW[P].Model[mix]; 2357 2357 FromLoc := Loc; 2358 2358 … … 2360 2360 ShowMove.EndHealthDef := MoveInfo.EndHealthDef; 2361 2361 if MoveInfo.MoveType = mtAttack then 2362 WriteBattleHistory(ToLoc, FromLoc, p, MoveInfo.Defender, mix,2362 WriteBattleHistory(ToLoc, FromLoc, P, MoveInfo.Defender, mix, 2363 2363 RW[MoveInfo.Defender].Un[MoveInfo.Duix].mix, MoveInfo.EndHealth <= 0, 2364 2364 MoveInfo.EndHealthDef <= 0); … … 2367 2367 begin 2368 2368 if Mode>=moMovie then 2369 CallPlayer(cShowCancelTreaty,MoveInfo.Defender, p);2370 CancelTreaty( p,MoveInfo.Defender)2369 CallPlayer(cShowCancelTreaty,MoveInfo.Defender,P); 2370 CancelTreaty(P,MoveInfo.Defender) 2371 2371 end; } 2372 2372 if Mode >= moMovie then { show attack in interface modules } 2373 2373 for p1 := 0 to nPl - 1 do 2374 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2374 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2375 2375 then 2376 2376 begin … … 2380 2380 if SeeFrom and SeeTo then 2381 2381 begin 2382 TellAboutModel(p1, p, mix);2383 if p1 = pthen2382 TellAboutModel(p1, P, mix); 2383 if p1 = P then 2384 2384 ShowMove.emix := -1 2385 2385 else 2386 ShowMove.emix := emixSafe(p1, p, mix);2386 ShowMove.emix := emixSafe(p1, P, mix); 2387 2387 CallPlayer(cShowAttacking, p1, ShowMove); 2388 2388 end; 2389 2389 end; 2390 2390 2391 LoseCityPop := false;2391 LoseCityPop := False; 2392 2392 if (RealMap[ToLoc] and fCity <> 0) and 2393 2393 ((MoveInfo.MoveType = mtAttack) and (MoveInfo.EndHealthDef <= 0) or … … 2411 2411 if MoveInfo.MoveType = mtBombard then 2412 2412 begin 2413 assert(Movement >= 100);2413 Assert(Movement >= 100); 2414 2414 if PModel.Attack = 0 then 2415 2415 Flags := Flags and not unBombsLoaded; 2416 dec(Movement, 100);2416 Dec(Movement, 100); 2417 2417 end 2418 2418 else if MoveInfo.MoveType = mtExpel then 2419 2419 begin 2420 assert(Movement >= 100);2420 Assert(Movement >= 100); 2421 2421 Job := jNone; 2422 2422 Flags := Flags and not unFortified; 2423 dec(Movement, 100);2423 Dec(Movement, 100); 2424 2424 end 2425 2425 else 2426 2426 begin 2427 assert(MoveInfo.MoveType = mtAttack);2427 Assert(MoveInfo.MoveType = mtAttack); 2428 2428 if MoveInfo.EndHealth = 0 then 2429 RemoveUnit( p, uix, MoveInfo.Defender) // destroy attacker2429 RemoveUnit(P, uix, MoveInfo.Defender) // destroy attacker 2430 2430 else 2431 2431 begin // update attacker … … 2434 2434 Exp := (nExp - 1) * ExpCost 2435 2435 else 2436 inc(Exp, ExpGain);2436 Inc(Exp, ExpGain); 2437 2437 Health := MoveInfo.EndHealth; 2438 2438 Job := jNone; … … 2442 2442 Flags := Flags and not unFortified; 2443 2443 if Movement > 100 then 2444 dec(Movement, 100)2444 Dec(Movement, 100) 2445 2445 else 2446 2446 Movement := 0; … … 2448 2448 end; 2449 2449 2450 ZoCDefenderDestroyed := false;2450 ZoCDefenderDestroyed := False; 2451 2451 nUpdateLoc := 0; 2452 2452 if MoveInfo.MoveType = mtExpel then … … 2469 2469 PlaceUnit(MoveInfo.Defender, MoveInfo.Duix); 2470 2470 UpdateLoc[nUpdateLoc] := Loc; 2471 inc(nUpdateLoc);2471 Inc(nUpdateLoc); 2472 2472 Flags := Flags or unWithdrawn; 2473 2473 end; … … 2480 2480 Exp := (nExp - 1) * ExpCost 2481 2481 else 2482 inc(Exp, ExpGain);2482 Inc(Exp, ExpGain); 2483 2483 Health := MoveInfo.EndHealthDef; 2484 2484 end … … 2493 2493 (RealMap[ToLoc] and fTerImp <> tiFort)) or LoseCityPop and 2494 2494 (RW[MoveInfo.Defender].City[MoveInfo.Dcix].Size = 2) then 2495 RemoveAllUnits(MoveInfo.Defender, ToLoc, p)2495 RemoveAllUnits(MoveInfo.Defender, ToLoc, P) 2496 2496 { no city, base or fortress } 2497 2497 else 2498 RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, p);2498 RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, P); 2499 2499 end; 2500 2500 … … 2509 2509 begin 2510 2510 UpdateLoc[nUpdateLoc] := Loc; 2511 inc(nUpdateLoc);2511 Inc(nUpdateLoc); 2512 2512 end; 2513 2513 // unit will be removed -- remember position and update for all players 2514 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);2514 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False); 2515 2515 CheckBorders(ToLoc, MoveInfo.Defender); 2516 RecalcPeaceMap( p);2516 RecalcPeaceMap(P); 2517 2517 end; 2518 2518 end; 2519 2519 2520 2520 if CityDestroyed and (nUpdateLoc > 0) then 2521 RecalcMapZoC( p)2521 RecalcMapZoC(P) 2522 2522 else if ZoCDefenderDestroyed then 2523 RecalcV8ZoC( p, ToLoc);2523 RecalcV8ZoC(P, ToLoc); 2524 2524 UpdateUnitMap(FromLoc); 2525 2525 UpdateUnitMap(ToLoc, LoseCityPop); 2526 for i:= 0 to nUpdateLoc - 1 do2527 UpdateUnitMap(UpdateLoc[ i]);2526 for I := 0 to nUpdateLoc - 1 do 2527 UpdateUnitMap(UpdateLoc[I]); 2528 2528 // tell about lost units of defender 2529 2529 2530 2530 if Mode >= moMovie then 2531 2531 begin 2532 for i := 0 to RW[p].nEnemyModel - 1 do2533 with RW[ p].EnemyModel[i] do2534 Lost := Destroyed[ p, Owner, mix];2532 for I := 0 to RW[P].nEnemyModel - 1 do 2533 with RW[P].EnemyModel[I] do 2534 Lost := Destroyed[P, Owner, mix]; 2535 2535 for p1 := 0 to nPl - 1 do { show after-attack in interface modules } 2536 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2536 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2537 2537 then 2538 2538 begin … … 2561 2561 end; 2562 2562 2563 function MoveUnit( p, uix, dx, dy: integer; TestOnly: boolean): integer;2563 function MoveUnit(P, uix, dx, dy: Integer; TestOnly: Boolean): Integer; 2564 2564 var 2565 ToLoc: integer;2565 ToLoc: Integer; 2566 2566 MoveInfo: TMoveInfo; 2567 2567 ShowMove: TShowMove; 2568 2568 begin 2569 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}2570 with RW[ p].Un[uix] do2569 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 2570 with RW[P].Un[uix] do 2571 2571 begin 2572 2572 ToLoc := dLoc(Loc, dx, dy); 2573 2573 if (ToLoc < 0) or (ToLoc >= MapSize) then 2574 2574 begin 2575 result := eInvalid;2576 exit;2575 Result := eInvalid; 2576 Exit; 2577 2577 end; 2578 result := CalculateMove(p, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);2579 if result = eZOC_EnemySpotted then2578 Result := CalculateMove(P, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo); 2579 if Result = eZOC_EnemySpotted then 2580 2580 ZOCTile := ToLoc; 2581 if ( result >= rExecuted) and not TestOnly then2581 if (Result >= rExecuted) and not TestOnly then 2582 2582 begin 2583 2583 ShowMove.dx := dx; … … 2589 2589 ShowMove.Exp := Exp; 2590 2590 ShowMove.Load := TroopLoad + AirLoad; 2591 ShowMove.Owner := p;2591 ShowMove.Owner := P; 2592 2592 if (TroopLoad > 0) or (AirLoad > 0) then 2593 2593 ShowMove.Flags := unMulti … … 2606 2606 case MoveInfo.MoveType of 2607 2607 mtMove, mtCapture, mtSpyMission: 2608 result := ExecuteMove(p, uix, ToLoc, MoveInfo, ShowMove) or result;2608 Result := ExecuteMove(P, uix, ToLoc, MoveInfo, ShowMove) or Result; 2609 2609 mtAttack, mtBombard, mtExpel: 2610 result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result;2610 Result := ExecuteAttack(P, uix, ToLoc, MoveInfo, ShowMove) or Result; 2611 2611 end; 2612 2612 end; … … 2614 2614 end; 2615 2615 2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;2617 2618 function CountPrice(const Offer: TOffer; PriceType: integer): integer;2616 function Server(Command, Player, Subject: Integer; var Data): Integer; stdcall; 2617 2618 function CountPrice(const Offer: TOffer; PriceType: Integer): Integer; 2619 2619 var 2620 i: integer;2620 I: Integer; 2621 2621 begin 2622 result := 0;2623 for i:= 0 to Offer.nDeliver + Offer.nCost - 1 do2624 if Offer.Price[ i] and $FFFF0000 = Cardinal(PriceType) then2625 inc(result);2622 Result := 0; 2623 for I := 0 to Offer.nDeliver + Offer.nCost - 1 do 2624 if Offer.Price[I] and $FFFF0000 = Cardinal(PriceType) then 2625 Inc(Result); 2626 2626 end; 2627 2627 2628 2628 { procedure UpdateBorderHelper; 2629 2629 var 2630 x, y, Loc, Loc1, dx, dy, ObserveMask: integer;2630 X, Y, Loc, Loc1, dx, dy, ObserveMask: Integer; 2631 2631 begin 2632 2632 ObserveMask:=3 shl (2*pTurn); 2633 for x:=0 to lx-1 do for y:=0 to ly shr 1-1 do2633 for X:=0 to lx-1 do for Y:=0 to ly shr 1-1 do 2634 2634 begin 2635 Loc:=lx*( y*2)+x;2635 Loc:=lx*(Y*2)+X; 2636 2636 if ObserveLevel[Loc] and ObserveMask<>0 then 2637 2637 begin 2638 2638 for dy:=0 to 1 do for dx:=0 to 1 do 2639 2639 begin 2640 Loc1:=(Loc+dx-1+lx) mod lx +lx*(( y+dy)*2-1);2640 Loc1:=(Loc+dx-1+lx) mod lx +lx*((Y+dy)*2-1); 2641 2641 if (Loc1>=0) and (Loc1<MapSize) 2642 2642 and (ObserveLevel[Loc1] and ObserveMask<>0) then … … 2666 2666 ptInvalid = 8; 2667 2667 2668 function ProjectType(Project: integer): integer;2668 function ProjectType(Project: Integer): Integer; 2669 2669 begin 2670 2670 if Project and cpCompleted <> 0 then 2671 result := ptSelect2671 Result := ptSelect 2672 2672 else if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 2673 result := ptTrGoods2673 Result := ptTrGoods 2674 2674 else if Project and cpImp = 0 then 2675 2675 if RW[Player].Model[Project and cpIndex].Kind = mkCaravan then 2676 result := ptCaravan2677 else 2678 result := ptUn2676 Result := ptCaravan 2677 else 2678 Result := ptUn 2679 2679 else if Project and cpIndex >= nImp then 2680 result := ptInvalid2680 Result := ptInvalid 2681 2681 else if Imp[Project and cpIndex].Kind = ikWonder then 2682 result := ptWonder2682 Result := ptWonder 2683 2683 else if Imp[Project and cpIndex].Kind = ikShipPart then 2684 result := ptShip2684 Result := ptShip 2685 2685 else 2686 result := ptImp;2686 Result := ptImp; 2687 2687 end; 2688 2688 2689 2689 var 2690 d, i, j, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,2690 D, I, J, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap, 2691 2691 MaxCap, CapWeight, Cost, NextProd, Preq, TotalFood, TotalProd, CheckSum, 2692 2692 StopTurn, FutureMCost, NewProject, OldImp, mix, V8, V21, AStr, DStr, 2693 ABaseDamage, DBaseDamage: integer;2693 ABaseDamage, DBaseDamage: Integer; 2694 2694 CityReport: TCityReport; 2695 2695 FormerCLState: TCmdListState; … … 2708 2708 end; 2709 2709 2710 assert(MapSize = lx * ly);2711 assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);2710 Assert(MapSize = lx * ly); 2711 Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute); 2712 2712 // not for internal commands 2713 2713 if (Command < 0) or (Command >= $10000) then 2714 2714 begin 2715 result := eUnknown;2716 exit;2715 Result := eUnknown; 2716 Exit; 2717 2717 end; 2718 2718 … … 2721 2721 ((Subject < 0) or (Subject >= $1000))) then 2722 2722 begin 2723 result := eInvalid;2724 exit;2723 Result := eInvalid; 2724 Exit; 2725 2725 end; 2726 2726 … … 2731 2731 begin 2732 2732 PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player])); 2733 result := eNoTurn;2734 exit;2733 Result := eNoTurn; 2734 Exit; 2735 2735 end; 2736 2736 2737 result := eOK;2737 Result := eOK; 2738 2738 2739 2739 // check if command allowed now … … 2758 2758 PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x', 2759 2759 [Player, Command shr 4])); 2760 result := eNoTurn;2761 exit;2760 Result := eNoTurn; 2761 Exit; 2762 2762 end; 2763 2763 … … 2767 2767 HandoverStack[nHandoverStack] := Player + $1000; 2768 2768 HandoverStack[nHandoverStack + 1] := Command; 2769 inc(nHandoverStack, 2);2769 Inc(nHandoverStack, 2); 2770 2770 2771 2771 InvalidTreatyMap := 0; … … 2780 2780 FormerCLState := CL.State; 2781 2781 CL.Put(Command, Player, Subject, @Data); 2782 logged := true;2782 logged := True; 2783 2783 end 2784 2784 else 2785 logged := false;2785 logged := False; 2786 2786 2787 2787 case Command of … … 2798 2798 2799 2799 sGetDebugMap: 2800 pointer(Data) := DebugMap[Subject];2800 Pointer(Data) := DebugMap[Subject]; 2801 2801 2802 2802 { sChangeSuperView: 2803 2803 if Difficulty[Player]=0 then 2804 2804 begin 2805 for i:=0 to nBrain-1 do if Brain[i].Initialized then2806 CallClient( i, cShowSuperView, Subject)2805 for I:=0 to nBrain-1 do if Brain[I].Initialized then 2806 CallClient(I, cShowSuperView, Subject) 2807 2807 end 2808 else result:=eInvalid; }2808 else Result:=eInvalid; } 2809 2809 2810 2810 sRefreshDebugMap: … … 2829 2829 else 2830 2830 StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1; 2831 move(Stat[Command shr 4 and $F, Subject]^, Data,2832 StopTurn * SizeOf( integer));2831 Move(Stat[Command shr 4 and $F, Subject]^, Data, 2832 StopTurn * SizeOf(Integer)); 2833 2833 FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) * 2834 SizeOf( integer), 0);2834 SizeOf(Integer), 0); 2835 2835 end 2836 2836 else 2837 result := eInvalid;2837 Result := eInvalid; 2838 2838 2839 2839 sGetTechCost: 2840 integer(Data) := TechCost(Player);2840 Integer(Data) := TechCost(Player); 2841 2841 2842 2842 sGetAIInfo: 2843 2843 if AIInfo[Subject] = '' then 2844 pchar(Data) := nil2845 else 2846 pchar(Data) := @AIInfo[Subject][1];2844 PChar(Data) := nil 2845 else 2846 PChar(Data) := @AIInfo[Subject][1]; 2847 2847 2848 2848 sGetAICredits: 2849 2849 if AICredits = '' then 2850 pchar(Data) := nil2851 else 2852 pchar(Data) := @AICredits[1];2850 PChar(Data) := nil 2851 else 2852 PChar(Data) := @AICredits[1]; 2853 2853 2854 2854 sGetVersion: 2855 integer(Data) := CevoVersion;2855 Integer(Data) := CevoVersion; 2856 2856 2857 2857 sGetGameChanged: 2858 2858 if Player <> 0 then 2859 result := eInvalid2859 Result := eInvalid 2860 2860 else if (CL <> nil) and (CL.State.nLog = nLogOpened) and 2861 2861 (CL.State.MoveCode = 0) and not HasCityTileChanges and 2862 2862 not HasChanges(Player) then 2863 result := eNotChanged;2863 Result := eNotChanged; 2864 2864 2865 2865 sGetTileInfo: 2866 2866 if (Subject >= 0) and (Subject < MapSize) then 2867 result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))2868 else 2869 result := eInvalid;2867 Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data)) 2868 else 2869 Result := eInvalid; 2870 2870 2871 2871 sGetCityTileInfo: 2872 2872 if (Subject >= 0) and (Subject < MapSize) then 2873 result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))2874 else 2875 result := eInvalid;2873 Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data)) 2874 else 2875 Result := eInvalid; 2876 2876 2877 2877 sGetHypoCityTileInfo: … … 2880 2880 if (TTileInfo(Data).ExplCity < 0) or 2881 2881 (TTileInfo(Data).ExplCity >= RW[Player].nCity) then 2882 result := eInvalid2882 Result := eInvalid 2883 2883 else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2884 result := eNoPreq2884 Result := eNoPreq 2885 2885 else 2886 result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,2886 Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject, 2887 2887 TTileInfo(Data)); 2888 2888 end 2889 2889 else 2890 result := eInvalid;2890 Result := eInvalid; 2891 2891 2892 2892 sGetJobProgress: … … 2894 2894 begin 2895 2895 if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2896 result := eNoPreq2896 Result := eNoPreq 2897 2897 else 2898 result := GetJobProgress(Player, Subject, TJobProgressData(Data));2898 Result := GetJobProgress(Player, Subject, TJobProgressData(Data)); 2899 2899 end 2900 2900 else 2901 result := eInvalid;2901 Result := eInvalid; 2902 2902 2903 2903 sGetModels: … … 2911 2911 end 2912 2912 else 2913 result := eInvalid;2913 Result := eInvalid; 2914 2914 2915 2915 sGetUnits: 2916 2916 if (Subject >= 0) and (Subject < MapSize) and 2917 2917 (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then 2918 integer(Data) := GetUnitStack(Player, Subject)2919 else 2920 result := eNoPreq;2918 Integer(Data) := GetUnitStack(Player, Subject) 2919 else 2920 Result := eNoPreq; 2921 2921 2922 2922 sGetDefender: 2923 2923 if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player) 2924 2924 then 2925 Strongest(Subject, integer(Data), d, i, j)2926 else 2927 result := eInvalid;2925 Strongest(Subject, Integer(Data), D, I, J) 2926 else 2927 Result := eInvalid; 2928 2928 2929 2929 sGetBattleForecast, sGetBattleForecastEx: … … 2935 2935 ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then 2936 2936 begin 2937 result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,2937 Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1, 2938 2938 cix1, AStr, DStr, ABaseDamage, DBaseDamage); 2939 2939 if Command = sGetBattleForecastEx then … … 2944 2944 TBattleForecastEx(Data).DBaseDamage := DBaseDamage; 2945 2945 end; 2946 if result = eOK then2947 result := eInvalid; // no enemy unit there!2946 if Result = eOK then 2947 Result := eInvalid; // no enemy unit there! 2948 2948 end 2949 2949 else 2950 result := eInvalid2951 else 2952 result := eInvalid;2950 Result := eInvalid 2951 else 2952 Result := eInvalid; 2953 2953 2954 2954 sGetUnitReport: 2955 2955 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2956 2956 (RW[Player].Un[Subject].Loc < 0) then 2957 result := eInvalid2957 Result := eInvalid 2958 2958 else 2959 2959 GetUnitReport(Player, Subject, TUnitReport(Data)); … … 2962 2962 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2963 2963 (RW[Player].Un[Subject].Loc < 0) then 2964 result := eInvalid2965 else 2966 result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));2964 Result := eInvalid 2965 else 2966 Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data)); 2967 2967 2968 2968 sGetPlaneReturn: … … 2970 2970 (RW[Player].Un[Subject].Loc < 0) or 2971 2971 (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then 2972 result := eInvalid2972 Result := eInvalid 2973 2973 else 2974 2974 begin 2975 2975 if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then 2976 result := eOK2976 Result := eOK 2977 2977 else 2978 result := eNoWay;2978 Result := eNoWay; 2979 2979 end; 2980 2980 … … 2987 2987 Owner := Player; 2988 2988 SearchCity(Subject, Owner, cix1); 2989 c:= RW[Owner].City[cix1];2990 if (Owner <> Player) and ( c.Project and cpImp = 0) then2991 TellAboutModel(Player, Owner, c.Project and cpIndex);2989 C := RW[Owner].City[cix1]; 2990 if (Owner <> Player) and (C.Project and cpImp = 0) then 2991 TellAboutModel(Player, Owner, C.Project and cpIndex); 2992 2992 end 2993 2993 else 2994 result := eInvalid;2994 Result := eInvalid; 2995 2995 2996 2996 sGetCityReport: 2997 2997 if (Subject < 0) or (Subject >= RW[Player].nCity) or 2998 2998 (RW[Player].City[Subject].Loc < 0) then 2999 result := eInvalid3000 else 3001 result := GetCityReport(Player, Subject, TCityReport(Data));2999 Result := eInvalid 3000 else 3001 Result := GetCityReport(Player, Subject, TCityReport(Data)); 3002 3002 3003 3003 sGetCityReportNew: 3004 3004 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3005 3005 (RW[Player].City[Subject].Loc < 0) then 3006 result := eInvalid3006 Result := eInvalid 3007 3007 else 3008 3008 GetCityReportNew(Player, Subject, TCityReportNew(Data)); … … 3011 3011 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3012 3012 (RW[Player].City[Subject].Loc < 0) then 3013 result := eInvalid3013 Result := eInvalid 3014 3014 else 3015 3015 GetCityAreaInfo(Player, RW[Player].City[Subject].Loc, … … 3031 3031 end 3032 3032 else 3033 result := eInvalid;3033 Result := eInvalid; 3034 3034 3035 3035 sGetEnemyCityReportNew: … … 3048 3048 end 3049 3049 else 3050 result := eInvalid;3050 Result := eInvalid; 3051 3051 3052 3052 sGetEnemyCityAreaInfo: … … 3062 3062 end 3063 3063 else 3064 result := eInvalid;3064 Result := eInvalid; 3065 3065 3066 3066 sGetCityTileAdvice: 3067 3067 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3068 3068 (RW[Player].City[Subject].Loc < 0) then 3069 result := eInvalid3069 Result := eInvalid 3070 3070 else 3071 3071 GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data)); … … 3080 3080 EditTile(Loc, NewTile) 3081 3081 else 3082 result := eInvalid;3082 Result := eInvalid; 3083 3083 3084 3084 sRandomMap: … … 3086 3086 begin 3087 3087 CreateElevation; 3088 PreviewElevation := false;3089 CreateMap( false);3088 PreviewElevation := False; 3089 CreateMap(False); 3090 3090 FillChar(ObserveLevel, MapSize * 4, 0); 3091 3091 DiscoverAll(Player, lObserveSuper); 3092 3092 end 3093 3093 else 3094 result := eInvalid;3094 Result := eInvalid; 3095 3095 3096 3096 sMapGeneratorRequest: 3097 3097 if not MapGeneratorAvailable then 3098 result := eInvalid;3098 Result := eInvalid; 3099 3099 3100 3100 { … … 3104 3104 sTurn, sTurn - sExecute: 3105 3105 begin 3106 AllHumansDead := true;3106 AllHumansDead := True; 3107 3107 for p1 := 0 to nPl - 1 do 3108 3108 if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then 3109 AllHumansDead := false;3109 AllHumansDead := False; 3110 3110 if (pDipActive >= 0) // still in negotiation mode 3111 3111 or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or 3112 3112 (Difficulty[0] > 0) and AllHumansDead) then // game end reached 3113 result := eViolation3113 Result := eViolation 3114 3114 else if Command >= sExecute then 3115 3115 begin … … 3122 3122 begin 3123 3123 LogChanges; 3124 SaveGame('~' + LogFileName, true);3124 SaveGame('~' + LogFileName, True); 3125 3125 end; 3126 3126 {$ENDIF} … … 3137 3137 TotalFood := 0; 3138 3138 TotalProd := 0; 3139 for i:= 0 to RW[pTurn].nCity - 1 do3140 if RW[pTurn].City[ i].Loc >= 0 then3139 for I := 0 to RW[pTurn].nCity - 1 do 3140 if RW[pTurn].City[I].Loc >= 0 then 3141 3141 begin 3142 inc(TotalFood, RW[pTurn].City[i].Food);3143 inc(TotalProd, RW[pTurn].City[i].Prod);3142 Inc(TotalFood, RW[pTurn].City[I].Food); 3143 Inc(TotalProd, RW[pTurn].City[I].Prod); 3144 3144 end; 3145 3145 CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 + … … 3152 3152 begin 3153 3153 if CheckSum <> Subject then 3154 LoadOK := false;3154 LoadOK := False; 3155 3155 end 3156 3156 else // save checksum … … 3179 3179 pTurn := (pTurn + 1) mod nPl; 3180 3180 if pTurn = 0 then 3181 inc(GTurn);3181 Inc(GTurn); 3182 3182 if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then 3183 3183 begin // already made extinct -- continue statistics … … 3218 3218 sBreak, sResign, sNextRound, sReload: 3219 3219 if Mode = moMovie then 3220 MovieStopped := true3220 MovieStopped := True 3221 3221 else 3222 3222 begin … … 3224 3224 begin 3225 3225 ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and 3226 ( integer(Data) >= 0) and (integer(Data) < GTurn);3226 (Integer(Data) >= 0) and (Integer(Data) < GTurn); 3227 3227 for p1 := 1 to nPl - 1 do 3228 3228 if bix[p1].Kind = btTerm then 3229 ok := false;3229 ok := False; 3230 3230 // allow reload in AI-only games only 3231 3231 end … … 3236 3236 if (Command = sBreak) or (Command = sResign) then 3237 3237 Notify(ntBackOn); 3238 for i:= 0 to Brains.Count - 1 do3239 if Brains[ i].Initialized then3238 for I := 0 to Brains.Count - 1 do 3239 if Brains[I].Initialized then 3240 3240 begin 3241 if Brains[ i].Kind = btAI then3242 Notify(ntDeinitModule, i);3243 CallClient( i, cBreakGame, nil^);3241 if Brains[I].Kind = btAI then 3242 Notify(ntDeinitModule, I); 3243 CallClient(I, cBreakGame, nil^); 3244 3244 end; 3245 3245 Notify(ntEndInfo); … … 3248 3248 LogCityTileChanges; 3249 3249 LogChanges; 3250 SaveGame(LogFileName, false);3250 SaveGame(LogFileName, False); 3251 3251 end; 3252 3252 DeleteFile(SavePath + '~' + LogFileName); … … 3261 3261 LandMass, MaxTurn); 3262 3262 sReload: 3263 LoadGame(SavePath, LogFileName, integer(Data), false);3263 LoadGame(SavePath, LogFileName, Integer(Data), False); 3264 3264 end; 3265 3265 end 3266 3266 else 3267 result := eInvalid;3267 Result := eInvalid; 3268 3268 end; 3269 3269 … … 3282 3282 end 3283 3283 else 3284 result := eInvalid;3284 Result := eInvalid; 3285 3285 3286 3286 scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact 3287 3287 - sExecute + (nPl - 1) shl 4: 3288 3288 if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then 3289 result := eInvalid3289 Result := eInvalid 3290 3290 else if GWinner > 0 then 3291 result := eViolation // game end reached3291 Result := eViolation // game end reached 3292 3292 else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then 3293 result := eNoPreq3293 Result := eNoPreq 3294 3294 else if GTurn < GColdWarStart + ColdWarTurns then 3295 result := eColdWar3295 Result := eColdWar 3296 3296 else if RW[Player].Government = gAnarchy then 3297 result := eAnarchy3297 Result := eAnarchy 3298 3298 else if RW[Command shr 4 and $F].Government = gAnarchy then 3299 3299 begin 3300 result := eAnarchy;3300 Result := eAnarchy; 3301 3301 LastEndClientCommand := scReject; // enable cancel treaty 3302 3302 pContacted := Command shr 4 and $F; … … 3306 3306 pContacted := Command shr 4 and $F; 3307 3307 pDipActive := pContacted; 3308 assert(Mode = moPlaying);3308 Assert(Mode = moPlaying); 3309 3309 Inform(pDipActive); 3310 3310 ChangeClientWhenDone(scContact, pDipActive, pTurn, 4); … … 3317 3317 begin // contact requested and not accepted yet 3318 3318 pDipActive := -1; 3319 assert(Mode = moPlaying);3319 Assert(Mode = moPlaying); 3320 3320 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3321 3321 end; 3322 3322 end 3323 3323 else 3324 result := eInvalid;3324 Result := eInvalid; 3325 3325 3326 3326 scDipStart, scDipStart - sExecute: … … 3333 3333 RW[pTurn].Credibility; 3334 3334 pDipActive := pTurn; 3335 assert(Mode = moPlaying);3335 Assert(Mode = moPlaying); 3336 3336 IntServer(sIntHaveContact, pTurn, pContacted, nil^); 3337 3337 ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0); … … 3339 3339 end 3340 3340 else 3341 result := eInvalid;3341 Result := eInvalid; 3342 3342 3343 3343 scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak, … … 3346 3346 if pDipActive >= 0 then 3347 3347 begin 3348 assert(Mode = moPlaying);3348 Assert(Mode = moPlaying); 3349 3349 if pDipActive = pTurn then 3350 3350 p1 := pContacted … … 3362 3362 // check if offer can be accepted 3363 3363 if nDeliver + nCost = 0 then 3364 result := eOfferNotAcceptable;3365 for i:= 0 to nDeliver + nCost - 1 do3366 if Price[ i] = opChoose then3367 result := eOfferNotAcceptable;3368 for i:= 0 to nCost - 1 do3369 if not PayPrice(pDipActive, p1, Price[nDeliver + i], false) then3370 result := eOfferNotAcceptable;3371 if (Command >= sExecute) and ( result >= rExecuted) then3364 Result := eOfferNotAcceptable; 3365 for I := 0 to nDeliver + nCost - 1 do 3366 if Price[I] = opChoose then 3367 Result := eOfferNotAcceptable; 3368 for I := 0 to nCost - 1 do 3369 if not PayPrice(pDipActive, p1, Price[nDeliver + I], False) then 3370 Result := eOfferNotAcceptable; 3371 if (Command >= sExecute) and (Result >= rExecuted) then 3372 3372 begin 3373 3373 IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive, … … 3376 3376 3377 3377 // tell other players about ship part trades 3378 HasShipChanged := false;3378 HasShipChanged := False; 3379 3379 FillChar(ShowShipChange, SizeOf(ShowShipChange), 0); 3380 for i:= 0 to nDeliver + nCost - 1 do3381 if Price[ i] and opMask = opShipParts then3380 for I := 0 to nDeliver + nCost - 1 do 3381 if Price[I] and opMask = opShipParts then 3382 3382 begin 3383 HasShipChanged := true;3384 if i>= nDeliver then3383 HasShipChanged := True; 3384 if I >= nDeliver then 3385 3385 begin // p1 has demanded from pDipActive 3386 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3387 + integer(Price[i] and $FFFF);3388 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3389 - integer(Price[i] and $FFFF);3386 ShowShipChange.Ship1Change[Price[I] shr 16 and 3] := 3387 +Integer(Price[I] and $FFFF); 3388 ShowShipChange.Ship2Change[Price[I] shr 16 and 3] := 3389 -Integer(Price[I] and $FFFF); 3390 3390 end 3391 3391 else 3392 3392 begin // p1 has delivered to pDipActive 3393 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3394 - integer(Price[i] and $FFFF);3395 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3396 + integer(Price[i] and $FFFF);3393 ShowShipChange.Ship1Change[Price[I] shr 16 and 3] := 3394 -Integer(Price[I] and $FFFF); 3395 ShowShipChange.Ship2Change[Price[I] shr 16 and 3] := 3396 +Integer(Price[I] and $FFFF); 3397 3397 end; 3398 3398 end; … … 3406 3406 (1 shl p2 and (GAlive or GWatching) <> 0) then 3407 3407 begin 3408 move(GShip, RW[p2].Ship, SizeOf(GShip));3408 Move(GShip, RW[p2].Ship, SizeOf(GShip)); 3409 3409 if 1 shl p2 and GWatching <> 0 then 3410 3410 CallPlayer(cShowShipChange, p2, ShowShipChange); … … 3419 3419 (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns) 3420 3420 then 3421 result := eCancelTreatyRush3421 Result := eCancelTreatyRush 3422 3422 else if Command >= sExecute then 3423 3423 begin … … 3426 3426 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3427 3427 begin 3428 i:= p1 shl 4 + pDipActive;3429 CallPlayer(cShowSupportAllianceAgainst, p2, i);3428 I := p1 shl 4 + pDipActive; 3429 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3430 3430 end; 3431 3431 for p2 := 0 to nPl - 1 do 3432 3432 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3433 3433 begin 3434 i:= p2;3435 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);3434 I := p2; 3435 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I); 3436 3436 end; 3437 3437 end; 3438 3438 end 3439 3439 else 3440 result := eInvalid;3441 if (Command >= sExecute) and ( result >= rExecuted) then3440 Result := eInvalid; 3441 if (Command >= sExecute) and (Result >= rExecuted) then 3442 3442 if LastEndClientCommand = scDipBreak then 3443 3443 begin // break negotiation … … 3461 3461 end 3462 3462 else 3463 result := eInvalid;3463 Result := eInvalid; 3464 3464 3465 3465 scDipOffer, scDipOffer - sExecute: … … 3474 3474 pDipActive := -1; 3475 3475 CallPlayer(cShowEndContact, pContacted, nil^); 3476 assert(Mode = moPlaying);3476 Assert(Mode = moPlaying); 3477 3477 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3478 3478 end; … … 3487 3487 if RW[pDipActive].Treaty[p1] < trPeace then 3488 3488 begin // no tribute allowed! 3489 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3490 if (TOffer(Data).Price[ i] and opMask = opTribute) then3491 result := eInvalidOffer;3492 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3493 if (TOffer(Data).Price[ i] = opTreaty + trPeace) then3494 result := eOK;3489 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3490 if (TOffer(Data).Price[I] and opMask = opTribute) then 3491 Result := eInvalidOffer; 3492 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3493 if (TOffer(Data).Price[I] = opTreaty + trPeace) then 3494 Result := eOK; 3495 3495 end; 3496 for i:= 0 to TOffer(Data).nDeliver - 1 do3497 if (TOffer(Data).Price[ i] <> opChoose) and3498 not PayPrice(pDipActive, p1, TOffer(Data).Price[ i], false) then3499 result := eInvalidOffer;3496 for I := 0 to TOffer(Data).nDeliver - 1 do 3497 if (TOffer(Data).Price[I] <> opChoose) and 3498 not PayPrice(pDipActive, p1, TOffer(Data).Price[I], False) then 3499 Result := eInvalidOffer; 3500 3500 if CountPrice(TOffer(Data), opTreaty) > 1 then 3501 result := eInvalidOffer;3502 for i:= 0 to nShipPart - 1 do3503 if CountPrice(TOffer(Data), opShipParts + ishl 16) > 1 then3504 result := eInvalidOffer;3501 Result := eInvalidOffer; 3502 for I := 0 to nShipPart - 1 do 3503 if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then 3504 Result := eInvalidOffer; 3505 3505 if CountPrice(TOffer(Data), opMoney) > 1 then 3506 result := eInvalidOffer;3506 Result := eInvalidOffer; 3507 3507 if CountPrice(TOffer(Data), opTribute) > 1 then 3508 result := eInvalidOffer;3508 Result := eInvalidOffer; 3509 3509 case CountPrice(TOffer(Data), opChoose) of 3510 3510 0: … … 3512 3512 1: 3513 3513 if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then 3514 result := eInvalidOffer;3514 Result := eInvalidOffer; 3515 3515 else 3516 result := eInvalidOffer;3516 Result := eInvalidOffer; 3517 3517 end; 3518 3518 3519 3519 // !!! check here if cost can be demanded 3520 3520 3521 if (Command >= sExecute) and ( result >= rExecuted) then3521 if (Command >= sExecute) and (Result >= rExecuted) then 3522 3522 begin 3523 3523 OfferFullySupported := (TOffer(Data).nDeliver <= 2) and 3524 3524 (TOffer(Data).nCost <= 2); // >2 no more allowed 3525 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3525 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3526 3526 begin 3527 if TOffer(Data).Price[ i] and opMask = opTribute then3528 OfferFullySupported := false;3527 if TOffer(Data).Price[I] and opMask = opTribute then 3528 OfferFullySupported := False; 3529 3529 // tribute no more part of the game 3530 if (TOffer(Data).Price[ i] and opMask = opTreaty) and3531 (TOffer(Data).Price[ i] - opTreaty <= RW[pDipActive].Treaty[p1])3530 if (TOffer(Data).Price[I] and opMask = opTreaty) and 3531 (TOffer(Data).Price[I] - opTreaty <= RW[pDipActive].Treaty[p1]) 3532 3532 then 3533 OfferFullySupported := false;3533 OfferFullySupported := False; 3534 3534 // agreed treaty end no more part of the game 3535 if TOffer(Data).Price[ i] = opTreaty + trCeaseFire then3536 OfferFullySupported := false;3535 if TOffer(Data).Price[I] = opTreaty + trCeaseFire then 3536 OfferFullySupported := False; 3537 3537 // ceasefire no more part of the game 3538 3538 end; … … 3559 3559 LastOffer := TOffer(Data); 3560 3560 // show offered things to receiver 3561 for i:= 0 to LastOffer.nDeliver - 1 do3562 ShowPrice(pDipActive, p1, LastOffer.Price[ i]);3561 for I := 0 to LastOffer.nDeliver - 1 do 3562 ShowPrice(pDipActive, p1, LastOffer.Price[I]); 3563 3563 pDipActive := p1; 3564 assert(Mode = moPlaying);3564 Assert(Mode = moPlaying); 3565 3565 ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer, 3566 3566 SizeOf(LastOffer)); … … 3569 3569 end 3570 3570 else 3571 result := eInvalid;3571 Result := eInvalid; 3572 3572 3573 3573 { … … 3582 3582 end 3583 3583 else 3584 result := eInvalid;3584 Result := eInvalid; 3585 3585 3586 3586 sSetTestFlag: … … 3592 3592 end 3593 3593 else 3594 result := eInvalid;3594 Result := eInvalid; 3595 3595 3596 3596 sSetGovernment, sSetGovernment - sExecute: … … 3598 3598 {$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF} 3599 3599 if RW[Player].Happened and phChangeGov = 0 then 3600 result := eViolation3600 Result := eViolation 3601 3601 else if RW[Player].Government = Subject then 3602 result := eNotChanged3602 Result := eNotChanged 3603 3603 else if (Subject >= nGov) then 3604 result := eInvalid3604 Result := eInvalid 3605 3605 else if (Subject >= gMonarchy) and 3606 3606 (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then 3607 result := eNoPreq3607 Result := eNoPreq 3608 3608 else if Command >= sExecute then 3609 3609 begin … … 3620 3620 {$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF} 3621 3621 if Subject and $F + Subject shr 4 > 10 then 3622 result := eInvalid3622 Result := eInvalid 3623 3623 else if (RW[Player].TaxRate = Subject and $F * 10) and 3624 3624 (RW[Player].LuxRate = Subject shr 4 * 10) then 3625 result := eNotChanged3625 Result := eNotChanged 3626 3626 else if Command >= sExecute then 3627 3627 begin … … 3635 3635 {$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF} 3636 3636 if RW[Player].Government = gAnarchy then 3637 result := eInvalid3637 Result := eInvalid 3638 3638 else 3639 3639 begin … … 3657 3657 if (Mode = moPlaying) and (Subject = adMilitary) and 3658 3658 (DevModelTurn[Player] <> GTurn) then 3659 result := eNoModel3659 Result := eNoModel 3660 3660 else if Subject <> adMilitary then 3661 3661 begin … … 3663 3663 begin 3664 3664 if Tech[Subject] >= MaxFutureTech_Computing then 3665 result := eInvalid;3665 Result := eInvalid; 3666 3666 end 3667 3667 else if Subject in FutureTech then 3668 3668 begin 3669 3669 if Tech[Subject] >= MaxFutureTech then 3670 result := eInvalid;3670 Result := eInvalid; 3671 3671 end 3672 3672 else if Tech[Subject] >= tsApplicable then 3673 result := eInvalid; // already discovered3673 Result := eInvalid; // already discovered 3674 3674 if Tech[Subject] <> tsSeen then // look if preqs met 3675 3675 if AdvPreq[Subject, 2] <> preNone then 3676 3676 begin // 2 of 3 required 3677 i:= 0;3678 for j:= 0 to 2 do3679 if Tech[AdvPreq[Subject, j]] >= tsApplicable then3680 inc(i);3681 if i< 2 then3682 result := eNoPreq;3677 I := 0; 3678 for J := 0 to 2 do 3679 if Tech[AdvPreq[Subject, J]] >= tsApplicable then 3680 Inc(I); 3681 if I < 2 then 3682 Result := eNoPreq; 3683 3683 end 3684 3684 else if (AdvPreq[Subject, 0] <> preNone) and … … 3686 3686 (AdvPreq[Subject, 1] <> preNone) and 3687 3687 (Tech[AdvPreq[Subject, 1]] < tsApplicable) then 3688 result := eNoPreq;3688 Result := eNoPreq; 3689 3689 end; 3690 if ( result = eOK) and (Command >= sExecute) then3690 if (Result = eOK) and (Command >= sExecute) then 3691 3691 begin 3692 3692 if (Mode = moPlaying) and (Subject = adMilitary) then … … 3697 3697 end 3698 3698 else 3699 result := eViolation;3699 Result := eViolation; 3700 3700 end; 3701 3701 … … 3705 3705 {$ENDIF} 3706 3706 if RW[Player].Happened and phStealTech = 0 then 3707 result := eInvalid3707 Result := eInvalid 3708 3708 else if (Subject >= nAdv) or (Subject in FutureTech) or 3709 3709 (RW[Player].Tech[Subject] >= tsSeen) or 3710 3710 (RW[GStealFrom].Tech[Subject] < tsApplicable) then 3711 result := eInvalid3711 Result := eInvalid 3712 3712 else if Command >= sExecute then 3713 3713 begin 3714 3714 SeeTech(Player, Subject); 3715 dec(RW[Player].Happened, phStealTech);3715 Dec(RW[Player].Happened, phStealTech); 3716 3716 end; 3717 3717 end; … … 3724 3724 if (Subject >= nAttitude) or (p1 >= nPl) or 3725 3725 (RW[Player].EnemyReport[p1] = nil) then 3726 result := eInvalid3726 Result := eInvalid 3727 3727 else if RW[Player].Treaty[p1] = trNoContact then 3728 result := eNoPreq3728 Result := eNoPreq 3729 3729 else if RW[Player].Attitude[p1] = Subject then 3730 result := eNotChanged3730 Result := eNotChanged 3731 3731 else if Command >= sExecute then 3732 3732 begin … … 3739 3739 if (LastEndClientCommand <> scReject) or 3740 3740 (RW[Player].Treaty[pContacted] < trPeace) then 3741 result := eInvalid3741 Result := eInvalid 3742 3742 else if (ServerVersion[Player] >= $010100) and 3743 3743 (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns) 3744 3744 then 3745 result := eCancelTreatyRush3745 Result := eCancelTreatyRush 3746 3746 else if Command >= sExecute then 3747 3747 begin … … 3751 3751 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3752 3752 begin 3753 i:= pContacted shl 4 + Player;3754 CallPlayer(cShowSupportAllianceAgainst, p2, i);3753 I := pContacted shl 4 + Player; 3754 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3755 3755 end; 3756 3756 for p2 := 0 to nPl - 1 do 3757 3757 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3758 3758 begin 3759 i:= p2;3760 CallPlayer(cShowCancelTreatyByAlliance, Player, i);3759 I := p2; 3760 CallPlayer(cShowCancelTreatyByAlliance, Player, I); 3761 3761 end; 3762 3762 LastEndClientCommand := sTurn; … … 3771 3771 {$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF} 3772 3772 if Subject >= 4 then 3773 result := eInvalid3773 Result := eInvalid 3774 3774 else if (upgrade[Subject, 0].Preq <> preNone) and 3775 3775 (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then 3776 result := eNoPreq3776 Result := eNoPreq 3777 3777 else if Command >= sExecute then 3778 3778 begin … … 3785 3785 Upgrades := 0; 3786 3786 FutureMCost := 0; 3787 for i:= 0 to nUpgrade - 1 do3788 with upgrade[Domain, i] do3787 for I := 0 to nUpgrade - 1 do 3788 with upgrade[Domain, I] do 3789 3789 if (Preq = preNone) or (Preq >= 0) and 3790 3790 ((RW[Player].Tech[Preq] >= tsApplicable) or … … 3793 3793 if Preq in FutureTech then 3794 3794 begin 3795 j:= RW[Player].Tech[Preq];3796 inc(FutureMCost, j* Cost);3795 J := RW[Player].Tech[Preq]; 3796 Inc(FutureMCost, J * Cost); 3797 3797 end 3798 3798 else 3799 3799 begin 3800 j:= 1;3800 J := 1; 3801 3801 if Cost > MCost then 3802 3802 MCost := Cost; 3803 3803 end; 3804 inc(Upgrades, 1 shl i);3805 inc(MStrength, j* Strength);3806 inc(MTrans, j* Trans);3804 Inc(Upgrades, 1 shl I); 3805 Inc(MStrength, J * Strength); 3806 Inc(MTrans, J * Trans); 3807 3807 end; 3808 inc(MCost, FutureMCost);3808 Inc(MCost, FutureMCost); 3809 3809 FillChar(Cap, SizeOf(Cap), 0); 3810 3810 Cap[mcOffense] := 2; 3811 3811 Cap[mcDefense] := 1; 3812 for i:= 0 to nFeature - 1 do3813 with Feature[ i] do3812 for I := 0 to nFeature - 1 do 3813 with Feature[I] do 3814 3814 if (1 shl Domain and Domains <> 0) and 3815 3815 ((Preq = preNone) or (Preq = preSun) and 3816 3816 (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and 3817 (RW[Player].Tech[Preq] >= tsApplicable)) and ( iin AutoFeature)3817 (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature) 3818 3818 then 3819 Cap[ i] := 1;3819 Cap[I] := 1; 3820 3820 MaxWeight := 5; 3821 3821 if (WeightPreq7[Domain] <> preNA) and … … 3839 3839 {$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF} 3840 3840 if Subject >= nFeature then 3841 result := eInvalid3841 Result := eInvalid 3842 3842 else if DevModelTurn[Player] = GTurn then 3843 3843 begin … … 3845 3845 with RW[Player].DevModel do 3846 3846 if 1 shl Domain and Feature[Subject].Domains = 0 then 3847 result := eDomainMismatch3847 Result := eDomainMismatch 3848 3848 else if not((Feature[Subject].Preq = preNone) or 3849 3849 (Feature[Subject].Preq = preSun) and … … 3851 3851 (Feature[Subject].Preq >= 0) and 3852 3852 (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then 3853 result := eNoPreq3853 Result := eNoPreq 3854 3854 else 3855 3855 begin … … 3867 3867 MaxCap := 3; 3868 3868 if RW[Player].Tech[adSteel] >= tsApplicable then 3869 inc(MaxCap);3869 Inc(MaxCap); 3870 3870 end 3871 3871 else … … 3877 3877 if (NewCap < MinCap) or (NewCap > MaxCap) or 3878 3878 (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then 3879 result := eViolation3879 Result := eViolation 3880 3880 else if Command >= sExecute then 3881 3881 begin … … 3920 3920 end 3921 3921 else 3922 result := eNoModel;3922 Result := eNoModel; 3923 3923 end; 3924 3924 … … 3931 3931 {$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3932 3932 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3933 result := eInvalid3933 Result := eInvalid 3934 3934 else 3935 3935 begin 3936 result := eRemoved;3936 Result := eRemoved; 3937 3937 Loc0 := RW[Player].Un[Subject].Loc; 3938 3938 if RealMap[Loc0] and fCity <> 0 then { check utilize } … … 3946 3946 (Project and cpImp = 0) and 3947 3947 (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then 3948 result := eUtilized;3948 Result := eUtilized; 3949 3949 if Command >= sExecute then 3950 3950 begin 3951 if result = eUtilized then3951 if Result = eUtilized then 3952 3952 begin 3953 3953 with RW[Player].Un[Subject] do 3954 3954 begin 3955 Cost := integer(RW[Player].Model[mix].Cost) * Health *3955 Cost := Integer(RW[Player].Model[mix].Cost) * Health * 3956 3956 BuildCostMod[Difficulty[Player]] div 1200; 3957 3957 if RW[Player].Model[mix].Cap[mcLine] > 0 then … … 3959 3959 end; 3960 3960 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 3961 inc(RW[Player].Money, Cost)3961 Inc(RW[Player].Money, Cost) 3962 3962 else 3963 3963 begin 3964 inc(Prod, Cost * 2 div 3);3964 Inc(Prod, Cost * 2 div 3); 3965 3965 Project0 := Project0 and not cpCompleted; 3966 3966 if Project0 and not cpAuto <> Project and not cpAuto then … … 3982 3982 {$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3983 3983 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3984 result := eInvalid3984 Result := eInvalid 3985 3985 else 3986 3986 begin 3987 3987 Loc0 := RW[Player].Un[Subject].Loc; 3988 3988 if RealMap[Loc0] and fCity = 0 then 3989 result := eInvalid3989 Result := eInvalid 3990 3990 else 3991 3991 begin 3992 3992 SearchCity(Loc0, Player, cix1); 3993 3993 if RW[Player].City[cix1].Flags and chCaptured <> 0 then 3994 result := eViolation3994 Result := eViolation 3995 3995 else if Command >= sExecute then 3996 3996 RW[Player].Un[Subject].Home := cix1; … … 4009 4009 {$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4010 4010 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4011 result := eInvalid4011 Result := eInvalid 4012 4012 else 4013 result := LoadUnit(Player, Subject, Command < sExecute);4013 Result := LoadUnit(Player, Subject, Command < sExecute); 4014 4014 end; 4015 4015 … … 4018 4018 {$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4019 4019 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4020 result := eInvalid4020 Result := eInvalid 4021 4021 else 4022 result := UnloadUnit(Player, Subject, Command < sExecute);4022 Result := UnloadUnit(Player, Subject, Command < sExecute); 4023 4023 end; 4024 4024 4025 4025 sSelectTransport, sSelectTransport - sExecute: 4026 4026 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4027 result := eInvalid4027 Result := eInvalid 4028 4028 else 4029 4029 with RW[Player].Model[RW[Player].Un[Subject].mix] do 4030 4030 begin 4031 4031 if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then 4032 result := eInvalid4032 Result := eInvalid 4033 4033 else if Command >= sExecute then 4034 4034 uixSelectedTransport := Subject; … … 4041 4041 begin 4042 4042 p1 := Command shr 4 and $F; 4043 Loc1 := integer(Data);4043 Loc1 := Integer(Data); 4044 4044 if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or 4045 4045 (RealMap[Loc1] and fCity <> 0) and 4046 4046 (RealMap[Loc1] shr 27 <> Cardinal(p1)) or 4047 4047 (RW[p1].Model[Subject].Domain < dAir) and 4048 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[ integer(Data)] and4048 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and 4049 4049 fTerrain < fGrass)) then 4050 result := eViolation4050 Result := eViolation 4051 4051 else if Command >= sExecute then 4052 4052 begin 4053 4053 CreateUnit(p1, Subject); 4054 RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);4054 RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data); 4055 4055 PlaceUnit(p1, RW[p1].nUn - 1); 4056 UpdateUnitMap( integer(Data));4056 UpdateUnitMap(Integer(Data)); 4057 4057 end; 4058 4058 end 4059 4059 else 4060 result := eInvalid;4060 Result := eInvalid; 4061 4061 4062 4062 sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16, … … 4075 4075 {$IFDEF TEXTLOG}CmdInfo := Format('MoveUnit P%d I%d Mod%d Loc%d (%d,%d)', [Player, Subject, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc, dx, dy]); {$ENDIF} 4076 4076 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4077 result := eInvalid4077 Result := eInvalid 4078 4078 else 4079 result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);4079 Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute); 4080 4080 end; 4081 4081 … … 4088 4088 {$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4089 4089 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4090 result := eInvalid4090 Result := eInvalid 4091 4091 else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind 4092 4092 in [mkSettler, mkSlaves]) and 4093 4093 (RW[Player].Un[Subject].Flags and unConscripts = 0) then 4094 result := eViolation4094 Result := eViolation 4095 4095 else 4096 4096 begin 4097 4097 Loc0 := RW[Player].Un[Subject].Loc; 4098 4098 if RealMap[Loc0] and fCity = 0 then 4099 result := eInvalid4099 Result := eInvalid 4100 4100 else 4101 4101 begin … … 4103 4103 with RW[Player].City[cix1] do 4104 4104 if not CanCityGrow(Player, cix1) then 4105 result := eMaxSize4105 Result := eMaxSize 4106 4106 else if Command >= sExecute then 4107 4107 begin { add to city } … … 4123 4123 begin 4124 4124 Loc0 := RW[Player].Un[Subject].Loc; 4125 i:= Command shr 4 and $3F; // new job4126 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, i]); {$ENDIF}4125 I := Command shr 4 and $3F; // new job 4126 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, I]); {$ENDIF} 4127 4127 if (Subject >= RW[Player].nUn) or (Loc0 < 0) then 4128 result := eInvalid4129 else if i>= nJob then4130 result := eInvalid4128 Result := eInvalid 4129 else if I >= nJob then 4130 Result := eInvalid 4131 4131 else 4132 4132 begin 4133 result := StartJob(Player, Subject, i, Command < sExecute);4134 if result = eCity then4133 Result := StartJob(Player, Subject, I, Command < sExecute); 4134 if Result = eCity then 4135 4135 begin // new city 4136 4136 cix1 := RW[Player].nCity - 1; … … 4157 4157 sSetCityProject, sSetCityProject - sExecute: 4158 4158 begin 4159 NewProject := integer(Data) and not cpAuto;4159 NewProject := Integer(Data) and not cpAuto; 4160 4160 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF} 4161 4161 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4162 4162 then 4163 result := eInvalid4163 Result := eInvalid 4164 4164 else 4165 4165 with RW[Player].City[Subject] do 4166 4166 begin 4167 4167 if NewProject = Project then 4168 result := eNotChanged4168 Result := eNotChanged 4169 4169 else 4170 4170 begin … … 4174 4174 begin 4175 4175 if NewProject and cpIndex >= RW[Player].nModel then 4176 result := eInvalid4176 Result := eInvalid 4177 4177 else if (NewProject and cpConscripts <> 0) and 4178 4178 not((RW[Player].Tech[adConscription] >= tsApplicable) and … … 4180 4180 and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout)) 4181 4181 then 4182 result := eViolation4182 Result := eViolation 4183 4183 // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves) 4184 4184 // and (GWonder[woPyramids].EffectiveOwner<>Player) then … … 4186 4186 end 4187 4187 else if NewProject and cpIndex >= nImp then 4188 result := eInvalid4188 Result := eInvalid 4189 4189 else 4190 4190 begin 4191 4191 Preq := Imp[NewProject and cpIndex].Preq; 4192 for i:= 0 to nImpReplacement - 1 do4193 if (ImpReplacement[ i].OldImp = NewProject and cpIndex) and4194 (built[ImpReplacement[ i].NewImp] > 0) then4195 result := eObsolete;4196 if result = eObsolete then4192 for I := 0 to nImpReplacement - 1 do 4193 if (ImpReplacement[I].OldImp = NewProject and cpIndex) and 4194 (built[ImpReplacement[I].NewImp] > 0) then 4195 Result := eObsolete; 4196 if Result = eObsolete then 4197 4197 else if Preq = preNA then 4198 result := eInvalid4198 Result := eInvalid 4199 4199 else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable) 4200 4200 then 4201 result := eNoPreq4201 Result := eNoPreq 4202 4202 else if built[NewProject and cpIndex] > 0 then 4203 result := eInvalid4203 Result := eInvalid 4204 4204 else if (NewProject and cpIndex < nWonder) and 4205 4205 (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then 4206 result := eViolation // wonder already exists4206 Result := eViolation // wonder already exists 4207 4207 else if (NewProject and cpIndex = imSpacePort) and 4208 4208 (RW[Player].NatBuilt[imSpacePort] > 0) then 4209 result := eViolation // space port already exists4209 Result := eViolation // space port already exists 4210 4210 else if (NewProject = cpImp + imBank) and (built[imMarket] = 0) 4211 4211 or (NewProject = cpImp + imUniversity) and … … 4213 4213 (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant) 4214 4214 and (built[imFactory] = 0) then 4215 result := eNoPreq;4215 Result := eNoPreq; 4216 4216 case NewProject - cpImp of 4217 4217 woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform: … … 4224 4224 if (Loc1 >= 0) and (Loc1 < MapSize) and 4225 4225 (RealMap[Loc1] and fTerrain = fShore) then 4226 inc(Preq);4226 Inc(Preq); 4227 4227 end; 4228 4228 if Preq = 0 then 4229 result := eNoPreq;4229 Result := eNoPreq; 4230 4230 end; 4231 4231 woHoover, imHydro: … … 4239 4239 ((RealMap[Loc1] and fTerrain = fMountains) or 4240 4240 (RealMap[Loc1] and fRiver <> 0)) then 4241 inc(Preq);4241 Inc(Preq); 4242 4242 end; 4243 4243 if Preq = 0 then 4244 result := eNoPreq;4244 Result := eNoPreq; 4245 4245 end; 4246 4246 woMIR, imShipComp, imShipPow, imShipHab: 4247 4247 if RW[Player].NatBuilt[imSpacePort] = 0 then 4248 result := eNoPreq;4248 Result := eNoPreq; 4249 4249 end; 4250 4250 if (GTestFlags and tfNoRareNeed = 0) and 4251 4251 (Imp[NewProject and cpIndex].Kind = ikShipPart) then 4252 4252 if RW[Player].Tech[adMassProduction] < tsApplicable then 4253 result := eNoPreq4253 Result := eNoPreq 4254 4254 else 4255 4255 begin // check for rare resources 4256 4256 if NewProject and cpIndex = imShipComp then 4257 j:= 14257 J := 1 4258 4258 else if NewProject and cpIndex = imShipPow then 4259 j:= 24259 J := 2 4260 4260 else { if NewProject and cpIndex=imShipHab then } 4261 j:= 3;4261 J := 3; 4262 4262 // j = rare resource required 4263 4263 Preq := 0; … … 4267 4267 Loc1 := Radius[V21]; 4268 4268 if (Loc1 >= 0) and (Loc1 < MapSize) and 4269 (RealMap[Loc1] shr 25 and 3 = Cardinal( j)) then4270 inc(Preq);4269 (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then 4270 Inc(Preq); 4271 4271 end; 4272 4272 if Preq = 0 then 4273 result := eNoPreq;4273 Result := eNoPreq; 4274 4274 end; 4275 4275 end; 4276 4276 4277 if (Command >= sExecute) and ( result >= rExecuted) then4277 if (Command >= sExecute) and (Result >= rExecuted) then 4278 4278 begin 4279 4279 if pt0 <> ptSelect then … … 4284 4284 and (pt0 <> ptCaravan) then 4285 4285 begin 4286 inc(RW[Player].Money, Prod0);4286 Inc(RW[Player].Money, Prod0); 4287 4287 Prod := 0; 4288 4288 Prod0 := 0; … … 4291 4291 else 4292 4292 Prod := Prod0 * 2 div 3; 4293 Project := NewProject 4293 Project := NewProject; 4294 4294 end; 4295 4295 end; … … 4302 4302 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4303 4303 then 4304 result := eInvalid4304 Result := eInvalid 4305 4305 else 4306 4306 with RW[Player].City[Subject] do 4307 4307 if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0) 4308 4308 then 4309 result := eOutOfControl4309 Result := eOutOfControl 4310 4310 else if (Project and cpImp <> 0) and 4311 4311 ((Project and cpIndex = imTrGoods) or 4312 4312 (Imp[Project and cpIndex].Kind = ikShipPart)) then 4313 result := eInvalid // don't buy colony ship4313 Result := eInvalid // don't buy colony ship 4314 4314 else 4315 4315 begin … … 4330 4330 Cost := Cost * 4; 4331 4331 if Cost <= 0 then 4332 result := eNotChanged4332 Result := eNotChanged 4333 4333 else if Cost > RW[Player].Money then 4334 result := eViolation4334 Result := eViolation 4335 4335 else if Command >= sExecute then 4336 4336 IntServer(sIntBuyMaterial, Player, Subject, Cost); … … 4345 4345 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4346 4346 then 4347 result := eInvalid4347 Result := eInvalid 4348 4348 else if Command >= sExecute then 4349 4349 with RW[Player].City[Subject] do 4350 4350 begin 4351 inc(RW[Player].Money, Prod0);4351 Inc(RW[Player].Money, Prod0); 4352 4352 Prod := 0; 4353 4353 Prod0 := 0; … … 4357 4357 sSellCityImprovement, sSellCityImprovement - sExecute: 4358 4358 begin 4359 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}4359 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF} 4360 4360 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4361 4361 then 4362 result := eInvalid4362 Result := eInvalid 4363 4363 else 4364 4364 with RW[Player].City[Subject] do 4365 if built[ integer(Data)] = 0 then4366 result := eInvalid4365 if built[Integer(Data)] = 0 then 4366 Result := eInvalid 4367 4367 else if (RW[Player].Government = gAnarchy) or 4368 4368 (Flags and chCaptured <> 0) then 4369 result := eOutOfControl4369 Result := eOutOfControl 4370 4370 else if Flags and chImprovementSold <> 0 then 4371 result := eOnlyOnce4371 Result := eOnlyOnce 4372 4372 else if Command >= sExecute then 4373 4373 begin 4374 inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod4374 Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod 4375 4375 [Difficulty[Player]] div 12); 4376 built[ integer(Data)] := 0;4377 if Imp[ integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then4376 built[Integer(Data)] := 0; 4377 if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then 4378 4378 begin 4379 RW[Player].NatBuilt[ integer(Data)] := 0;4380 case integer(Data) of4379 RW[Player].NatBuilt[Integer(Data)] := 0; 4380 case Integer(Data) of 4381 4381 imGrWall: 4382 4382 GrWallContinent[Player] := -1; … … 4385 4385 end; 4386 4386 end; 4387 inc(Flags, chImprovementSold);4387 Inc(Flags, chImprovementSold); 4388 4388 end; 4389 4389 end; … … 4391 4391 sRebuildCityImprovement, sRebuildCityImprovement - sExecute: 4392 4392 begin 4393 OldImp := integer(Data);4393 OldImp := Integer(Data); 4394 4394 {$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF} 4395 4395 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4396 4396 then 4397 result := eInvalid4397 Result := eInvalid 4398 4398 else 4399 4399 begin 4400 4400 if (OldImp < 0) or (OldImp >= nImp) or 4401 4401 not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then 4402 result := eInvalid4402 Result := eInvalid 4403 4403 else 4404 4404 with RW[Player].City[Subject] do … … 4406 4406 not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal, 4407 4407 ikNatGlobal]) then 4408 result := eInvalid4408 Result := eInvalid 4409 4409 else if (RW[Player].Government = gAnarchy) or 4410 4410 (Flags and chCaptured <> 0) then 4411 result := eOutOfControl4411 Result := eOutOfControl 4412 4412 else if Flags and chImprovementSold <> 0 then 4413 result := eOnlyOnce4413 Result := eOnlyOnce 4414 4414 else if Command >= sExecute then 4415 4415 begin 4416 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]4416 Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]] 4417 4417 div 12 * 2 div 3); 4418 4418 Project0 := Project0 and not cpCompleted; … … 4431 4431 end; 4432 4432 end; 4433 inc(Flags, chImprovementSold);4433 Inc(Flags, chImprovementSold); 4434 4434 end; 4435 4435 end; … … 4438 4438 sSetCityTiles, sSetCityTiles - sExecute: 4439 4439 begin 4440 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}4440 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF} 4441 4441 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4442 4442 then 4443 result := eInvalid4443 Result := eInvalid 4444 4444 else 4445 result := SetCityTiles(Player, Subject, integer(Data),4445 Result := SetCityTiles(Player, Subject, Integer(Data), 4446 4446 Command < sExecute); 4447 4447 end; … … 4460 4460 end 4461 4461 else 4462 result := eUnknown;4462 Result := eUnknown; 4463 4463 end; { case command } 4464 4464 4465 4465 // do not log invalid and non-relevant commands 4466 if result = eZOC_EnemySpotted then4466 if Result = eZOC_EnemySpotted then 4467 4467 begin 4468 assert(Mode = moPlaying);4468 Assert(Mode = moPlaying); 4469 4469 CL.State := FormerCLState; 4470 4470 IntServer(sIntDiscoverZOC, Player, 0, ZOCTile); 4471 4471 end 4472 else if result and rEffective = 0 then4472 else if Result and rEffective = 0 then 4473 4473 if Mode < moPlaying then 4474 4474 begin 4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [ result]) + CmdInfo;4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo; 4476 4476 {$ENDIF} 4477 LoadOK := false;4477 LoadOK := False; 4478 4478 end 4479 4479 else … … 4481 4481 if logged then 4482 4482 CL.State := FormerCLState; 4483 if ( result < rExecuted) and (Command >= sExecute) then4483 if (Result < rExecuted) and (Command >= sExecute) then 4484 4484 PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)', 4485 4485 [Player, Command, Subject])); … … 4487 4487 4488 4488 if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient) 4489 and ( result >= rExecuted) then4489 and (Result >= rExecuted) then 4490 4490 LastEndClientCommand := Command; 4491 {$IFOPT O-} dec(nHandoverStack, 2); {$ENDIF}4491 {$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF} 4492 4492 end; 4493 4493 -
trunk/Global.pas
r417 r447 28 28 end. 29 29 30 -
trunk/IPQ.pas
r442 r447 1 1 { binary heap priority queue 2 code contributed by Rassim Eminli }2 Code contributed by Rassim Eminli } 3 3 4 4 {$INCLUDE Switches.inc} … … 8 8 9 9 type 10 TIntegerArray = array [0 .. $40000000 div sizeof(integer)] of integer;10 TIntegerArray = array [0 .. $40000000 div SizeOf(Integer)] of Integer; 11 11 PIntegerArray = ^TIntegerArray; 12 12 13 13 TheapItem = record 14 Item: integer;15 Value: integer;14 Item: Integer; 15 Value: Integer; 16 16 end; 17 17 18 TItemArray = array [0 .. $40000000 div sizeof(TheapItem)] of TheapItem;18 TItemArray = array [0 .. $40000000 div SizeOf(TheapItem)] of TheapItem; 19 19 PItemArray = ^TItemArray; 20 20 21 21 TIPQ = class 22 constructor Create( max: integer);22 constructor Create(Max: Integer); 23 23 destructor Destroy; override; 24 24 procedure Empty; 25 function Put(Item, Value: integer): boolean;26 function TestPut(Item, Value: integer): boolean;27 function Get(var Item, Value: integer): boolean;25 function Put(Item, Value: Integer): Boolean; 26 function TestPut(Item, Value: Integer): Boolean; 27 function Get(var Item, Value: Integer): Boolean; 28 28 private 29 29 // n - is the size of the heap. 30 30 // fmax - is the max size of the heap. 31 n, fmax: integer;31 N, fmax: Integer; 32 32 33 33 // bh - stores (Value, Item) pairs of the heap. … … 39 39 implementation 40 40 41 constructor TIPQ.Create( max: integer);41 constructor TIPQ.Create(Max: Integer); 42 42 begin 43 43 inherited Create; 44 fmax := max;45 GetMem(bh, fmax * sizeof(TheapItem));46 GetMem(Ix, fmax * sizeof(integer));47 n:= -1;44 fmax := Max; 45 GetMem(bh, fmax * SizeOf(TheapItem)); 46 GetMem(Ix, fmax * SizeOf(Integer)); 47 N := -1; 48 48 Empty; 49 49 end; … … 58 58 procedure TIPQ.Empty; 59 59 begin 60 if n<> 0 then60 if N <> 0 then 61 61 begin 62 FillChar(Ix^, fmax * sizeof(integer), 255);63 n:= 0;62 FillChar(Ix^, fmax * SizeOf(Integer), 255); 63 N := 0; 64 64 end; 65 65 end; 66 66 67 67 // Parent(i) = (i-1)/2. 68 function TIPQ.Put(Item, Value: integer): boolean; // O(lg(n))68 function TIPQ.Put(Item, Value: Integer): Boolean; // O(lg(n)) 69 69 var 70 i, j: integer;70 I, J: Integer; 71 71 lbh: PItemArray; 72 72 lIx: PIntegerArray; … … 74 74 lIx := Ix; 75 75 lbh := bh; 76 i:= lIx[Item];77 if i>= 0 then76 I := lIx[Item]; 77 if I >= 0 then 78 78 begin 79 if lbh[ i].Value <= Value then79 if lbh[I].Value <= Value then 80 80 begin 81 result := False;82 exit;81 Result := False; 82 Exit; 83 83 end; 84 84 end 85 85 else 86 86 begin 87 i := n;88 Inc( n);87 I := N; 88 Inc(N); 89 89 end; 90 90 91 while i> 0 do91 while I > 0 do 92 92 begin 93 j := (i- 1) shr 1; // Parent(i) = (i-1)/294 if Value >= lbh[ j].Value then95 break;96 lbh[ i] := lbh[j];97 lIx[lbh[ i].Item] := i;98 i := j;93 J := (I - 1) shr 1; // Parent(i) = (i-1)/2 94 if Value >= lbh[J].Value then 95 Break; 96 lbh[I] := lbh[J]; 97 lIx[lbh[I].Item] := I; 98 I := J; 99 99 end; 100 100 // Insert the new Item at the insertion point found. 101 lbh[ i].Value := Value;102 lbh[ i].Item := Item;103 lIx[lbh[ i].Item] := i;104 result := True;101 lbh[I].Value := Value; 102 lbh[I].Item := Item; 103 lIx[lbh[I].Item] := I; 104 Result := True; 105 105 end; 106 106 107 function TIPQ.TestPut(Item, Value: integer): boolean;107 function TIPQ.TestPut(Item, Value: Integer): Boolean; 108 108 var 109 i: integer;109 I: Integer; 110 110 begin 111 i:= Ix[Item];112 result := (i < 0) or (bh[i].Value > Value);111 I := Ix[Item]; 112 Result := (I < 0) or (bh[I].Value > Value); 113 113 end; 114 114 115 115 // Left(i) = 2*i+1. 116 116 // Right(i) = 2*i+2 => Left(i)+1 117 function TIPQ.Get(var Item, Value: integer): boolean; // O(lg(n))117 function TIPQ.Get(var Item, Value: Integer): Boolean; // O(lg(n)) 118 118 var 119 i, j: integer;120 last: TheapItem;119 I, J: Integer; 120 Last: TheapItem; 121 121 lbh: PItemArray; 122 122 begin 123 if n= 0 then123 if N = 0 then 124 124 begin 125 result := False;126 exit;125 Result := False; 126 Exit; 127 127 end; 128 128 … … 133 133 Ix[Item] := -1; 134 134 135 dec(n);136 if n> 0 then135 Dec(N); 136 if N > 0 then 137 137 begin 138 last := lbh[n];139 i:= 0;140 j:= 1;141 while j < ndo138 Last := lbh[N]; 139 I := 0; 140 J := 1; 141 while J < N do 142 142 begin 143 143 // Right(i) = Left(i)+1 144 if ( j < n - 1) and (lbh[j].Value > lbh[j+ 1].Value) then145 Inc( j);146 if last.Value <= lbh[j].Value then147 break;144 if (J < N - 1) and (lbh[J].Value > lbh[J + 1].Value) then 145 Inc(J); 146 if Last.Value <= lbh[J].Value then 147 Break; 148 148 149 lbh[ i] := lbh[j];150 Ix[lbh[ i].Item] := i;151 i := j;152 j := jshl 1 + 1; // Left(j) = 2*j+1149 lbh[I] := lbh[J]; 150 Ix[lbh[I].Item] := I; 151 I := J; 152 J := J shl 1 + 1; // Left(j) = 2*j+1 153 153 end; 154 154 155 155 // Insert the root in the correct place in the heap. 156 lbh[ i] := last;157 Ix[ last.Item] := i;156 lbh[I] := Last; 157 Ix[Last.Item] := I; 158 158 end; 159 result := True;159 Result := True; 160 160 end; 161 161 -
trunk/Inp.pas
r442 r447 21 21 procedure CenterToRect(Rect: TRect); 22 22 private 23 Center: boolean;23 Center: Boolean; 24 24 end; 25 25 … … 54 54 9, Caption); 55 55 { Corner(canvas,1,1,0,MainTexture); 56 Corner( canvas,ClientWidth-9,1,1,MainTexture);57 Corner( canvas,1,ClientHeight-9,2,MainTexture);58 Corner( canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); }56 Corner(Canvas,ClientWidth-9,1,1,MainTexture); 57 Corner(Canvas,1,ClientHeight-9,2,MainTexture); 58 Corner(Canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); } 59 59 end; 60 60 -
trunk/LocalPlayer/Battle.pas
r442 r447 32 32 uix, ToLoc: Integer; 33 33 Forecast: TBattleForecastEx; 34 IsSuicideQuery: boolean;34 IsSuicideQuery: Boolean; 35 35 end; 36 36 … … 63 63 TextSize: TSize; 64 64 LabelText: string; 65 FirstStrike: boolean;65 FirstStrike: Boolean; 66 66 begin 67 67 MaxBar := 65; … … 196 196 BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66, 197 197 ym + 8 + 12); 198 MakeUnitInfo( me, MyUn[uix], UnitInfo);198 MakeUnitInfo(Me, MyUn[uix], UnitInfo); 199 199 UnitInfo.Flags := UnitInfo.Flags and not unFortified; 200 200 IsoMap.PaintUnit(1, 0, UnitInfo, 0); … … 216 216 ClientWidth := 300; 217 217 ClientHeight := 288; 218 OKBtn.Visible := true;219 CancelBtn.Visible := true;218 OKBtn.Visible := True; 219 CancelBtn.Visible := True; 220 220 Left := (Screen.Width - ClientWidth) div 2; // center on screen 221 221 Top := (Screen.Height - ClientHeight) div 2; … … 225 225 ClientWidth := 178; 226 226 ClientHeight := 178; 227 OKBtn.Visible := false;228 CancelBtn.Visible := false;227 OKBtn.Visible := False; 228 CancelBtn.Visible := False; 229 229 end; 230 230 end; … … 232 232 procedure TBattleDlg.FormPaint(Sender: TObject); 233 233 var 234 ym, cix, p: Integer;235 s, s1: string;234 ym, cix, P: Integer; 235 S, s1: string; 236 236 begin 237 237 with Canvas do … … 253 253 begin 254 254 Canvas.Font.Assign(UniFont[ftCaption]); 255 s:= Phrases.Lookup('TITLE_SUICIDE');256 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,257 7 + Border, s);255 S := Phrases.Lookup('TITLE_SUICIDE'); 256 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 257 7 + Border, S); 258 258 Canvas.Font.Assign(UniFont[ftNormal]); 259 s:= Phrases.Lookup('SUICIDE');260 p := pos('\', s);261 if p= 0 then262 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))263 div 2, 205, s)259 S := Phrases.Lookup('SUICIDE'); 260 P := Pos('\', S); 261 if P = 0 then 262 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) 263 div 2, 205, S) 264 264 else 265 265 begin 266 s1 := copy(s, 1, p- 1);266 s1 := Copy(S, 1, P - 1); 267 267 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2, 268 268 205 - MessageLineSpacing div 2, s1); 269 s1 := copy(s, p+ 1, 255);269 s1 := Copy(S, P + 1, 255); 270 270 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2, 271 271 205 + (MessageLineSpacing - MessageLineSpacing div 2), s1); -
trunk/LocalPlayer/CityScreen.pas
r442 r447 39 39 procedure FormDestroy(Sender: TObject); 40 40 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 41 Shift: TShiftState; x, y: integer);41 Shift: TShiftState; X, Y: Integer); 42 42 procedure BuyClick(Sender: TObject); 43 43 procedure CloseBtnClick(Sender: TObject); … … 53 53 procedure PageDownBtnClick(Sender: TObject); 54 54 private 55 c: TCity;55 C: TCity; 56 56 Report: TCityReportNew; 57 57 cOwner: Integer; … … 70 70 Optimize_cixTileChange: Integer; 71 71 Optimize_TilesBeforeChange: Integer; 72 Happened: cardinal;73 imix: array [0 .. 15] of integer;72 Happened: Cardinal; 73 imix: array [0 .. 15] of Integer; 74 74 CityAreaInfo: TCityAreaInfo; 75 75 AreaMap: TIsoMap; … … 89 89 procedure InitZoomCityMap; 90 90 procedure ChooseProject; 91 procedure ChangeCity( d: integer);92 procedure ChangeResourceWeights(iResourceWeights: integer);91 procedure ChangeCity(D: Integer); 92 procedure ChangeResourceWeights(iResourceWeights: Integer); 93 93 procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND; 94 94 public … … 96 96 CloseAction: TCityCloseAction; 97 97 procedure OffscreenPaint; override; 98 procedure ShowNewContent(NewMode: TWindowMode; Loc: integer; ShowEvent: cardinal);98 procedure ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal); 99 99 procedure Reset; 100 100 procedure CheckAge; … … 202 202 NoMap := TIsoMap.Create; 203 203 AreaMap := TIsoMap.Create; 204 AreaMap.SetOutput( offscreen);204 AreaMap.SetOutput(Offscreen); 205 205 AreaMap.SetPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192, 206 206 ymArea + 96); … … 293 293 procedure TCityDlg.InitSmallCityMap; 294 294 var 295 i, iix, cli1, Color0, Color1, Color2: integer;295 I, iix, cli1, Color0, Color1, Color2: Integer; 296 296 begin 297 297 if cix >= 0 then 298 c:= MyCity[cix];298 C := MyCity[cix]; 299 299 case MyMap[cLoc] and fTerrain of 300 300 fPrairie: cli1 := cliPrairie; … … 329 329 begin 330 330 Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImp]; 331 for i:= 0 to 29 do331 for I := 0 to 29 do 332 332 begin 333 333 for iix := nWonder to nImp - 1 do 334 if (ImpPosition[iix] = i) and (c.Built[iix] > 0) then334 if (ImpPosition[iix] = I) and (C.Built[iix] > 0) then 335 335 begin 336 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),337 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),338 11 + 12 * ( imod 18 div 3)));339 break;336 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 337 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 338 11 + 12 * (I mod 18 div 3))); 339 Break; 340 340 end; 341 341 end; 342 i:= 30;342 I := 30; 343 343 for iix := 0 to nImp do 344 if ( c.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then344 if (C.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then 345 345 begin 346 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),347 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),348 11 + 12 * ( imod 18 div 3)));349 inc(i);350 if i= 36 then351 break; // area is full346 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 347 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 348 11 + 12 * (I mod 18 div 3))); 349 Inc(I); 350 if I = 36 then 351 Break; // area is full 352 352 end; 353 if c.Project and cpImp <> 0 then354 begin 355 iix := c.Project and cpIndex;353 if C.Project and cpImp <> 0 then 354 begin 355 iix := C.Project and cpIndex; 356 356 if iix <> imTrGoods then 357 357 begin 358 358 if (iix >= nWonder) and (ImpPosition[iix] >= 0) then 359 i:= ImpPosition[iix];360 if i< 36 then359 I := ImpPosition[iix]; 360 if I < 36 then 361 361 begin 362 brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];363 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),364 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),365 11 + 12 * ( imod 18 div 3)));362 Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject]; 363 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 364 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 365 11 + 12 * (I mod 18 div 3))); 366 366 end; 367 367 end; 368 368 end; 369 brush.style := bsClear;369 Brush.style := bsClear; 370 370 end; 371 371 end; … … 384 384 112 * (ZoomArea - 3), wZoomMap - wZoomEnvironment, hZoomMap); 385 385 ImageOp_B(ZoomCityMap, CityMapTemplate, wZoomMap - wZoomEnvironment, 0, 386 1504 + wZoomEnvironment * byte(IsPort), 112 * (ZoomArea - 3),386 1504 + wZoomEnvironment * Byte(IsPort), 112 * (ZoomArea - 3), 387 387 wZoomEnvironment, hZoomMap); 388 388 end; … … 392 392 procedure TCityDlg.OffscreenPaint; 393 393 394 procedure FillBar( x, y, pos, Growth, max, Kind: integer;395 IndicateComplete: boolean);394 procedure FillBar(X, Y, Pos, Growth, Max, Kind: Integer; 395 IndicateComplete: Boolean); 396 396 begin 397 397 BarTex.Assign(MainTexture); … … 400 400 BarTex.ColorBevelShade := BarTex.ColorBevelLight; 401 401 end; 402 PaintRelativeProgressBar( offscreen.Canvas, Kind, x - 3, y, wBar - 4, pos,403 Growth, max, IndicateComplete, BarTex);404 end; 405 406 procedure PaintResources( x, y, Loc: integer; Add4Happy: boolean);402 PaintRelativeProgressBar(Offscreen.Canvas, Kind, X - 3, Y, wBar - 4, Pos, 403 Growth, Max, IndicateComplete, BarTex); 404 end; 405 406 procedure PaintResources(X, Y, Loc: Integer; Add4Happy: Boolean); 407 407 var 408 d, i, Total, xGr, yGr: integer;408 D, I, Total, xGr, yGr: Integer; 409 409 TileInfo: TTileInfo; 410 rare: boolean;410 rare: Boolean; 411 411 begin 412 412 with AreaMap do begin 413 if Server(sGetCityTileInfo, me, Loc, TileInfo) <> eOk then414 begin 415 assert(cix < 0);416 exit413 if Server(sGetCityTileInfo, Me, Loc, TileInfo) <> eOk then 414 begin 415 Assert(cix < 0); 416 Exit 417 417 end; 418 418 Total := TileInfo.Food + TileInfo.Prod + TileInfo.Trade; 419 419 rare := MyMap[Loc] and $06000000 > 0; 420 420 if rare then 421 inc(Total);421 Inc(Total); 422 422 if Add4Happy then 423 inc(Total, 4);423 Inc(Total, 4); 424 424 if Total > 1 then 425 d:= (xxt - 11) div (Total - 1);426 if d< 1 then427 d:= 1;428 if d> 4 then429 d:= 4;430 for i:= 0 to Total - 1 do425 D := (xxt - 11) div (Total - 1); 426 if D < 1 then 427 D := 1; 428 if D > 4 then 429 D := 4; 430 for I := 0 to Total - 1 do 431 431 begin 432 432 yGr := 115; 433 if Add4Happy and ( i>= Total - 4) then433 if Add4Happy and (I >= Total - 4) then 434 434 begin 435 435 xGr := 132; 436 436 yGr := 126 437 437 end 438 else if rare and ( i= Total - 1) then438 else if rare and (I = Total - 1) then 439 439 xGr := 66 + 110 440 else if i>= TileInfo.Food + TileInfo.Prod then440 else if I >= TileInfo.Food + TileInfo.Prod then 441 441 xGr := 66 + 44 442 else if i>= TileInfo.Prod then442 else if I >= TileInfo.Prod then 443 443 xGr := 66 444 444 else 445 445 xGr := 66 + 22; 446 Sprite( offscreen, HGrSystem, x + xxt - 5 + d * (2 * i+ 1 - Total),447 y+ yyt - 5, 10, 10, xGr, yGr);446 Sprite(Offscreen, HGrSystem, X + xxt - 5 + D * (2 * I + 1 - Total), 447 Y + yyt - 5, 10, 10, xGr, yGr); 448 448 end; 449 449 end; 450 450 end; 451 451 var 452 line, MessageCount: integer;453 454 procedure CheckMessage(Flag: integer);452 Line, MessageCount: Integer; 453 454 procedure CheckMessage(Flag: Integer); 455 455 var 456 i, test: integer;457 s: string;456 I, Test: Integer; 457 S: string; 458 458 begin 459 459 if Happened and Flag <> 0 then 460 460 begin 461 i:= 0;462 test := 1;463 while test < Flag do461 I := 0; 462 Test := 1; 463 while Test < Flag do 464 464 begin 465 inc(i);466 inc(test, test)465 Inc(I); 466 Inc(Test, Test); 467 467 end; 468 468 469 469 if AllowChange and (Sounds <> nil) and (OpenSoundEvent = -1) then 470 470 begin 471 s := CityEventSoundItem[i];472 if s<> '' then473 s := Sounds.Lookup(s);474 if (Flag = chProduction) or ( s <> '') and (s[1] <> '*') and (s[1] <> '[')471 S := CityEventSoundItem[I]; 472 if S <> '' then 473 S := Sounds.Lookup(S); 474 if (Flag = chProduction) or (S <> '') and (S[1] <> '*') and (S[1] <> '[') 475 475 then 476 OpenSoundEvent := i476 OpenSoundEvent := I; 477 477 end; 478 478 479 s := CityEventName(i);479 S := CityEventName(I); 480 480 { if Flag=chNoGrowthWarning then 481 if c.Built[imAqueduct]=0 then482 s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])483 else s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }484 RisedTextOut( offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +485 16 * line, s);486 inc(line)481 if C.Built[imAqueduct]=0 then 482 S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)]) 483 else S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); } 484 RisedTextOut(Offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount + 485 16 * Line, S); 486 Inc(Line); 487 487 end; 488 488 end; 489 489 490 490 var 491 x, y, xGr, i, j, iix, d, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,491 X, Y, xGr, I, J, iix, D, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix, 492 492 HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: Integer; 493 493 av: Integer; 494 PrName, s: string;494 PrName, S: string; 495 495 UnitInfo: TUnitInfo; 496 496 UnitReport: TUnitReport; … … 499 499 inherited; 500 500 if cix >= 0 then 501 c:= MyCity[cix];501 C := MyCity[cix]; 502 502 Report.HypoTiles := -1; 503 503 Report.HypoTaxRate := -1; 504 504 Report.HypoLuxuryRate := -1; 505 505 if cix >= 0 then 506 Server(sGetCityReportNew, me, cix, Report) // own city506 Server(sGetCityReportNew, Me, cix, Report) // own city 507 507 else 508 Server(sGetEnemyCityReportNew, me, cLoc, Report); // enemy city509 TrueFood := c.Food;510 TrueProd := c.Prod;511 TruePoll := c.Pollution;508 Server(sGetEnemyCityReportNew, Me, cLoc, Report); // enemy city 509 TrueFood := C.Food; 510 TrueProd := C.Prod; 511 TruePoll := C.Pollution; 512 512 if Supervising or (cix < 0) then 513 513 begin // normalize city from after-turn state … … 522 522 TruePoll := 0; // shouldn't happen 523 523 end; 524 IsCityAlive := (cGov <> gAnarchy) and ( c.Flags and chCaptured = 0);524 IsCityAlive := (cGov <> gAnarchy) and (C.Flags and chCaptured = 0); 525 525 if not IsCityAlive then 526 Report.Working := c.Size;526 Report.Working := C.Size; 527 527 528 528 RedTex.Assign(MainTexture); … … 532 532 RedTex.ColorTextShade := $0000FF; 533 533 534 BitBltCanvas( offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);534 BitBltCanvas(Offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0); 535 535 536 536 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); … … 544 544 Brush.style := bsClear; 545 545 Font.Color := $000000; 546 s := IntToStr(c.Size);547 TextOut(8 + 14 - TextWidth( s) div 2, 7, s);546 S := IntToStr(C.Size); 547 TextOut(8 + 14 - TextWidth(S) div 2, 7, S); 548 548 end; 549 549 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); … … 553 553 MakeRed(Offscreen, 18, 280, 298, 40); 554 554 if cGov = gAnarchy then 555 s:= Phrases.Lookup('GOVERNMENT', gAnarchy)555 S := Phrases.Lookup('GOVERNMENT', gAnarchy) 556 556 else { if c.Flags and chCaptured<>0 then } 557 s:= Phrases.Lookup('CITYEVENTS', 14);558 RisedTextOut( offscreen.Canvas, 167 - BiColorTextWidth(offscreen.Canvas, s)559 div 2, ymOpt - 9, s);557 S := Phrases.Lookup('CITYEVENTS', 14); 558 RisedTextOut(Offscreen.Canvas, 167 - BiColorTextWidth(Offscreen.Canvas, S) 559 div 2, ymOpt - 9, S); 560 560 end 561 561 else if AllowChange then 562 562 begin 563 OptiType := c.Status shr 4 and $0F;564 Sprite( offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,563 OptiType := C.Status shr 4 and $0F; 564 Sprite(Offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64, 565 565 1 + OptiType mod 3 * 64, 217 + OptiType div 3 * 64); 566 566 567 567 { display messages now } 568 568 MessageCount := 0; 569 for i:= 0 to 31 do570 if Happened and ($FFFFFFFF - chCaptured) and (1 shl i) <> 0 then571 inc(MessageCount);569 for I := 0 to 31 do 570 if Happened and ($FFFFFFFF - chCaptured) and (1 shl I) <> 0 then 571 Inc(MessageCount); 572 572 if MessageCount > 3 then 573 573 MessageCount := 3; 574 574 if MessageCount > 0 then 575 575 begin 576 MakeBlue( offscreen, 74, 280, 242, 40);577 line := 0;578 for i:= 0 to nCityEventPriority - 1 do579 if line < MessageCount then580 CheckMessage(CityEventPriority[ i]);576 MakeBlue(Offscreen, 74, 280, 242, 40); 577 Line := 0; 578 for I := 0 to nCityEventPriority - 1 do 579 if Line < MessageCount then 580 CheckMessage(CityEventPriority[I]); 581 581 end 582 582 else 583 583 begin 584 s:= Phrases.Lookup('CITYMANAGETYPE', OptiType);585 j := pos('\', s);586 if j= 0 then587 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40,588 ymOpt - 9, s)584 S := Phrases.Lookup('CITYMANAGETYPE', OptiType); 585 J := Pos('\', S); 586 if J = 0 then 587 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, 588 ymOpt - 9, S) 589 589 else 590 590 begin 591 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40,592 ymOpt - 17, copy(s, 1, j- 1));593 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,594 copy(s, j+ 1, 255));591 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, 592 ymOpt - 17, Copy(S, 1, J - 1)); 593 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1, 594 Copy(S, J + 1, 255)); 595 595 end; 596 596 end; … … 602 602 AreaMap.Paint(xmArea - xxt * 2 * rx, ymArea - yyt * 2 * ry - 3 * yyt, 603 603 dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner, 604 false, AllowChange and IsCityAlive and605 ( c.Status and csResourceWeightsMask = 0));606 BitBltCanvas( offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,604 False, AllowChange and IsCityAlive and 605 (C.Status and csResourceWeightsMask = 0)); 606 BitBltCanvas(Offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas, 607 607 xmArea + 102, 42); 608 608 … … 616 616 ((Loc1 < 0) or (Loc1 >= G.lx * G.ly) or (MyMap[Loc1] and fCity = 0)) 617 617 then 618 Sprite( offscreen, HGrTerrain, xmArea - xxt + xxt * dx,618 Sprite(Offscreen, HGrTerrain, xmArea - xxt + xxt * dx, 619 619 ymArea - yyt + yyt * dy, xxt * 2, yyt * 2, 1 + 5 * (xxt * 2 + 1), 620 620 1 + yyt + 15 * (yyt * 3 + 1)); 621 if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and c.Tiles <> 0) then621 if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and C.Tiles <> 0) then 622 622 PaintResources(xmArea - xxt + xxt * dx, ymArea - yyt + yyt * dy, 623 623 Loc1, (dx = 0) and (dy = 0)); … … 626 626 627 627 if Report.Working > 1 then 628 d:= (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);629 if d> 28 then630 d:= 28;631 for i:= Report.Working - 1 downto 0 do628 D := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1); 629 if D > 28 then 630 D := 28; 631 for I := Report.Working - 1 downto 0 do 632 632 begin 633 633 if IsCityAlive then … … 635 635 else 636 636 xGr := 141; 637 BitBltCanvas( offscreen.Canvas, xmArea - 192 + 5 + i * d, ymArea - 96 - 29,637 BitBltCanvas(Offscreen.Canvas, xmArea - 192 + 5 + I * D, ymArea - 96 - 29, 638 638 27, 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow } 639 Sprite( offscreen, HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27,639 Sprite(Offscreen, HGrSystem, xmArea - 192 + 4 + I * D, ymArea - 96 - 30, 27, 640 640 30, xGr, 171); 641 641 end; 642 if c.Size - Report.Working > 1 then643 d := (xmArea + 192 - xService - 32) div (c.Size - Report.Working - 1);644 if d> 28 then645 d:= 28;646 for i := 0 to c.Size - Report.Working - 1 do642 if C.Size - Report.Working > 1 then 643 D := (xmArea + 192 - xService - 32) div (C.Size - Report.Working - 1); 644 if D > 28 then 645 D := 28; 646 for I := 0 to C.Size - Report.Working - 1 do 647 647 begin 648 648 xGr := 1 + 112; 649 BitBltCanvas( offscreen.Canvas, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27,649 BitBltCanvas(Offscreen.Canvas, xmArea + 192 - 27 + 1 - I * D, 29 + 1, 27, 650 650 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow } 651 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30,651 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 - I * D, 29, 27, 30, 652 652 xGr, 171); 653 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10,653 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 4 - I * D, 29 + 32, 10, 654 654 10, 121, 126); 655 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10,655 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 13 - I * D, 29 + 32, 10, 656 656 10, 121, 126); 657 657 // Sprite(offscreen,HGrSystem,xmArea+192-31+18-i*d,ymArea-96-80+32,10,10,88,115); 658 658 end; 659 659 660 if c.Project and cpImp = 0 then661 PrName := Tribe[cOwner].ModelName[ c.Project and cpIndex]660 if C.Project and cpImp = 0 then 661 PrName := Tribe[cOwner].ModelName[C.Project and cpIndex] 662 662 else 663 PrName := Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex);663 PrName := Phrases.Lookup('IMPROVEMENTS', C.Project and cpIndex); 664 664 PrCost := Report.ProjectCost; 665 665 … … 668 668 begin 669 669 if cGov = gFundamentalism then 670 CountBar( offscreen, xHapp, yHapp + dyBar, wBar, 17,670 CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17, 671 671 Phrases.Lookup('FAITH'), Report.CollectedControl, MainTexture) 672 672 else 673 673 begin 674 CountBar( offscreen, xHapp, yHapp + dyBar, wBar, 17,674 CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17, 675 675 Phrases.Lookup('HAPPINESS'), Report.Morale, MainTexture); 676 CountBar( offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,676 CountBar(Offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16, 677 677 Phrases.Lookup('CONTROL'), Report.CollectedControl, MainTexture); 678 678 end; 679 CountBar( offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),679 CountBar(Offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'), 680 680 Report.Luxury, MainTexture); 681 CountBar( offscreen, xHapp + dxBar, yHapp, wBar, 19,681 CountBar(Offscreen, xHapp + dxBar, yHapp, wBar, 19, 682 682 Phrases.Lookup('UNREST'), 2 * Report.Deployed, MainTexture); 683 CountBar( offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,684 Phrases.Lookup('HAPPINESSDEMAND'), c.Size, MainTexture);683 CountBar(Offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17, 684 Phrases.Lookup('HAPPINESSDEMAND'), C.Size, MainTexture); 685 685 if Report.HappinessBalance >= 0 then 686 CountBar( offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,686 CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17, 687 687 Phrases.Lookup('HAPPINESSPLUS'), Report.HappinessBalance, MainTexture) 688 688 else 689 689 begin 690 690 MakeRed(Offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38); 691 CountBar( offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,691 CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18, 692 692 Phrases.Lookup('LACK'), -Report.HappinessBalance, RedTex); 693 693 end; … … 697 697 if IsCityAlive then 698 698 begin 699 CountBar( offscreen, xFood, yFood + dyBar div 2, wBar, 0,699 CountBar(Offscreen, xFood, yFood + dyBar div 2, wBar, 0, 700 700 Phrases.Lookup('FOOD'), Report.CollectedFood, MainTexture); 701 CountBar( offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,702 Phrases.Lookup('DEMAND'), 2 * c.Size, MainTexture);703 CountBar( offscreen, xFood + dxBar, yFood, wBar, 0,701 CountBar(Offscreen, xFood + dxBar, yFood + dyBar, wBar, 0, 702 Phrases.Lookup('DEMAND'), 2 * C.Size, MainTexture); 703 CountBar(Offscreen, xFood + dxBar, yFood, wBar, 0, 704 704 Phrases.Lookup('SUPPORT'), Report.FoodSupport, MainTexture); 705 705 if Report.FoodSurplus >= 0 then 706 if (cGov = gFuture) or ( c.Size >= NeedAqueductSize) and706 if (cGov = gFuture) or (C.Size >= NeedAqueductSize) and 707 707 (Report.FoodSurplus < 2) then 708 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,708 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6, 709 709 Phrases.Lookup('PROFIT'), Report.FoodSurplus, MainTexture) 710 710 else 711 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,711 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0, 712 712 Phrases.Lookup('SURPLUS'), Report.FoodSurplus, MainTexture) 713 713 else 714 714 begin 715 715 MakeRed(Offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38); 716 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,716 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1, 717 717 Phrases.Lookup('LACK'), -Report.FoodSurplus, RedTex); 718 718 end; 719 719 end; 720 CanGrow := ( c.Size < MaxCitySize) and (cGov <> gFuture) and721 (Report.FoodSurplus > 0) and (( c.Size < NeedAqueductSize) or722 ( c.Built[imAqueduct] = 1) and (c.Size < NeedSewerSize) or723 ( c.Built[imSewer] = 1));720 CanGrow := (C.Size < MaxCitySize) and (cGov <> gFuture) and 721 (Report.FoodSurplus > 0) and ((C.Size < NeedAqueductSize) or 722 (C.Built[imAqueduct] = 1) and (C.Size < NeedSewerSize) or 723 (C.Built[imSewer] = 1)); 724 724 FillBar(xFood + 3, yFood + 102, TrueFood, 725 CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, c.Size),725 CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, C.Size), 726 726 Report.Storage, 1, CanGrow); 727 LoweredTextout( offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,727 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood + 3 - 5, 728 728 yFood + 102 - 20, Format('%d/%d', [TrueFood, Report.Storage])); 729 LoweredTextout( offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,729 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66, 730 730 Phrases.Lookup('STORAGE')); 731 731 … … 733 733 if IsCityAlive then 734 734 begin 735 CountBar( offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),735 CountBar(Offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'), 736 736 Report.CollectedMaterial, MainTexture); 737 CountBar( offscreen, xProd + dxBar, yProd, wBar, 2,737 CountBar(Offscreen, xProd + dxBar, yProd, wBar, 2, 738 738 Phrases.Lookup('SUPPORT'), Report.MaterialSupport, MainTexture); 739 739 if Report.Production >= 0 then 740 if c.Project and (cpImp + cpIndex) = cpImp + imTrGoods then741 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,740 if C.Project and (cpImp + cpIndex) = cpImp + imTrGoods then 741 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6, 742 742 Phrases.Lookup('PROFIT'), Report.Production, MainTexture) 743 743 else 744 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,744 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2, 745 745 Phrases.Lookup('PROD'), Report.Production, MainTexture) 746 746 else 747 747 begin 748 748 MakeRed(Offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38); 749 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,749 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3, 750 750 Phrases.Lookup('LACK'), -Report.Production, RedTex); 751 751 end; 752 752 end; 753 if c.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then754 with offscreen.Canvas do755 begin 756 i:= Report.Production;757 if ( i< 0) or not IsCityAlive then758 i:= 0;759 FillBar(xProd + 3, yProd + 16 + 63, TrueProd, i, PrCost, 4, true);760 LoweredTextout( offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,753 if C.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then 754 with Offscreen.Canvas do 755 begin 756 I := Report.Production; 757 if (I < 0) or not IsCityAlive then 758 I := 0; 759 FillBar(xProd + 3, yProd + 16 + 63, TrueProd, I, PrCost, 4, True); 760 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xProd + 3 - 5, 761 761 yProd + 16 + 43, Format('%d/%d', [TrueProd, PrCost])); 762 if BiColorTextWidth( offscreen.Canvas, PrName) > wBar + dxBar then762 if BiColorTextWidth(Offscreen.Canvas, PrName) > wBar + dxBar then 763 763 begin 764 764 repeat 765 Delete(PrName, length(PrName), 1)766 until BiColorTextWidth( offscreen.Canvas, PrName) <= wBar + dxBar;765 Delete(PrName, Length(PrName), 1) 766 until BiColorTextWidth(Offscreen.Canvas, PrName) <= wBar + dxBar; 767 767 PrName := PrName + '.' 768 768 end; 769 769 end; 770 RisedTextOut( offscreen.Canvas, xProd - 2, yProd + 36, PrName);770 RisedTextOut(Offscreen.Canvas, xProd - 2, yProd + 36, PrName); 771 771 772 772 // pollution section … … 774 774 begin 775 775 FillBar(xPoll + 3, yPoll + 20, TruePoll, Report.AddPollution, 776 MaxPollution, 3, true);777 RisedTextOut( offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,776 MaxPollution, 3, True); 777 RisedTextOut(Offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20, 778 778 Phrases.Lookup('POLL')); 779 779 end; … … 782 782 if IsCityAlive and (Report.CollectedTrade > 0) then 783 783 begin 784 CountBar( offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,784 CountBar(Offscreen, xTrade, yTrade + dyBar div 2, wBar, 4, 785 785 Phrases.Lookup('TRADE'), Report.CollectedTrade, MainTexture); 786 CountBar( offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,786 CountBar(Offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5, 787 787 Phrases.Lookup('CORR'), Report.Corruption, MainTexture); 788 CountBar( offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),788 CountBar(Offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'), 789 789 Report.Tax, MainTexture); 790 CountBar( offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,790 CountBar(Offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12, 791 791 Phrases.Lookup('SCIENCE'), Report.Science, MainTexture); 792 792 end; 793 793 794 794 // small map 795 BitBltCanvas( offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,795 BitBltCanvas(Offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap, 796 796 SmallCityMap.Canvas, 0, 0); 797 797 if SmallMapMode = smImprovements then 798 Frame( offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),798 Frame(Offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3), 799 799 ySmallMap + 24 * (ZoomArea mod 3), xSmallMap + 48 * (ZoomArea div 3) + 49, 800 800 ySmallMap + 24 * (ZoomArea mod 3) + 25, MainTexture.ColorMark, 801 801 MainTexture.ColorMark); 802 Frame( offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,802 Frame(Offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap, 803 803 ySmallMap + hSmallMap, $B0B0B0, $FFFFFF); 804 RFrame( offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +804 RFrame(Offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap + 805 805 1, ySmallMap + hSmallMap + 1, $FFFFFF, $B0B0B0); 806 806 807 Frame( offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,807 Frame(Offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport, 808 808 ySupport + hSupport, $B0B0B0, $FFFFFF); 809 RFrame( offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,809 RFrame(Offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1, 810 810 ySupport + hSupport + 1, $FFFFFF, $B0B0B0); 811 x:= xSupport + wSupport div 2;812 y:= ySupport + hSupport div 2;811 X := xSupport + wSupport div 2; 812 Y := ySupport + hSupport div 2; 813 813 if SmallMapMode = smSupportedUnits then 814 814 begin 815 offscreen.Canvas.brush.Color := MainTexture.ColorMark;816 offscreen.Canvas.FillRect(Rect(x - 27, y - 6, x + 27, y+ 6));817 offscreen.Canvas.brush.style := bsClear;818 end; 819 Sprite( offscreen, HGrSystem, x - 16, y- 5, 10, 10, 88, 115);820 Sprite( offscreen, HGrSystem, x - 5, y- 5, 10, 10, 66, 115);821 Sprite( offscreen, HGrSystem, x + 6, y- 5, 10, 10, 154, 126);822 823 BitBltCanvas( offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,815 Offscreen.Canvas.Brush.Color := MainTexture.ColorMark; 816 Offscreen.Canvas.FillRect(Rect(X - 27, Y - 6, X + 27, Y + 6)); 817 Offscreen.Canvas.Brush.style := bsClear; 818 end; 819 Sprite(Offscreen, HGrSystem, X - 16, Y - 5, 10, 10, 88, 115); 820 Sprite(Offscreen, HGrSystem, X - 5, Y - 5, 10, 10, 66, 115); 821 Sprite(Offscreen, HGrSystem, X + 6, Y - 5, 10, 10, 154, 126); 822 823 BitBltCanvas(Offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap, 824 824 ZoomCityMap.Canvas, 0, 0); 825 825 826 for i:= 0 to 5 do827 imix[ i] := -1;826 for I := 0 to 5 do 827 imix[I] := -1; 828 828 if SmallMapMode = smImprovements then 829 829 begin … … 832 832 Cnt := 0; 833 833 for iix := 0 to nImp - 1 do 834 if ((iix < nWonder) or (ImpPosition[iix] < 0)) and ( c.Built[iix] > 0) then834 if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (C.Built[iix] > 0) then 835 835 begin 836 i:= Cnt - Page * 6;837 if ( i >= 0) and (i< 6) then838 imix[ i] := iix;839 inc(Cnt);836 I := Cnt - Page * 6; 837 if (I >= 0) and (I < 6) then 838 imix[I] := iix; 839 Inc(Cnt); 840 840 end; 841 841 PageCount := (Cnt + 5) div 6; … … 845 845 for iix := nWonder to nImp - 1 do 846 846 begin 847 i:= ImpPosition[iix] - 6 * ZoomArea;848 if ( i >= 0) and (i < 6) and (c.Built[iix] > 0) then849 imix[ i] := iix;847 I := ImpPosition[iix] - 6 * ZoomArea; 848 if (I >= 0) and (I < 6) and (C.Built[iix] > 0) then 849 imix[I] := iix; 850 850 end; 851 851 PageCount := 0; 852 852 end; 853 for i:= 0 to 5 do854 if imix[ i] >= 0 then853 for I := 0 to 5 do 854 if imix[I] >= 0 then 855 855 begin 856 iix := imix[ i];857 x := xZoomMap + 14 + 72 * (imod 3);858 y := yZoomMap + 14 + 56 * (idiv 3);859 ImpImage( offscreen.Canvas, x, y, iix, cGov, AllowChange and856 iix := imix[I]; 857 X := xZoomMap + 14 + 72 * (I mod 3); 858 Y := yZoomMap + 14 + 56 * (I div 3); 859 ImpImage(Offscreen.Canvas, X, Y, iix, cGov, AllowChange and 860 860 (ClientMode < scContact)); 861 861 if IsCityAlive then … … 863 863 if iix = imColosseum then 864 864 begin 865 Sprite( offscreen, HGrSystem, x + 46, y, 14, 14, 82, 100);865 Sprite(Offscreen, HGrSystem, X + 46, Y, 14, 14, 82, 100); 866 866 end 867 867 else … … 881 881 if HappyGain > 1 then 882 882 begin 883 d:= 30 div (HappyGain - 1);884 if d> 10 then885 d:= 10883 D := 30 div (HappyGain - 1); 884 if D > 10 then 885 D := 10 886 886 end; 887 for j:= 0 to HappyGain - 1 do888 Sprite( offscreen, HGrSystem, x + 50, y + d * j, 10, 10, 132, 126);887 for J := 0 to HappyGain - 1 do 888 Sprite(Offscreen, HGrSystem, X + 50, Y + D * J, 10, 10, 132, 126); 889 889 end; 890 for j:= 0 to Imp[iix].Maint - 1 do891 Sprite( offscreen, HGrSystem, x - 4, y + 29 - 3 * j, 10, 10,890 for J := 0 to Imp[iix].Maint - 1 do 891 Sprite(Offscreen, HGrSystem, X - 4, Y + 29 - 3 * J, 10, 10, 892 892 132, 115); 893 893 end … … 920 920 else { if SmallMapMode = smSupportedUnits then } 921 921 begin 922 LoweredTextout( offscreen.Canvas, -1, MainTexture, xZoomMap + 6,922 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xZoomMap + 6, 923 923 yZoomMap + 2, Phrases.Lookup('SUPUNITS')); 924 FreeSupp := c.Size * SupportFree[cGov] shr 1;924 FreeSupp := C.Size * SupportFree[cGov] shr 1; 925 925 Cnt := 0; 926 for i:= 0 to MyRO.nUn - 1 do927 if (MyUn[ i].Loc >= 0) and (MyUn[i].Home = cix) then928 with MyModel[MyUn[ i].mix] do926 for I := 0 to MyRO.nUn - 1 do 927 if (MyUn[I].Loc >= 0) and (MyUn[I].Home = cix) then 928 with MyModel[MyUn[I].mix] do 929 929 begin 930 Server(sGetUnitReport, me, i, UnitReport);930 Server(sGetUnitReport, Me, I, UnitReport); 931 931 if (Cnt >= 6 * Page) and (Cnt < 6 * (Page + 1)) then 932 932 begin // unit visible in display 933 imix[Cnt - 6 * Page] := i;934 x:= ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;935 y:= ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;936 MakeUnitInfo( me, MyUn[i], UnitInfo);937 NoMap.SetOutput( offscreen);938 NoMap.PaintUnit( x, y, UnitInfo, MyUn[i].Status);939 940 for j:= 0 to UnitReport.FoodSupport - 1 do941 Sprite( offscreen, HGrSystem, x + 38 + 11 * j, y+ 40, 10,933 imix[Cnt - 6 * Page] := I; 934 X := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap; 935 Y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20; 936 MakeUnitInfo(Me, MyUn[I], UnitInfo); 937 NoMap.SetOutput(Offscreen); 938 NoMap.PaintUnit(X, Y, UnitInfo, MyUn[I].Status); 939 940 for J := 0 to UnitReport.FoodSupport - 1 do 941 Sprite(Offscreen, HGrSystem, X + 38 + 11 * J, Y + 40, 10, 942 942 10, 66, 115); 943 for j:= 0 to UnitReport.ProdSupport - 1 do943 for J := 0 to UnitReport.ProdSupport - 1 do 944 944 begin 945 945 if (FreeSupp > 0) and 946 946 (UnitReport.ReportFlags and urfAlwaysSupport = 0) then 947 947 begin 948 Sprite( offscreen, HGrSystem, x + 16 - 11 * j, y+ 40, 10,948 Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10, 949 949 10, 143, 115); 950 dec(FreeSupp);950 Dec(FreeSupp); 951 951 end 952 952 else 953 Sprite( offscreen, HGrSystem, x + 16 - 11 * j, y+ 40, 10,953 Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10, 954 954 10, 88, 115); 955 955 end; 956 956 if UnitReport.ReportFlags and urfDeployed <> 0 then 957 for j:= 0 to 1 do958 Sprite( offscreen, HGrSystem, x + 27 + 11 * j, y+ 40, 10,957 for J := 0 to 1 do 958 Sprite(Offscreen, HGrSystem, X + 27 + 11 * J, Y + 40, 10, 959 959 10, 154, 126) 960 960 end // unit visible in display … … 977 977 begin 978 978 { display project now } 979 DLine( offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,979 DLine(Offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10, 980 980 yProd + dyBar + 16, $FFFFFF, $B0B0B0); 981 981 if ProdHint then 982 982 begin 983 ScreenTools.Frame( offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,983 ScreenTools.Frame(Offscreen.Canvas, xView + 9 - 1, yView + 5 - 1, 984 984 xView + 9 + xSizeBig, yView + 5 + ySizeBig, $B0B0B0, $FFFFFF); 985 RFrame( offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,985 RFrame(Offscreen.Canvas, xView + 9 - 2, yView + 5 - 2, 986 986 xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, $FFFFFF, $B0B0B0); 987 with offscreen.Canvas do987 with Offscreen.Canvas do 988 988 begin 989 brush.Color := $000000;989 Brush.Color := $000000; 990 990 FillRect(Rect(xView + 9, yView + 5, xView + 1 + 72 - 8, 991 991 yView + 5 + 40)); 992 brush.style := bsClear;992 Brush.style := bsClear; 993 993 end; 994 994 end 995 else if AllowChange and ( c.Status and 7 <> 0) then995 else if AllowChange and (C.Status and 7 <> 0) then 996 996 begin // city type autobuild 997 FrameImage( offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,998 ySizeBig, ( c.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and997 FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig, 998 ySizeBig, (C.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and 999 999 (ClientMode < scContact)); 1000 1000 end 1001 else if c.Project and cpImp = 0 then1001 else if C.Project and cpImp = 0 then 1002 1002 begin // project is unit 1003 FrameImage( offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,1003 FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig, 1004 1004 ySizeBig, 0, 0, AllowChange and (ClientMode < scContact)); 1005 with Tribe[cOwner].ModelPicture[ c.Project and cpIndex] do1006 Sprite( offscreen, HGr, xView + 5, yView + 1, 64, 44,1005 with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do 1006 Sprite(Offscreen, HGr, xView + 5, yView + 1, 64, 44, 1007 1007 pix mod 10 * 65 + 1, pix div 10 * 49 + 1); 1008 1008 end … … 1010 1010 begin // project is building 1011 1011 if ProdHint then 1012 Paintiix := c.Project0 and cpIndex1012 Paintiix := C.Project0 and cpIndex 1013 1013 else 1014 Paintiix := c.Project and cpIndex;1015 ImpImage( offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,1014 Paintiix := C.Project and cpIndex; 1015 ImpImage(Offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov, 1016 1016 AllowChange and (ClientMode < scContact)); 1017 1017 end; … … 1020 1020 if AllowChange and (ClientMode < scContact) then 1021 1021 begin 1022 i := Server(sBuyCityProject - sExecute, me, cix, nil^);1023 BuyBtn.Visible := ( i = eOk) or (i= eViolation);1022 I := Server(sBuyCityProject - sExecute, Me, cix, nil^); 1023 BuyBtn.Visible := (I = eOk) or (I = eViolation); 1024 1024 end 1025 1025 else 1026 BuyBtn.Visible := false;1026 BuyBtn.Visible := False; 1027 1027 1028 1028 MarkUsedOffscreen(ClientWidth, ClientHeight); … … 1031 1031 procedure TCityDlg.FormShow(Sender: TObject); 1032 1032 var 1033 dx, dy, Loc1: integer;1033 dx, dy, Loc1: Integer; 1034 1034 GetCityData: TGetCityData; 1035 1035 begin … … 1037 1037 if cix >= 0 then 1038 1038 begin { own city } 1039 c:= MyCity[cix];1040 cOwner := me;1039 C := MyCity[cix]; 1040 cOwner := Me; 1041 1041 cGov := MyRO.Government; 1042 1042 ProdHint := (cGov <> gAnarchy) and 1043 1043 (Happened and (chProduction or chFounded or chCaptured or 1044 1044 chAllImpsMade) <> 0); 1045 Server(sGetCityAreaInfo, me, cix, CityAreaInfo);1045 Server(sGetCityAreaInfo, Me, cix, CityAreaInfo); 1046 1046 NextCityBtn.Visible := WindowMode = wmPersistent; 1047 1047 PrevCityBtn.Visible := WindowMode = wmPersistent; … … 1050 1050 begin 1051 1051 SmallMapMode := smImprovements; 1052 Server(sGetCity, me, cLoc, GetCityData);1053 c := GetCityData.c;1052 Server(sGetCity, Me, cLoc, GetCityData); 1053 C := GetCityData.C; 1054 1054 cOwner := GetCityData.Owner; 1055 1055 cGov := MyRO.EnemyReport[cOwner].Government; 1056 Happened := c.Flags and $7FFFFFFF;1057 ProdHint := false;1058 Server(sGetEnemyCityAreaInfo, me, cLoc, CityAreaInfo);1059 1060 if c.Project and cpImp = 0 then1056 Happened := C.Flags and $7FFFFFFF; 1057 ProdHint := False; 1058 Server(sGetEnemyCityAreaInfo, Me, cLoc, CityAreaInfo); 1059 1060 if C.Project and cpImp = 0 then 1061 1061 begin 1062 1062 emix := MyRO.nEnemyModel - 1; 1063 1063 while (emix > 0) and ((MyRO.EnemyModel[emix].Owner <> cOwner) or 1064 ( integer(MyRO.EnemyModel[emix].mix) <> c.Project and cpIndex)) do1065 dec(emix);1066 if not Assigned(Tribe[cOwner].ModelPicture[ c.Project and cpIndex].HGr) then1064 (Integer(MyRO.EnemyModel[emix].mix) <> C.Project and cpIndex)) do 1065 Dec(emix); 1066 if not Assigned(Tribe[cOwner].ModelPicture[C.Project and cpIndex].HGr) then 1067 1067 InitEnemyModel(emix); 1068 1068 end; … … 1073 1073 Page := 0; 1074 1074 1075 if c.Size < 5 then1075 if C.Size < 5 then 1076 1076 SizeClass := 0 1077 else if c.Size < 9 then1077 else if C.Size < 9 then 1078 1078 SizeClass := 1 1079 else if c.Size < 13 then1079 else if C.Size < 13 then 1080 1080 SizeClass := 2 1081 1081 else … … 1100 1100 end; 1101 1101 1102 Caption := CityName( c.ID);1102 Caption := CityName(C.ID); 1103 1103 1104 1104 InitSmallCityMap; … … 1109 1109 end; 1110 1110 1111 procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: integer; ShowEvent: cardinal);1111 procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal); 1112 1112 begin 1113 1113 if MyMap[Loc] and fOwned <> 0 then … … 1115 1115 cix := MyRO.nCity - 1; 1116 1116 while (cix >= 0) and (MyCity[cix].Loc <> Loc) do 1117 dec(cix);1118 assert(cix >= 0);1117 Dec(cix); 1118 Assert(cix >= 0); 1119 1119 if (Optimize_cixTileChange >= 0) and 1120 1120 (Optimize_TilesBeforeChange and not MyCity[Optimize_cixTileChange].Tiles … … 1132 1132 else 1133 1133 cix := -1; 1134 AllowChange := not supervising and (cix >= 0);1134 AllowChange := not Supervising and (cix >= 0); 1135 1135 cLoc := Loc; 1136 1136 Happened := ShowEvent; … … 1139 1139 1140 1140 procedure TCityDlg.FormMouseDown(Sender: TObject; Button: TMouseButton; 1141 Shift: TShiftState; x, y: integer);1141 Shift: TShiftState; X, Y: Integer); 1142 1142 var 1143 i, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: integer;1144 Rebuild: boolean;1145 begin 1146 if (ssLeft in Shift) and ( x >= xSmallMap) and (x< xSmallMap + wSmallMap) and1147 ( y >= ySmallMap) and (y< ySmallMap + hSmallMap) then1143 I, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: Integer; 1144 Rebuild: Boolean; 1145 begin 1146 if (ssLeft in Shift) and (X >= xSmallMap) and (X < xSmallMap + wSmallMap) and 1147 (Y >= ySmallMap) and (Y < ySmallMap + hSmallMap) then 1148 1148 begin 1149 1149 SmallMapMode := smImprovements; 1150 ZoomArea := ( y- ySmallMap) * 3 div hSmallMap + 3 *1151 (( x- xSmallMap) * 2 div wSmallMap);1150 ZoomArea := (Y - ySmallMap) * 3 div hSmallMap + 3 * 1151 ((X - xSmallMap) * 2 div wSmallMap); 1152 1152 Page := 0; 1153 1153 InitZoomCityMap; … … 1155 1155 Exit; 1156 1156 end; 1157 if (ssLeft in Shift) and ( x >= xSupport) and (x< xSupport + wSupport) and1158 ( y >= ySupport) and (y< ySupport + hSupport) then1157 if (ssLeft in Shift) and (X >= xSupport) and (X < xSupport + wSupport) and 1158 (Y >= ySupport) and (Y < ySupport + hSupport) then 1159 1159 begin 1160 1160 SmallMapMode := smSupportedUnits; … … 1168 1168 1169 1169 if (ssLeft in Shift) then 1170 if (ClientMode < scContact) and ( x >= xView) and (y>= yView) and1171 ( x < xView + 73) and (y< yView + 50) then1170 if (ClientMode < scContact) and (X >= xView) and (Y >= yView) and 1171 (X < xView + 73) and (Y < yView + 50) then 1172 1172 if cGov = gAnarchy then 1173 1173 with MessgExDlg do 1174 1174 begin 1175 1175 { MessgText:=Phrases.Lookup('OUTOFCONTROL'); 1176 if c.Project and cpImp=0 then1177 MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[ c.Project and cpIndex]])1178 else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex)]); }1176 if C.Project and cpImp=0 then 1177 MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[C.Project and cpIndex]]) 1178 else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',C.Project and cpIndex)]); } 1179 1179 MessgText := Phrases.Lookup('NOCHANGEINANARCHY'); 1180 1180 Kind := mkOk; … … 1185 1185 if ProdHint then 1186 1186 begin 1187 ProdHint := false;1187 ProdHint := False; 1188 1188 SmartUpdateContent 1189 1189 end; 1190 1190 ChooseProject; 1191 1191 end 1192 else if (SmallMapMode = smImprovements) and ( x >= xZoomMap) and (x< xZoomMap + wZoomMap) and1193 ( y >= yZoomMap) and (y< yZoomMap + hZoomMap) then1194 begin 1195 i:= 5;1196 while ( i >= 0) and not((x >= xZoomMap + 14 + 72 * (imod 3)) and1197 ( x < xZoomMap + 14 + 56 + 72 * (imod 3)) and1198 ( y >= yZoomMap + 14 + 56 * (idiv 3)) and1199 ( y < yZoomMap + 14 + 40 + 56 * (idiv 3))) do1200 dec(i);1201 if i>= 0 then1192 else if (SmallMapMode = smImprovements) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and 1193 (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then 1194 begin 1195 I := 5; 1196 while (I >= 0) and not((X >= xZoomMap + 14 + 72 * (I mod 3)) and 1197 (X < xZoomMap + 14 + 56 + 72 * (I mod 3)) and 1198 (Y >= yZoomMap + 14 + 56 * (I div 3)) and 1199 (Y < yZoomMap + 14 + 40 + 56 * (I div 3))) do 1200 Dec(I); 1201 if I >= 0 then 1202 1202 begin 1203 iix := imix[ i];1203 iix := imix[I]; 1204 1204 if iix >= 0 then 1205 1205 if ssShift in Shift then … … 1221 1221 else 1222 1222 begin 1223 SellResult := Server(sSellCityImprovement - sExecute, me,1223 SellResult := Server(sSellCityImprovement - sExecute, Me, 1224 1224 cix, iix); 1225 1225 if SellResult < rExecuted then … … 1236 1236 else 1237 1237 begin 1238 if Server(sRebuildCityImprovement - sExecute, me, cix, iix) < rExecuted1238 if Server(sRebuildCityImprovement - sExecute, Me, cix, iix) < rExecuted 1239 1239 then 1240 1240 begin // no rebuild possible, ask for sell only 1241 Rebuild := false;1241 Rebuild := False; 1242 1242 MessgText := Phrases.Lookup('IMPROVEMENTS', iix); 1243 1243 if not Phrases2FallenBackToEnglish then 1244 1244 MessgText := Format(Phrases2.Lookup('SELL2'), 1245 1245 [MessgText, Imp[iix].Cost * BuildCostMod 1246 [G.Difficulty[ me]] div 12])1246 [G.Difficulty[Me]] div 12]) 1247 1247 else 1248 1248 MessgText := Format(Phrases.Lookup('SELL'), [MessgText]); 1249 1249 if iix = imSpacePort then 1250 with MyRO.Ship[ me] do1250 with MyRO.Ship[Me] do 1251 1251 if Parts[0] + Parts[1] + Parts[2] > 0 then 1252 1252 MessgText := MessgText + ' ' + … … 1259 1259 else 1260 1260 begin 1261 Rebuild := true;1261 Rebuild := True; 1262 1262 MessgText := Phrases.Lookup('IMPROVEMENTS', iix); 1263 1263 if not Phrases2FallenBackToEnglish then 1264 1264 MessgText := Format(Phrases2.Lookup('DISPOSE2'), 1265 1265 [MessgText, Imp[iix].Cost * BuildCostMod 1266 [G.Difficulty[ me]] div 12 * 2 div 3])1266 [G.Difficulty[Me]] div 12 * 2 div 3]) 1267 1267 else 1268 1268 MessgText := Format(Phrases.Lookup('DISPOSE'), 1269 1269 [MessgText]); 1270 1270 if iix = imSpacePort then 1271 with MyRO.Ship[ me] do1271 with MyRO.Ship[Me] do 1272 1272 if Parts[0] + Parts[1] + Parts[2] > 0 then 1273 1273 MessgText := MessgText + ' ' + … … 1283 1283 begin 1284 1284 Play('CITY_REBUILDIMP'); 1285 Server(sRebuildCityImprovement, me, cix, iix);1285 Server(sRebuildCityImprovement, Me, cix, iix); 1286 1286 end 1287 1287 else 1288 1288 begin 1289 1289 Play('CITY_SELLIMP'); 1290 Server(sSellCityImprovement, me, cix, iix);1290 Server(sSellCityImprovement, Me, cix, iix); 1291 1291 end; 1292 1292 CityOptimizer_CityChange(cix); … … 1301 1301 end; 1302 1302 end 1303 else if (SmallMapMode = smSupportedUnits) and ( x >= xZoomMap) and (x< xZoomMap + wZoomMap) and1304 ( y >= yZoomMap) and (y< yZoomMap + hZoomMap) then1305 begin 1306 i:= 5;1307 while ( i >= 0) and not((x >= xZoomMap + 64 * (imod 3)) and1308 ( x < xZoomMap + 64 + 64 * (imod 3)) and1309 ( y >= yZoomMap + 20 + 48 * (idiv 3)) and1310 ( y < yZoomMap + 20 + 52 + 48 * (idiv 3))) do1311 dec(i);1312 if ( i >= 0) and (imix[i] >= 0) then1303 else if (SmallMapMode = smSupportedUnits) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and 1304 (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then 1305 begin 1306 I := 5; 1307 while (I >= 0) and not((X >= xZoomMap + 64 * (I mod 3)) and 1308 (X < xZoomMap + 64 + 64 * (I mod 3)) and 1309 (Y >= yZoomMap + 20 + 48 * (I div 3)) and 1310 (Y < yZoomMap + 20 + 52 + 48 * (I div 3))) do 1311 Dec(I); 1312 if (I >= 0) and (imix[I] >= 0) then 1313 1313 if ssShift in Shift then 1314 1314 else if (cix >= 0) and (ClientMode < scContact) and … … 1317 1317 CloseAction := None; 1318 1318 Close; 1319 MainScreen.CityClosed(imix[ i], false, true);1319 MainScreen.CityClosed(imix[I], False, True); 1320 1320 end; 1321 1321 end 1322 else if ( x >= xmArea - 192) and (x < xmArea + 192) and (y>= ymArea - 96)1323 and ( y< ymArea + 96) then1322 else if (X >= xmArea - 192) and (X < xmArea + 192) and (Y >= ymArea - 96) 1323 and (Y < ymArea + 96) then 1324 1324 with AreaMap do begin 1325 qx := ((4000 * xxt * yyt) + ( x - xmArea) * (yyt * 2) + (y- ymArea + yyt)1325 qx := ((4000 * xxt * yyt) + (X - xmArea) * (yyt * 2) + (Y - ymArea + yyt) 1326 1326 * (xxt * 2)) div (xxt * yyt * 4) - 1000; 1327 qy := ((4000 * xxt * yyt) + ( y - ymArea + yyt) * (xxt * 2) - (x- xmArea)1327 qy := ((4000 * xxt * yyt) + (Y - ymArea + yyt) * (xxt * 2) - (X - xmArea) 1328 1328 * (yyt * 2)) div (xxt * yyt * 4) - 1000; 1329 1329 dx := qx - qy; … … 1338 1338 end 1339 1339 else if (ClientMode < scContact) and (cGov <> gAnarchy) and 1340 ( c.Flags and chCaptured = 0) then1340 (C.Flags and chCaptured = 0) then 1341 1341 begin // toggle exploitation 1342 assert(not supervising);1343 if c.Status and csResourceWeightsMask <> 0 then1342 Assert(not Supervising); 1343 if C.Status and csResourceWeightsMask <> 0 then 1344 1344 begin 1345 1345 with MessgExDlg do … … 1355 1355 MyCity[cix].Status := MyCity[cix].Status and 1356 1356 not csResourceWeightsMask; // off 1357 c.Status := MyCity[cix].Status;1357 C.Status := MyCity[cix].Status; 1358 1358 SmartUpdateContent; 1359 1359 end; 1360 exit;1360 Exit; 1361 1361 end; 1362 1362 fix := (dy + 3) shl 2 + (dx + 3) shr 1; 1363 1363 NewTiles := MyCity[cix].Tiles xor (1 shl fix); 1364 if Server(sSetCityTiles, me, cix, NewTiles) >= rExecuted then1364 if Server(sSetCityTiles, Me, cix, NewTiles) >= rExecuted then 1365 1365 begin 1366 1366 SmartUpdateContent; … … 1371 1371 end 1372 1372 else if (ClientMode < scContact) and (cGov <> gAnarchy) and 1373 ( c.Flags and chCaptured = 0) and (x >= xmOpt - 32) and (x< xmOpt + 32)1374 and ( y >= ymOpt - 32) and (y< ymOpt + 32) then1375 begin 1376 i := sqr(x - xmOpt) + sqr(y- ymOpt); // click radius1377 if i<= 32 * 32 then1373 (C.Flags and chCaptured = 0) and (X >= xmOpt - 32) and (X < xmOpt + 32) 1374 and (Y >= ymOpt - 32) and (Y < ymOpt + 32) then 1375 begin 1376 I := sqr(X - xmOpt) + sqr(Y - ymOpt); // click radius 1377 if I <= 32 * 32 then 1378 1378 begin 1379 if i< 16 * 16 then // inner area clicked1380 if c.Status and csResourceWeightsMask <> 0 then1381 i := (c.Status shr 4 and $0F) mod 5 + 1 // rotate except off1379 if I < 16 * 16 then // inner area clicked 1380 if C.Status and csResourceWeightsMask <> 0 then 1381 I := (C.Status shr 4 and $0F) mod 5 + 1 // rotate except off 1382 1382 else 1383 i:= 3 // rwGrowth1383 I := 3 // rwGrowth 1384 1384 else 1385 case trunc(arctan2( x - xmOpt, ymOpt - y) * 180 / pi) of1385 case trunc(arctan2(X - xmOpt, ymOpt - Y) * 180 / pi) of 1386 1386 - 25 - 52 * 2 .. -26 - 52: 1387 i:= 1;1387 I := 1; 1388 1388 -25 - 52 .. -26: 1389 i:= 2;1389 I := 2; 1390 1390 -25 .. 25: 1391 i:= 3;1391 I := 3; 1392 1392 26 .. 25 + 52: 1393 i:= 4;1393 I := 4; 1394 1394 26 + 52 .. 25 + 52 * 2: 1395 i:= 5;1395 I := 5; 1396 1396 180 - 26 .. 180, -180 .. -180 + 26: 1397 i:= 0;1397 I := 0; 1398 1398 else 1399 i:= -1;1399 I := -1; 1400 1400 end; 1401 if i>= 0 then1401 if I >= 0 then 1402 1402 begin 1403 ChangeResourceWeights( i);1403 ChangeResourceWeights(I); 1404 1404 SmartUpdateContent; 1405 1405 if WindowMode <> wmModal then … … 1423 1423 ); 1424 1424 1425 function ProjectType(Project: integer): TProjectType;1425 function ProjectType(Project: Integer): TProjectType; 1426 1426 begin 1427 1427 if Project and cpCompleted <> 0 then … … 1445 1445 1446 1446 var 1447 NewProject, OldMoney, cix1: integer;1447 NewProject, OldMoney, cix1: Integer; 1448 1448 pt0, pt1: TProjectType; 1449 QueryOk: boolean;1450 begin 1451 Assert(not supervising);1449 QueryOk: Boolean; 1450 begin 1451 Assert(not Supervising); 1452 1452 ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix); 1453 if ModalSelectDlg. result <> -1 then1454 begin 1455 if ModalSelectDlg. result and cpType <> 0 then1453 if ModalSelectDlg.Result <> -1 then 1454 begin 1455 if ModalSelectDlg.Result and cpType <> 0 then 1456 1456 begin 1457 1457 MyCity[cix].Status := MyCity[cix].Status and not 7 or 1458 (1 + ModalSelectDlg. result and cpIndex);1459 AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg. result and cpIndex]);1458 (1 + ModalSelectDlg.Result and cpIndex); 1459 AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg.Result and cpIndex]); 1460 1460 end 1461 1461 else … … 1522 1522 then 1523 1523 NewProject := NewProject or cpDisbandCity; 1524 Server(sSetCityProject, me, cix, NewProject);1525 c.Project := MyCity[cix].Project;1524 Server(sSetCityProject, Me, cix, NewProject); 1525 C.Project := MyCity[cix].Project; 1526 1526 if MyRO.Money > OldMoney then 1527 1527 Play('CITY_SELLIMP'); … … 1538 1538 procedure TCityDlg.BuyClick(Sender: TObject); 1539 1539 var 1540 NextProd, Cost: integer;1540 NextProd, Cost: Integer; 1541 1541 begin 1542 1542 if (cix < 0) or (ClientMode >= scContact) then 1543 exit;1543 Exit; 1544 1544 with MyCity[cix], MessgExDlg do 1545 1545 begin … … 1549 1549 NextProd := 0; 1550 1550 Cost := Cost - Prod - NextProd; 1551 if (MyRO.Wonder[woMich].EffectiveOwner = me) and (Project and cpImp <> 0)1551 if (MyRO.Wonder[woMich].EffectiveOwner = Me) and (Project and cpImp <> 0) 1552 1552 then 1553 1553 Cost := Cost * 2 … … 1573 1573 if (Kind = mkYesNo) and (ModalResult = mrOK) then 1574 1574 begin 1575 if Server(sBuyCityProject, me, cix, nil^) >= rExecuted then1575 if Server(sBuyCityProject, Me, cix, nil^) >= rExecuted then 1576 1576 begin 1577 1577 Play('CITY_BUYPROJECT'); … … 1633 1633 else if BlinkTime = 6 then 1634 1634 begin 1635 if AllowChange and ( c.Status and 7 <> 0) then1635 if AllowChange and (C.Status and 7 <> 0) then 1636 1636 begin // city type autobuild 1637 1637 FrameImage(Canvas, bigimp, xView + 9, yView + 5, xSizeBig, ySizeBig, 1638 ( c.Status and 7 - 1 + 3) * xSizeBig, 0, true);1638 (C.Status and 7 - 1 + 3) * xSizeBig, 0, True); 1639 1639 end 1640 else if c.Project and cpImp = 0 then1640 else if C.Project and cpImp = 0 then 1641 1641 begin // project is unit 1642 1642 BitBltCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig, 1643 1643 Bigimp.Canvas, 0, 0); 1644 with Tribe[cOwner].ModelPicture[ c.Project and cpIndex] do1644 with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do 1645 1645 Sprite(Canvas, HGr, xView + 5, yView + 1, 64, 44, pix mod 10 * 65 + 1, 1646 1646 pix div 10 * 49 + 1); 1647 1647 end 1648 1648 else 1649 ImpImage(Canvas, xView + 9, yView + 5, c.Project0 and cpIndex,1650 cGov, true);1649 ImpImage(Canvas, xView + 9, yView + 5, C.Project0 and cpIndex, 1650 cGov, True); 1651 1651 end; 1652 1652 end; … … 1664 1664 if 1 shl OpenSoundEvent = chProduction then 1665 1665 begin 1666 if c.Project0 and cpImp <> 0 then1667 begin 1668 if c.Project0 and cpIndex >= 28 then1666 if C.Project0 and cpImp <> 0 then 1667 begin 1668 if C.Project0 and cpIndex >= 28 then 1669 1669 // wonders have already extra message with sound 1670 if Imp[ c.Project0 and cpIndex].Kind = ikShipPart then1670 if Imp[C.Project0 and cpIndex].Kind = ikShipPart then 1671 1671 Play('SHIP_BUILT') 1672 1672 else … … 1682 1682 end; 1683 1683 1684 function Prio(iix: integer): integer;1684 function Prio(iix: Integer): Integer; 1685 1685 begin 1686 1686 case Imp[iix].Kind of 1687 1687 ikWonder: 1688 result := iix + 10000;1688 Result := iix + 10000; 1689 1689 ikNatLocal, ikNatGlobal: 1690 1690 case iix of 1691 1691 imPalace: 1692 result := 0;1692 Result := 0; 1693 1693 else 1694 result := iix + 20000;1694 Result := iix + 20000; 1695 1695 end; 1696 1696 else 1697 1697 case iix of 1698 1698 imTownHall, imCourt: 1699 result := iix + 30000;1699 Result := iix + 30000; 1700 1700 imAqueduct, imSewer: 1701 result := iix + 40000;1701 Result := iix + 40000; 1702 1702 imTemple, imTheater, imCathedral: 1703 result := iix + 50000;1704 else 1705 result := iix + 90000;1703 Result := iix + 50000; 1704 else 1705 Result := iix + 90000; 1706 1706 end; 1707 1707 end; … … 1718 1718 end; 1719 1719 1720 procedure TCityDlg.ChangeCity( d: integer);1720 procedure TCityDlg.ChangeCity(D: Integer); 1721 1721 var 1722 cixNew: integer;1722 cixNew: Integer; 1723 1723 begin 1724 1724 cixNew := cix; 1725 1725 repeat 1726 cixNew := (cixNew + MyRO.nCity + d) mod MyRO.nCity;1726 cixNew := (cixNew + MyRO.nCity + D) mod MyRO.nCity; 1727 1727 until (MyCity[cixNew].Loc >= 0) or (cixNew = cix); 1728 1728 if cixNew <> cix then … … 1766 1766 end; 1767 1767 1768 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: integer);1768 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: Integer); 1769 1769 var 1770 1770 Advice: TCityTileAdviceData; 1771 1771 begin 1772 assert(not supervising);1773 assert(cix >= 0);1772 Assert(not Supervising); 1773 Assert(cix >= 0); 1774 1774 MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or 1775 1775 (iResourceWeights shl 4); 1776 c.Status := MyCity[cix].Status;1776 C.Status := MyCity[cix].Status; 1777 1777 if iResourceWeights > 0 then 1778 1778 begin 1779 1779 Advice.ResourceWeights := OfferedResourceWeights[iResourceWeights]; 1780 Server(sGetCityTileAdvice, me, cix, Advice);1780 Server(sGetCityTileAdvice, Me, cix, Advice); 1781 1781 if Advice.Tiles <> MyCity[cix].Tiles then 1782 Server(sSetCityTiles, me, cix, Advice.Tiles);1782 Server(sSetCityTiles, Me, cix, Advice.Tiles); 1783 1783 end; 1784 1784 end; … … 1786 1786 procedure SortImprovements; 1787 1787 var 1788 i, j, k: integer;1789 begin 1790 for i:= 0 to nImp - 1 do1791 ImpSorted[ i] := i;1792 for i:= 0 to nImp - 2 do1793 for j := i+ 1 to nImp - 1 do1794 if Prio(ImpSorted[ i]) > Prio(ImpSorted[j]) then begin1795 k := ImpSorted[i];1796 ImpSorted[ i] := ImpSorted[j];1797 ImpSorted[ j] := k;1788 I, J, K: Integer; 1789 begin 1790 for I := 0 to nImp - 1 do 1791 ImpSorted[I] := I; 1792 for I := 0 to nImp - 2 do 1793 for J := I + 1 to nImp - 1 do 1794 if Prio(ImpSorted[I]) > Prio(ImpSorted[J]) then begin 1795 K := ImpSorted[I]; 1796 ImpSorted[I] := ImpSorted[J]; 1797 ImpSorted[J] := K; 1798 1798 end; 1799 1799 end; -
trunk/LocalPlayer/CityType.pas
r442 r447 18 18 procedure FormShow(Sender: TObject); 19 19 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 20 Shift: TShiftState; x, y: integer);20 Shift: TShiftState; X, Y: Integer); 21 21 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 22 Shift: TShiftState; x, y: integer);22 Shift: TShiftState; X, Y: Integer); 23 23 procedure FormClose(Sender: TObject; var Action: TCloseAction); 24 24 procedure DeleteBtnClick(Sender: TObject); … … 28 28 procedure OffscreenPaint; override; 29 29 private 30 nPool, dragiix, ctype: integer;31 Pooliix: array [0 .. nImp - 1] of integer;30 nPool, dragiix, ctype: Integer; 31 Pooliix: array [0 .. nImp - 1] of Integer; 32 32 listed: Set of 0 .. nImp; 33 Changed: boolean;34 procedure LoadType(NewType: integer);33 Changed: Boolean; 34 procedure LoadType(NewType: Integer); 35 35 procedure SaveType; 36 36 end; … … 82 82 procedure TCityTypeDlg.OffscreenPaint; 83 83 var 84 i, iix: integer;85 s: string;84 I, iix: Integer; 85 S: string; 86 86 begin 87 87 inherited; 88 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);88 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 89 89 FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow); 90 90 FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow); … … 92 92 yPool - yList - 32 * nListRow); 93 93 94 Frame( offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,94 Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255, 95 95 yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 96 Frame( offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,96 Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow, 97 97 InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight, 98 98 MainTexture.ColorBevelShade); 99 Frame( offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,99 Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow, 100 100 InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight, 101 101 MainTexture.ColorBevelShade); 102 Frame( offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,102 Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1, 103 103 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 104 for i:= 0 to nCityType - 1 do105 begin 106 RFrame( offscreen.Canvas, xSwitch + i * 42, ySwitch, xSwitch + 39 + i* 42,104 for I := 0 to nCityType - 1 do 105 begin 106 RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42, 107 107 ySwitch + 23, MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 108 if i= ctype then109 Frame( offscreen.Canvas, xSwitch + 1 + i* 42, ySwitch + 1,110 xSwitch + 38 + i* 42, ySwitch + 22, MainTexture.ColorBevelShade,108 if I = ctype then 109 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 110 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade, 111 111 MainTexture.ColorBevelLight) 112 112 else 113 Frame( offscreen.Canvas, xSwitch + 1 + i* 42, ySwitch + 1,114 xSwitch + 38 + i* 42, ySwitch + 22, MainTexture.ColorBevelLight,113 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 114 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight, 115 115 MainTexture.ColorBevelShade); 116 BitBltCanvas( offscreen.Canvas, xSwitch + 2 + i* 42, ySwitch + 2,117 xSizeSmall, ySizeSmall, SmallImp.Canvas, ( i+ 3) * xSizeSmall, 0);118 end; 119 RisedTextOut( offscreen.Canvas, 8, yList + 32 * nListRow + 2,116 BitBltCanvas(Offscreen.Canvas, xSwitch + 2 + I * 42, ySwitch + 2, 117 xSizeSmall, ySizeSmall, SmallImp.Canvas, (I + 3) * xSizeSmall, 0); 118 end; 119 RisedTextOut(Offscreen.Canvas, 8, yList + 32 * nListRow + 2, 120 120 Phrases.Lookup('BUILDORDER')); 121 RisedTextOut( offscreen.Canvas, 8, ySwitch + 26,121 RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26, 122 122 Phrases.Lookup('CITYTYPE', ctype)); 123 s:= Phrases.Lookup('BUILDREST');124 RisedTextOut( offscreen.Canvas,125 (InnerWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2,126 yList + 72 + 32 * nListRow, s);127 128 with offscreen.Canvas do129 begin 130 for i:= 1 to nListRow - 1 do131 DLine( offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,132 yList - 1 + 32 * i, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);133 for i:= 0 to nListCol * nListRow - 1 do134 begin 135 s := IntToStr(i+ 1);123 S := Phrases.Lookup('BUILDREST'); 124 RisedTextOut(Offscreen.Canvas, 125 (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 126 yList + 72 + 32 * nListRow, S); 127 128 with Offscreen.Canvas do 129 begin 130 for I := 1 to nListRow - 1 do 131 DLine(Offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol, 132 yList - 1 + 32 * I, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 133 for I := 0 to nListCol * nListRow - 1 do 134 begin 135 S := IntToStr(I + 1); 136 136 Font.Color := MainTexture.ColorTextLight; 137 Textout(xList + 20 + i mod nListCol * 42 - TextWidth(s) div 2,138 yList + 15 + i div nListCol * 32 - TextHeight(s) div 2, s);139 end; 140 end; 141 142 i:= 0;143 while MyData.ImpOrder[ctype, i] >= 0 do144 begin 145 RFrame( offscreen.Canvas, xList + 20 - xSizeSmall div 2 + imod nListCol *146 42, yList + 15 - ySizeSmall div 2 + idiv nListCol * 32,147 xList + 21 + xSizeSmall div 2 + imod nListCol * 42,148 yList + 16 + ySizeSmall div 2 + idiv nListCol * 32,137 Textout(xList + 20 + I mod nListCol * 42 - TextWidth(S) div 2, 138 yList + 15 + I div nListCol * 32 - TextHeight(S) div 2, S); 139 end; 140 end; 141 142 I := 0; 143 while MyData.ImpOrder[ctype, I] >= 0 do 144 begin 145 RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol * 146 42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32, 147 xList + 21 + xSizeSmall div 2 + I mod nListCol * 42, 148 yList + 16 + ySizeSmall div 2 + I div nListCol * 32, 149 149 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 150 BitBltCanvas( offscreen.Canvas, xList + 21 - xSizeSmall div 2 +151 i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + idiv nListCol * 32,150 BitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 + 151 I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32, 152 152 xSizeSmall, ySizeSmall, SmallImp.Canvas, 153 MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,154 (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *153 MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall, 154 (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 * 155 155 ySizeSmall); 156 inc(i);156 Inc(I); 157 157 end; 158 158 … … 165 165 begin 166 166 Pooliix[nPool] := iix; 167 RFrame( offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +167 RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 + 168 168 nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 + 169 169 nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 + … … 171 171 nPool div nPoolCol * 32, MainTexture.ColorBevelLight, 172 172 MainTexture.ColorBevelShade); 173 BitBltCanvas( offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +173 BitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 + 174 174 nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 + 175 175 nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas, 176 176 iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 * 177 177 ySizeSmall); 178 inc(nPool);178 Inc(nPool); 179 179 end; 180 180 DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0; … … 182 182 if dragiix >= 0 then 183 183 begin 184 ImpImage( offscreen.Canvas, xView + 9, yView + 5, dragiix);185 s:= Phrases.Lookup('IMPROVEMENTS', dragiix);186 RisedTextOut( offscreen.Canvas,187 xView + 36 - BiColorTextWidth( offscreen.Canvas, s) div 2,188 ySwitch + 26, s);184 ImpImage(Offscreen.Canvas, xView + 9, yView + 5, dragiix); 185 S := Phrases.Lookup('IMPROVEMENTS', dragiix); 186 RisedTextOut(Offscreen.Canvas, 187 xView + 36 - BiColorTextWidth(Offscreen.Canvas, S) div 2, 188 ySwitch + 26, S); 189 189 end; 190 190 MarkUsedOffscreen(InnerWidth, InnerHeight); 191 191 end; 192 192 193 procedure TCityTypeDlg.LoadType(NewType: integer);194 var 195 i: integer;193 procedure TCityTypeDlg.LoadType(NewType: Integer); 194 var 195 I: Integer; 196 196 begin 197 197 ctype := NewType; 198 198 listed := []; 199 i:= 0;200 while MyData.ImpOrder[ctype, i] >= 0 do201 begin 202 include(listed, MyData.ImpOrder[ctype, i]);203 inc(i);204 end; 205 Changed := false;199 I := 0; 200 while MyData.ImpOrder[ctype, I] >= 0 do 201 begin 202 Include(listed, MyData.ImpOrder[ctype, I]); 203 Inc(I); 204 end; 205 Changed := False; 206 206 end; 207 207 208 208 procedure TCityTypeDlg.SaveType; 209 209 var 210 cix: integer;210 cix: Integer; 211 211 begin 212 212 if Changed then … … 215 215 if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then 216 216 AutoBuild(cix, MyData.ImpOrder[ctype]); 217 Changed := false;217 Changed := False; 218 218 end; 219 219 end; … … 232 232 233 233 procedure TCityTypeDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 234 Shift: TShiftState; x, y: integer);235 var 236 i: integer;237 begin 238 x := x- SideFrame;239 y := y- WideFrame;240 i := (x - xList) div 42 + (y- yList) div 32 * nListCol;241 if ( i < nImp) and (MyData.ImpOrder[ctype, i] >= 0) and242 ( x > xList + 2 + imod nListCol * 42) and243 ( y > yList + 5 + idiv nListCol * 32) and244 ( x < xList + 3 + 36 + imod nListCol * 42) and245 ( y < yList + 6 + 20 + idiv nListCol * 32) then234 Shift: TShiftState; X, Y: Integer); 235 var 236 I: Integer; 237 begin 238 X := X - SideFrame; 239 Y := Y - WideFrame; 240 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 241 if (I < nImp) and (MyData.ImpOrder[ctype, I] >= 0) and 242 (X > xList + 2 + I mod nListCol * 42) and 243 (Y > yList + 5 + I div nListCol * 32) and 244 (X < xList + 3 + 36 + I mod nListCol * 42) and 245 (Y < yList + 6 + 20 + I div nListCol * 32) then 246 246 begin 247 247 if ssShift in Shift then 248 248 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, 249 MyData.ImpOrder[ctype, i])249 MyData.ImpOrder[ctype, I]) 250 250 else 251 251 begin 252 dragiix := MyData.ImpOrder[ctype, i];252 dragiix := MyData.ImpOrder[ctype, I]; 253 253 Screen.Cursor := crImpDrag; 254 254 SmartUpdateContent; 255 255 end; 256 exit;257 end; 258 i := (x - xPool) div 42 + (y- yPool) div 32 * nPoolCol;259 if ( i < nPool) and (x > xPool + 2 + imod nPoolCol * 42) and260 ( y > yPool + 5 + idiv nPoolCol * 32) and261 ( x < xPool + 3 + 36 + imod nPoolCol * 42) and262 ( y < yPool + 6 + 20 + idiv nPoolCol * 32) then256 Exit; 257 end; 258 I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol; 259 if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and 260 (Y > yPool + 5 + I div nPoolCol * 32) and 261 (X < xPool + 3 + 36 + I mod nPoolCol * 42) and 262 (Y < yPool + 6 + 20 + I div nPoolCol * 32) then 263 263 begin 264 264 if ssShift in Shift then 265 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[ i])265 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I]) 266 266 else 267 267 begin 268 dragiix := Pooliix[ i];268 dragiix := Pooliix[I]; 269 269 Screen.Cursor := crImpDrag; 270 270 SmartUpdateContent; 271 271 end; 272 exit;273 end; 274 i := (x- xSwitch) div 42;275 if ( i < nCityType) and (x > xSwitch + 2 + i* 42) and276 ( x < xSwitch + 3 + 36 + i * 42) and (y >= ySwitch + 2) and (y< ySwitch + 22)272 Exit; 273 end; 274 I := (X - xSwitch) div 42; 275 if (I < nCityType) and (X > xSwitch + 2 + I * 42) and 276 (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22) 277 277 then 278 278 begin 279 279 SaveType; 280 LoadType( i);280 LoadType(I); 281 281 SmartUpdateContent; 282 282 end; … … 284 284 285 285 procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 286 Shift: TShiftState; x, y: integer);287 288 procedure UnList(iix: integer);286 Shift: TShiftState; X, Y: Integer); 287 288 procedure UnList(iix: Integer); 289 289 var 290 i: integer;291 begin 292 i:= 0;293 while (MyData.ImpOrder[ctype, i] >= 0) and294 (MyData.ImpOrder[ctype, i] <> iix) do295 inc(i);296 assert(MyData.ImpOrder[ctype, i] = iix);297 move(MyData.ImpOrder[ctype, i + 1], MyData.ImpOrder[ctype, i], nImp - i);290 I: Integer; 291 begin 292 I := 0; 293 while (MyData.ImpOrder[ctype, I] >= 0) and 294 (MyData.ImpOrder[ctype, I] <> iix) do 295 Inc(I); 296 Assert(MyData.ImpOrder[ctype, I] = iix); 297 Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I); 298 298 Exclude(listed, iix); 299 299 end; 300 300 301 301 var 302 i: integer;303 begin 304 x := x- SideFrame;305 y := y- WideFrame;302 I: Integer; 303 begin 304 X := X - SideFrame; 305 Y := Y - WideFrame; 306 306 if dragiix >= 0 then 307 307 begin 308 if ( x >= xList) and (x < xList + nListCol * 42) and (y>= yList) and309 ( y< yList + nListRow * 32) then308 if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and 309 (Y < yList + nListRow * 32) then 310 310 begin 311 311 if dragiix in listed then 312 312 UnList(dragiix); 313 i := (x - xList) div 42 + (y- yList) div 32 * nListCol;314 while ( i > 0) and (MyData.ImpOrder[ctype, i- 1] < 0) do315 dec(i);316 move(MyData.ImpOrder[ctype, i], MyData.ImpOrder[ctype, i+ 1],317 nImp - i- 1);318 MyData.ImpOrder[ctype, i] := dragiix;319 include(listed, dragiix);320 Changed := true;313 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 314 while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do 315 Dec(I); 316 Move(MyData.ImpOrder[ctype, I], MyData.ImpOrder[ctype, I + 1], 317 nImp - I - 1); 318 MyData.ImpOrder[ctype, I] := dragiix; 319 Include(listed, dragiix); 320 Changed := True; 321 321 end 322 else if (dragiix in listed) and ( x >= xPool) and (x< xPool + nPoolCol * 42)323 and ( y >= yPool) and (y< yPool + nPoolRow * 32) then322 else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42) 323 and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then 324 324 begin 325 325 UnList(dragiix); 326 Changed := true;326 Changed := True; 327 327 end; 328 328 dragiix := -1; … … 340 340 procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject); 341 341 begin 342 fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));342 FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1)); 343 343 listed := []; 344 Changed := true;344 Changed := True; 345 345 SmartUpdateContent; 346 346 end; -
trunk/LocalPlayer/ClientTools.pas
r442 r447 9 9 const 10 10 nOfferedResourceWeights = 6; 11 OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of cardinal =11 OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of Cardinal = 12 12 (rwOff, rwMaxScience, rwForceScience, rwMaxGrowth, rwForceProd, rwMaxProd); 13 13 14 14 type 15 TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of shortint;16 TEnhancementJobs = array [0 .. 11, 0 .. 7] of byte;15 TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of ShortInt; 16 TEnhancementJobs = array [0 .. 11, 0 .. 7] of Byte; 17 17 JobResultSet = set of 0 .. 39; 18 18 … … 36 36 Server: TServerCall; 37 37 G: TNewGameData; 38 me: integer;38 Me: Integer; 39 39 MyRO: ^TPlayerContext; 40 40 MyMap: ^TTileList; … … 43 43 MyModel: ^TModelList; 44 44 45 AdvValue: array [0 .. nAdv - 1] of integer;46 47 function dLoc(Loc, dx, dy: integer): integer;48 function Distance(Loc0, Loc1: integer): integer;49 function UnrestAtLoc(uix, Loc: integer): boolean;50 function GetMoveAdvice(uix, ToLoc: integer;51 var MoveAdviceData: TMoveAdviceData): integer;52 function ColorOfHealth(Health: integer): integer;53 function IsMultiPlayerGame: boolean;54 procedure ItsMeAgain( p: integer);55 function GetAge( p: integer): integer;56 function IsCivilReportNew(Enemy: integer): boolean;57 function IsMilReportNew(Enemy: integer): boolean;58 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;59 gov, size: integer): integer;60 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;61 procedure SumCities(var TaxSum, ScienceSum: integer);62 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet = []): boolean;63 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);64 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);65 function UnitExhausted(uix: integer): boolean;66 function ModelHash(const ModelInfo: TModelInfo): integer;67 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;68 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;69 procedure DebugMessage(Level: integer; Text: string);45 AdvValue: array [0 .. nAdv - 1] of Integer; 46 47 function dLoc(Loc, dx, dy: Integer): Integer; 48 function Distance(Loc0, Loc1: Integer): Integer; 49 function UnrestAtLoc(uix, Loc: Integer): Boolean; 50 function GetMoveAdvice(uix, ToLoc: Integer; 51 var MoveAdviceData: TMoveAdviceData): Integer; 52 function ColorOfHealth(Health: Integer): Integer; 53 function IsMultiPlayerGame: Boolean; 54 procedure ItsMeAgain(P: Integer); 55 function GetAge(P: Integer): Integer; 56 function IsCivilReportNew(Enemy: Integer): Boolean; 57 function IsMilReportNew(Enemy: Integer): Boolean; 58 function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean; 59 gov, size: Integer): Integer; 60 function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer; 61 procedure SumCities(var TaxSum, ScienceSum: Integer); 62 function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet = []): Boolean; 63 procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo); 64 procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo); 65 function UnitExhausted(uix: Integer): Boolean; 66 function ModelHash(const ModelInfo: TModelInfo): Integer; 67 function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer; 68 function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean; 69 procedure DebugMessage(Level: Integer; Text: string); 70 70 procedure CityOptimizer_BeginOfTurn; 71 procedure CityOptimizer_CityChange(cix: integer);72 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);73 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);74 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);71 procedure CityOptimizer_CityChange(cix: Integer); 72 procedure CityOptimizer_TileBecomesAvailable(Loc: Integer); 73 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer); 74 procedure CityOptimizer_BeforeRemoveUnit(uix: Integer); 75 75 procedure CityOptimizer_AfterRemoveUnit; 76 76 procedure CityOptimizer_EndOfTurn; … … 84 84 85 85 var 86 CityNeedsOptimize: array [0 .. ncmax - 1] of boolean;87 88 function dLoc(Loc, dx, dy: integer): integer;89 var 90 y0: integer;86 CityNeedsOptimize: array [0 .. ncmax - 1] of Boolean; 87 88 function dLoc(Loc, dx, dy: Integer): Integer; 89 var 90 y0: Integer; 91 91 begin 92 92 y0 := (Loc + G.lx * 1024) div G.lx - 1024; … … 94 94 end; 95 95 96 function Distance(Loc0, Loc1: integer): integer;97 var 98 dx, dy: integer;96 function Distance(Loc0, Loc1: Integer): Integer; 97 var 98 dx, dy: Integer; 99 99 begin 100 100 Inc(Loc0, G.lx * 1024); … … 106 106 end; 107 107 108 function UnrestAtLoc(uix, Loc: integer): boolean;109 var 110 uix1: integer;108 function UnrestAtLoc(uix, Loc: Integer): Boolean; 109 var 110 uix1: Integer; 111 111 begin 112 112 Result := False; … … 114 114 case MyRO.Government of 115 115 gRepublic, gFuture: 116 Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> me) and116 Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> Me) and 117 117 (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance); 118 118 gDemocracy: 119 Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> me) and119 Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> Me) and 120 120 (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance); 121 121 end; … … 127 127 end; 128 128 129 function GetMoveAdvice(uix, ToLoc: integer;130 var MoveAdviceData: TMoveAdviceData): integer;131 var 132 MinEndHealth: integer;129 function GetMoveAdvice(uix, ToLoc: Integer; 130 var MoveAdviceData: TMoveAdviceData): Integer; 131 var 132 MinEndHealth: Integer; 133 133 begin 134 134 if MyModel[MyUn[uix].mix].Domain = dGround then … … 142 142 MoveAdviceData.MoreTurns := 999; 143 143 MoveAdviceData.MaxHostile_MovementLeft := MyUn[uix].Health - MinEndHealth; 144 Result := Server(sGetMoveAdvice, me, uix, MoveAdviceData);144 Result := Server(sGetMoveAdvice, Me, uix, MoveAdviceData); 145 145 if (MinEndHealth <= 1) or (Result <> eNoWay) then 146 exit;146 Exit; 147 147 end; 148 148 case MinEndHealth of … … 159 159 end; 160 160 161 function ColorOfHealth(Health: integer): integer;162 var 163 red, green: integer;164 begin 165 green := 400 * Health div 100;166 if green > 200 then167 green := 200;168 red := 510 * (100 - Health) div 100;169 if red > 255 then170 red := 255;171 Result := green shl 8 + red;172 end; 173 174 function IsMultiPlayerGame: boolean;175 var 176 p1: integer;161 function ColorOfHealth(Health: Integer): Integer; 162 var 163 Red, Green: Integer; 164 begin 165 Green := 400 * Health div 100; 166 if Green > 200 then 167 Green := 200; 168 Red := 510 * (100 - Health) div 100; 169 if Red > 255 then 170 Red := 255; 171 Result := Green shl 8 + Red; 172 end; 173 174 function IsMultiPlayerGame: Boolean; 175 var 176 p1: Integer; 177 177 begin 178 178 Result := False; … … 182 182 end; 183 183 184 procedure ItsMeAgain( p: integer);185 begin 186 if G.RO[ p] <> nil then187 MyRO := pointer(G.RO[p])188 else if G.SuperVisorRO[ p] <> nil then189 MyRO := pointer(G.SuperVisorRO[p])184 procedure ItsMeAgain(P: Integer); 185 begin 186 if G.RO[P] <> nil then 187 MyRO := Pointer(G.RO[P]) 188 else if G.SuperVisorRO[P] <> nil then 189 MyRO := Pointer(G.SuperVisorRO[P]) 190 190 else 191 exit;192 me := p;193 MyMap := pointer(MyRO.Map);194 MyUn := pointer(MyRO.Un);195 MyCity := pointer(MyRO.City);196 MyModel := pointer(MyRO.Model);197 end; 198 199 function GetAge( p: integer): integer;200 var 201 i: integer;202 begin 203 if p = me then begin191 Exit; 192 Me := P; 193 MyMap := Pointer(MyRO.Map); 194 MyUn := Pointer(MyRO.Un); 195 MyCity := Pointer(MyRO.City); 196 MyModel := Pointer(MyRO.Model); 197 end; 198 199 function GetAge(P: Integer): Integer; 200 var 201 I: Integer; 202 begin 203 if P = Me then begin 204 204 Result := 0; 205 for i:= 1 to 3 do206 if MyRO.Tech[AgePreq[ i]] >= tsApplicable then207 Result := i;205 for I := 1 to 3 do 206 if MyRO.Tech[AgePreq[I]] >= tsApplicable then 207 Result := I; 208 208 end else begin 209 209 Result := 0; 210 for i:= 1 to 3 do211 if MyRO.EnemyReport[ p].Tech[AgePreq[i]] >= tsApplicable then212 Result := i;213 end; 214 end; 215 216 function IsCivilReportNew(Enemy: integer): boolean;217 var 218 i: integer;219 begin 220 assert(Enemy <> me);221 i:= MyRO.EnemyReport[Enemy].TurnOfCivilReport;222 Result := ( i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);223 end; 224 225 function IsMilReportNew(Enemy: integer): boolean;226 var 227 i: integer;228 begin 229 assert(Enemy <> me);230 i:= MyRO.EnemyReport[Enemy].TurnOfMilReport;231 Result := ( i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);232 end; 233 234 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;235 gov, size: integer): integer;210 for I := 1 to 3 do 211 if MyRO.EnemyReport[P].Tech[AgePreq[I]] >= tsApplicable then 212 Result := I; 213 end; 214 end; 215 216 function IsCivilReportNew(Enemy: Integer): Boolean; 217 var 218 I: Integer; 219 begin 220 Assert(Enemy <> Me); 221 I := MyRO.EnemyReport[Enemy].TurnOfCivilReport; 222 Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me); 223 end; 224 225 function IsMilReportNew(Enemy: Integer): Boolean; 226 var 227 I: Integer; 228 begin 229 Assert(Enemy <> Me); 230 I := MyRO.EnemyReport[Enemy].TurnOfMilReport; 231 Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me); 232 end; 233 234 function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean; 235 gov, size: Integer): Integer; 236 236 begin 237 237 Result := FoodSurplus; … … 241 241 end; 242 242 243 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;244 var 245 i: integer;243 function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer; 244 var 245 I: Integer; 246 246 begin 247 247 Result := 0; … … 258 258 Inc(Result, CityReport.FoodSurplus); 259 259 end; 260 for i:= nWonder to nImp - 1 do261 if MyCity[cix].Built[ i] > 0 then262 Dec(Result, Imp[ i].Maint);263 end; 264 265 procedure SumCities(var TaxSum, ScienceSum: integer);266 var 267 cix: integer;260 for I := nWonder to nImp - 1 do 261 if MyCity[cix].Built[I] > 0 then 262 Dec(Result, Imp[I].Maint); 263 end; 264 265 procedure SumCities(var TaxSum, ScienceSum: Integer); 266 var 267 cix: Integer; 268 268 CityReport: TCityReportNew; 269 269 begin … … 271 271 ScienceSum := 0; 272 272 if MyRO.Government = gAnarchy then 273 exit;273 Exit; 274 274 for cix := 0 to MyRO.nCity - 1 do 275 275 if MyCity[cix].Loc >= 0 then … … 278 278 CityReport.HypoTaxRate := -1; 279 279 CityReport.HypoLuxuryRate := -1; 280 Server(sGetCityReportNew, me, cix, CityReport);280 Server(sGetCityReportNew, Me, cix, CityReport); 281 281 if (CityReport.HappinessBalance >= 0) { no disorder } and 282 282 (MyCity[cix].Flags and chCaptured = 0) then // not captured … … 286 286 end; 287 287 288 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet): boolean;289 var 290 Test: integer;291 begin 292 Test := Server(sStartJob + Job shl 4 - sExecute, me, uix, nil^);288 function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet): Boolean; 289 var 290 Test: Integer; 291 begin 292 Test := Server(sStartJob + Job shl 4 - sExecute, Me, uix, nil^); 293 293 Result := (Test >= rExecuted) or (Test in IgnoreResults); 294 294 end; 295 295 296 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);297 var 298 i, Cnt: integer;296 procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo); 297 var 298 I, Cnt: Integer; 299 299 begin 300 300 if MyMap[Loc] and fOwned <> 0 then 301 301 begin 302 Server(sGetDefender, me, Loc, uix);302 Server(sGetDefender, Me, Loc, uix); 303 303 Cnt := 0; 304 for i:= 0 to MyRO.nUn - 1 do305 if MyUn[ i].Loc = Loc then304 for I := 0 to MyRO.nUn - 1 do 305 if MyUn[I].Loc = Loc then 306 306 Inc(Cnt); 307 MakeUnitInfo( me, MyUn[uix], UnitInfo);307 MakeUnitInfo(Me, MyUn[uix], UnitInfo); 308 308 if Cnt > 1 then 309 309 UnitInfo.Flags := UnitInfo.Flags or unMulti; … … 318 318 end; 319 319 320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);320 procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo); 321 321 begin 322 322 if MyMap[Loc] and fOwned <> 0 then … … 328 328 with CityInfo do 329 329 begin 330 Owner := me;330 Owner := Me; 331 331 ID := MyCity[cix].ID; 332 332 size := MyCity[cix].size; … … 356 356 end; 357 357 358 function UnitExhausted(uix: integer): boolean;358 function UnitExhausted(uix: Integer): Boolean; 359 359 // check if another move of this unit is still possible 360 360 var 361 dx, dy: integer;361 dx, dy: Integer; 362 362 begin 363 363 Result := True; 364 364 if (MyUn[uix].Movement > 0) or 365 (MyRO.Wonder[woShinkansen].EffectiveOwner = me) then365 (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) then 366 366 if (MyUn[uix].Movement >= 100) or 367 367 ((MyModel[MyUn[uix].mix].Kind = mkCaravan) and … … 373 373 if abs(dx) + abs(dy) = 2 then 374 374 if Server(sMoveUnit - sExecute + dx and 7 shl 4 + dy and 375 7 shl 7, me, uix, nil^) >= rExecuted then375 7 shl 7, Me, uix, nil^) >= rExecuted then 376 376 Result := False; 377 377 end; 378 378 379 function ModelHash(const ModelInfo: TModelInfo): integer;380 var 381 i, FeatureCode, Hash1, Hash2, Hash2r, d: cardinal;379 function ModelHash(const ModelInfo: TModelInfo): Integer; 380 var 381 I, FeatureCode, Hash1, Hash2, Hash2r, D: Cardinal; 382 382 begin 383 383 with ModelInfo do 384 384 if Kind > mkEnemyDeveloped then 385 Result := integer($C0000000 + Speed div 50 + Kind shl 8)385 Result := Integer($C0000000 + Speed div 50 + Kind shl 8) 386 386 else 387 387 begin 388 388 FeatureCode := 0; 389 for i:= mcFirstNonCap to nFeature - 1 do390 if 1 shl Domain and Feature[ i].Domains <> 0 then389 for I := mcFirstNonCap to nFeature - 1 do 390 if 1 shl Domain and Feature[I].Domains <> 0 then 391 391 begin 392 392 FeatureCode := FeatureCode * 2; 393 if 1 shl ( i- mcFirstNonCap) <> 0 then393 if 1 shl (I - mcFirstNonCap) <> 0 then 394 394 Inc(FeatureCode); 395 395 end; … … 397 397 dGround: 398 398 begin 399 assert(FeatureCode < 1 shl 8);400 assert(Attack < 5113);401 assert(Defense < 2273);402 assert(Cost < 1611);399 Assert(FeatureCode < 1 shl 8); 400 Assert(Attack < 5113); 401 Assert(Defense < 2273); 402 Assert(Cost < 1611); 403 403 Hash1 := (Attack * 2273 + Defense) * 9 + (Speed - 150) div 50; 404 404 Hash2 := FeatureCode * 1611 + Cost; … … 406 406 dSea: 407 407 begin 408 assert(FeatureCode < 1 shl 9);409 assert(Attack < 12193);410 assert(Defense < 6097);411 assert(Cost < 4381);408 Assert(FeatureCode < 1 shl 9); 409 Assert(Attack < 12193); 410 Assert(Defense < 6097); 411 Assert(Cost < 4381); 412 412 Hash1 := ((Attack * 6097 + Defense) * 5 + 413 413 (Speed - 350) div 100) * 2; … … 419 419 dAir: 420 420 begin 421 assert(FeatureCode < 1 shl 5);422 assert(Attack < 2407);423 assert(Defense < 1605);424 assert(Bombs < 4813);425 assert(Cost < 2089);421 Assert(FeatureCode < 1 shl 5); 422 Assert(Attack < 2407); 423 Assert(Defense < 1605); 424 Assert(Bombs < 4813); 425 Assert(Cost < 2089); 426 426 Hash1 := (Attack * 1605 + Defense) shl 5 + FeatureCode; 427 427 Hash2 := ((Bombs * 7 + ATrans_Fuel) * 4 + TTrans) * 2089 + Cost; … … 429 429 end; 430 430 Hash2r := 0; 431 for i:= 0 to 7 do431 for I := 0 to 7 do 432 432 begin 433 433 Hash2r := Hash2r * 13; 434 d:= Hash2 div 13;435 Inc(Hash2r, Hash2 - d* 13);436 Hash2 := d;434 D := Hash2 div 13; 435 Inc(Hash2r, Hash2 - D * 13); 436 Hash2 := D; 437 437 end; 438 Result := integer(Domain shl 30 + Hash1 xor Hash2r);438 Result := Integer(Domain shl 30 + Hash1 xor Hash2r); 439 439 end; 440 440 end; 441 441 442 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;442 function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer; 443 443 { return values: 444 444 eJobDone - all applicable jobs done … … 446 446 eDied - job done and died (thurst) } 447 447 var 448 stage, NextJob, Tile: integer;448 stage, NextJob, Tile: Integer; 449 449 Done: set of jNone .. jPoll; 450 450 begin … … 452 452 Tile := MyMap[MyUn[uix].Loc]; 453 453 if Tile and fRoad <> 0 then 454 include(Done, jRoad);454 Include(Done, jRoad); 455 455 if Tile and fRR <> 0 then 456 include(Done, jRR);456 Include(Done, jRR); 457 457 if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) then 458 include(Done, jIrr);458 Include(Done, jIrr); 459 459 if Tile and fTerImp = tiFarm then 460 include(Done, jFarm);460 Include(Done, jFarm); 461 461 if Tile and fTerImp = tiMine then 462 include(Done, jMine);462 Include(Done, jMine); 463 463 if Tile and fPoll = 0 then 464 include(Done, jPoll);464 Include(Done, jPoll); 465 465 466 466 if MyUn[uix].Job = jNone then … … 485 485 Break; 486 486 end; // tile enhancement complete 487 Result := Server(sStartJob + NextJob shl 4, me, uix, nil^);488 include(Done, NextJob);489 end; 490 end; 491 492 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;493 var 494 i, NewProject: integer;487 Result := Server(sStartJob + NextJob shl 4, Me, uix, nil^); 488 Include(Done, NextJob); 489 end; 490 end; 491 492 function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean; 493 var 494 I, NewProject: Integer; 495 495 begin 496 496 Result := False; … … 498 498 (MyCity[cix].Flags and chProduction <> 0) then 499 499 begin 500 i:= 0;500 I := 0; 501 501 repeat 502 while (ImpOrder[ i] >= 0) and (MyCity[cix].Built[ImpOrder[i]] > 0) do503 Inc( i);504 if ImpOrder[ i] < 0 then502 while (ImpOrder[I] >= 0) and (MyCity[cix].Built[ImpOrder[I]] > 0) do 503 Inc(I); 504 if ImpOrder[I] < 0 then 505 505 Break; 506 assert(i< nImp);507 NewProject := cpImp + ImpOrder[ i];508 if Server(sSetCityProject, me, cix, NewProject) >= rExecuted then506 Assert(I < nImp); 507 NewProject := cpImp + ImpOrder[I]; 508 if Server(sSetCityProject, Me, cix, NewProject) >= rExecuted then 509 509 begin 510 510 Result := True; … … 512 512 Break; 513 513 end; 514 Inc( i);514 Inc(I); 515 515 until False; 516 516 end; … … 519 519 procedure CalculateAdvValues; 520 520 var 521 i, j: integer;522 known: array [0 .. nAdv - 1] of integer;523 524 procedure MarkPreqs( i: integer);525 begin 526 if known[ i] = 0 then521 I, J: Integer; 522 known: array [0 .. nAdv - 1] of Integer; 523 524 procedure MarkPreqs(I: Integer); 525 begin 526 if known[I] = 0 then 527 527 begin 528 known[ i] := 1;529 if ( i <> adScience) and (i<> adMassProduction) then528 known[I] := 1; 529 if (I <> adScience) and (I <> adMassProduction) then 530 530 begin 531 if (AdvPreq[ i, 0] >= 0) then532 MarkPreqs(AdvPreq[ i, 0]);533 if (AdvPreq[ i, 1] >= 0) then534 MarkPreqs(AdvPreq[ i, 1]);531 if (AdvPreq[I, 0] >= 0) then 532 MarkPreqs(AdvPreq[I, 0]); 533 if (AdvPreq[I, 1] >= 0) then 534 MarkPreqs(AdvPreq[I, 1]); 535 535 end; 536 536 end; … … 539 539 begin 540 540 FillChar(AdvValue, SizeOf(AdvValue), 0); 541 for i:= 0 to nAdv - 1 do541 for I := 0 to nAdv - 1 do 542 542 begin 543 543 FillChar(known, SizeOf(known), 0); 544 MarkPreqs( i);545 for j:= 0 to nAdv - 1 do546 if known[ j] > 0 then547 Inc(AdvValue[ i]);548 if iin FutureTech then549 Inc(AdvValue[ i], 3000)544 MarkPreqs(I); 545 for J := 0 to nAdv - 1 do 546 if known[J] > 0 then 547 Inc(AdvValue[I]); 548 if I in FutureTech then 549 Inc(AdvValue[I], 3000) 550 550 else if known[adMassProduction] > 0 then 551 Inc(AdvValue[ i], 2000)551 Inc(AdvValue[I], 2000) 552 552 else if known[adScience] > 0 then 553 Inc(AdvValue[ i], 1000);554 end; 555 end; 556 557 procedure DebugMessage(Level: integer; Text: string);558 begin 559 Server(sMessage, me, Level, PChar(Text)^);560 end; 561 562 function MarkCitiesAround(Loc, cixExcept: integer): boolean;553 Inc(AdvValue[I], 1000); 554 end; 555 end; 556 557 procedure DebugMessage(Level: Integer; Text: string); 558 begin 559 Server(sMessage, Me, Level, PChar(Text)^); 560 end; 561 562 function MarkCitiesAround(Loc, cixExcept: Integer): Boolean; 563 563 // return whether a city was marked 564 564 var 565 cix: integer;565 cix: Integer; 566 566 begin 567 567 Result := False; … … 576 576 end; 577 577 578 procedure OptimizeCities(CheckOnly: boolean);579 var 580 cix, fix, dx, dy, Loc1, OptiType: integer;581 Done: boolean;578 procedure OptimizeCities(CheckOnly: Boolean); 579 var 580 cix, fix, dx, dy, Loc1, OptiType: Integer; 581 Done: Boolean; 582 582 Advice: TCityTileAdviceData; 583 583 begin … … 591 591 begin 592 592 Advice.ResourceWeights := OfferedResourceWeights[OptiType]; 593 Server(sGetCityTileAdvice, me, cix, Advice);593 Server(sGetCityTileAdvice, Me, cix, Advice); 594 594 if Advice.Tiles <> MyCity[cix].Tiles then 595 595 if CheckOnly then … … 611 611 Done := False; 612 612 end; 613 Server(sSetCityTiles, me, cix, Advice.Tiles);613 Server(sSetCityTiles, Me, cix, Advice.Tiles); 614 614 end; 615 615 end; … … 621 621 procedure CityOptimizer_BeginOfTurn; 622 622 var 623 cix: integer;623 cix: Integer; 624 624 begin 625 625 FillChar(CityNeedsOptimize, MyRO.nCity - 1, 0); // false … … 634 634 end; 635 635 636 procedure CityOptimizer_CityChange(cix: integer);636 procedure CityOptimizer_CityChange(cix: Integer); 637 637 begin 638 638 if (MyRO.Government <> gAnarchy) and (cix <> -1) and (MyCity[cix].Flags and … … 644 644 end; 645 645 646 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);646 procedure CityOptimizer_TileBecomesAvailable(Loc: Integer); 647 647 begin 648 648 if (MyRO.Government <> gAnarchy) and MarkCitiesAround(Loc, -1) then … … 650 650 end; 651 651 652 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);653 var 654 fix, dx, dy, Loc1: integer;655 Done: boolean;652 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer); 653 var 654 fix, dx, dy, Loc1: Integer; 655 Done: Boolean; 656 656 begin 657 657 if (MyRO.Government <> gAnarchy) and (ReleasedTiles <> 0) then … … 672 672 end; 673 673 674 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);675 var 676 uix1: integer;674 procedure CityOptimizer_BeforeRemoveUnit(uix: Integer); 675 var 676 uix1: Integer; 677 677 begin 678 678 if MyRO.Government <> gAnarchy then … … 698 698 // all cities should already be optimized here -- only check this 699 699 var 700 cix: integer;700 cix: Integer; 701 701 begin 702 702 {$IFOPT O-} -
trunk/LocalPlayer/Diagram.pas
r442 r447 19 19 procedure ToggleBtnClick(Sender: TObject); 20 20 procedure PlayerClick(Sender: TObject); 21 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);21 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 22 22 23 23 public 24 24 procedure OffscreenPaint; override; 25 25 procedure ShowNewContent_Charts(NewMode: TWindowMode); 26 procedure ShowNewContent_Ship(NewMode: TWindowMode; p: integer = -1);26 procedure ShowNewContent_Ship(NewMode: TWindowMode; P: Integer = -1); 27 27 28 28 private 29 29 Kind: (dkChart, dkShip); 30 Player, Mode: integer;30 Player, Mode: Integer; 31 31 end; 32 32 … … 34 34 DiaDlg: TDiaDlg; 35 35 36 procedure PaintColonyShip( canvas: TCanvas; Player, Left, Width, Top: integer);36 procedure PaintColonyShip(Canvas: TCanvas; Player, Left, Width, Top: Integer); 37 37 38 38 implementation … … 45 45 const 46 46 Border = 24; 47 RoundPixels: array [0 .. nStat - 1] of integer = (0, 0, 0, 5, 5, 5);47 RoundPixels: array [0 .. nStat - 1] of Integer = (0, 0, 0, 5, 5, 5); 48 48 49 49 yArea = 48; 50 xComp: array [0 .. 5] of integer = (-60, -28, 4, 4, 36, 68);51 yComp: array [0 .. 5] of integer = (-40, -40, -79, -1, -40, -40);52 xPow: array [0 .. 3] of integer = (-116, -116, -116, -116);53 yPow: array [0 .. 3] of integer = (-28, 0, -44, 16);54 xHab: array [0 .. 1] of integer = (23, 23);55 yHab: array [0 .. 1] of integer = (-81, 1);56 57 procedure PaintColonyShip( canvas: TCanvas; Player, Left, Width, Top: integer);58 var 59 i, x, r, nComp, nPow, nHab: integer;50 xComp: array [0 .. 5] of Integer = (-60, -28, 4, 4, 36, 68); 51 yComp: array [0 .. 5] of Integer = (-40, -40, -79, -1, -40, -40); 52 xPow: array [0 .. 3] of Integer = (-116, -116, -116, -116); 53 yPow: array [0 .. 3] of Integer = (-28, 0, -44, 16); 54 xHab: array [0 .. 1] of Integer = (23, 23); 55 yHab: array [0 .. 1] of Integer = (-81, 1); 56 57 procedure PaintColonyShip(Canvas: TCanvas; Player, Left, Width, Top: Integer); 58 var 59 I, X, R, nComp, nPow, nHab: Integer; 60 60 begin 61 61 Canvas.Brush.Color := $000000; 62 62 Canvas.FillRect(Rect(Left, Top, Left + Width, Top + 200)); 63 63 Canvas.Brush.Style := bsClear; 64 ScreenTools.Frame( canvas, Left - 1, Top - 1, Left + Width, Top + 200,64 ScreenTools.Frame(Canvas, Left - 1, Top - 1, Left + Width, Top + 200, 65 65 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 66 RFrame( canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,66 RFrame(Canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1, 67 67 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 68 68 69 69 // stars 70 70 DelphiRandSeed := Player * 11111; 71 for i:= 1 to Width - 16 do71 for I := 1 to Width - 16 do 72 72 begin 73 x:= DelphiRandom((Width - 16) * 200);74 r:= DelphiRandom(13) + 28;75 Canvas.Pixels[ x div 200 + 8, xmod 200 + Top] :=76 ( r * r * r * rdiv 10001) * $10101;73 X := DelphiRandom((Width - 16) * 200); 74 R := DelphiRandom(13) + 28; 75 Canvas.Pixels[X div 200 + 8, X mod 200 + Top] := 76 (R * R * R * R div 10001) * $10101; 77 77 end; 78 78 … … 86 86 if nHab > 2 then 87 87 nHab := 2; 88 for i:= 0 to nHab - 1 do89 Sprite( canvas, HGrSystem2, Left + Width div 2 + xHab[i],90 Top + 100 + yHab[ i], 80, 80, 34, 1);91 for i:= 0 to nComp - 1 do92 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[i],93 Top + 100 + yComp[ i], 32, 80, 1, 1);88 for I := 0 to nHab - 1 do 89 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xHab[I], 90 Top + 100 + yHab[I], 80, 80, 34, 1); 91 for I := 0 to nComp - 1 do 92 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[I], 93 Top + 100 + yComp[I], 32, 80, 1, 1); 94 94 if nComp > 0 then 95 for i:= 3 downto nPow do96 Sprite( canvas, HGrSystem2, Left + Width div 2 + xPow[i] + 40,97 Top + 100 + yPow[ i], 16, 27, 1, 82);98 for i:= nPow - 1 downto 0 do99 Sprite( canvas, HGrSystem2, Left + Width div 2 + xPow[i],100 Top + 100 + yPow[ i], 56, 28, 58, 82);95 for I := 3 downto nPow do 96 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I] + 40, 97 Top + 100 + yPow[I], 16, 27, 1, 82); 98 for I := nPow - 1 downto 0 do 99 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I], 100 Top + 100 + yPow[I], 56, 28, 58, 82); 101 101 if (nComp < 3) and (nHab >= 1) then 102 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,102 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16, 103 103 Top + 100 + 7 + yComp[2], 16, 27, 1, 82); 104 104 if (nComp >= 3) and (nHab < 1) then 105 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,105 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32, 106 106 Top + 100 + 7 + yComp[2], 16, 27, 18, 82); 107 107 if (nComp < 4) and (nHab >= 2) then 108 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,108 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16, 109 109 Top + 100 + 46 + yComp[3], 16, 27, 1, 82); 110 110 if (nComp >= 4) and (nHab < 2) then 111 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,111 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32, 112 112 Top + 100 + 46 + yComp[3], 16, 27, 18, 82); 113 113 if (nComp <> 6) and (nComp <> 2) and not((nComp = 0) and (nPow < 1)) then 114 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],114 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp], 115 115 Top + 100 + 7 + yComp[nComp], 16, 27, 18, 82); 116 116 if (nComp <> 6) and (nComp <> 3) and not((nComp = 0) and (nPow < 2)) then 117 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],117 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp], 118 118 Top + 100 + 46 + yComp[nComp], 16, 27, 18, 82); 119 119 if nComp = 2 then 120 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3],120 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3], 121 121 Top + 100 + 7 + yComp[3], 16, 27, 18, 82); 122 122 if nComp = 3 then 123 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[4],123 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[4], 124 124 Top + 100 + 7 + yComp[4], 16, 27, 18, 82); 125 125 end; … … 142 142 procedure TDiaDlg.OffscreenPaint; 143 143 var 144 p, T, max, x, y, y0, Stop, r, RoundRange, LineStep: integer;145 s: string;144 P, T, Max, X, Y, y0, Stop, R, RoundRange, LineStep: Integer; 145 S: string; 146 146 List: ^TChart; 147 147 148 function Round(T: integer): integer;148 function Round(T: Integer): Integer; 149 149 var 150 n, i: integer;150 N, I: Integer; 151 151 begin 152 152 if T < RoundRange then 153 n:= T153 N := T 154 154 else 155 n:= RoundRange;156 result := 0;157 for i := T - nto T do158 inc(result, List[i]);159 result := result div (n+ 1);160 end; 161 162 procedure ShareBar( x, y: integer; Cap: string; val0, val1: integer);163 begin 164 LoweredTextOut( offscreen.canvas, -1, MainTexture, x - 2, y, Cap);165 DLine( offscreen.canvas, x - 2, x + 169, y+ 16, MainTexture.ColorTextShade,155 N := RoundRange; 156 Result := 0; 157 for I := T - N to T do 158 Inc(Result, List[I]); 159 Result := Result div (N + 1); 160 end; 161 162 procedure ShareBar(X, Y: Integer; Cap: string; val0, val1: Integer); 163 begin 164 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, X - 2, Y, Cap); 165 DLine(Offscreen.Canvas, X - 2, X + 169, Y + 16, MainTexture.ColorTextShade, 166 166 MainTexture.ColorTextLight); 167 167 if val0 > 0 then 168 s:= Format(Phrases.Lookup('SHARE'), [val0, val1])168 S := Format(Phrases.Lookup('SHARE'), [val0, val1]) 169 169 else 170 s:= '0';171 RisedTextOut( offscreen.canvas,172 x + 170 - BiColorTextWidth(offscreen.canvas, s), y, s);170 S := '0'; 171 RisedTextOut(Offscreen.Canvas, 172 X + 170 - BiColorTextWidth(Offscreen.Canvas, S), Y, S); 173 173 end; 174 174 … … 176 176 inherited; 177 177 if Kind = dkChart then 178 with offscreen.canvas do178 with Offscreen.Canvas do 179 179 begin 180 180 Font.Assign(UniFont[ftTiny]); … … 186 186 GetMem(List, 4 * (MyRO.Turn + 2)); 187 187 if Mode = stExplore then 188 max := G.lx * G.ly188 Max := G.lx * G.ly 189 189 else 190 190 begin 191 max := -1;192 for p:= 0 to nPl - 1 do193 if (G.Difficulty[ p] > 0) and194 (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then191 Max := -1; 192 for P := 0 to nPl - 1 do 193 if (G.Difficulty[P] > 0) and 194 (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then 195 195 for T := 0 to MyRO.Turn - 1 do 196 196 begin 197 r:= Round(T);198 if r > max then199 max := r;197 R := Round(T); 198 if R > Max then 199 Max := R; 200 200 end; 201 201 end; … … 215 215 for T := 0 to (MyRO.Turn - 1) div LineStep do 216 216 begin 217 x:= Border + (InnerWidth - 2 * Border) * T *217 X := Border + (InnerWidth - 2 * Border) * T * 218 218 LineStep div (MyRO.Turn - 1); 219 MoveTo( x, Border);220 LineTo( x, InnerHeight - Border);221 s:= IntToStr(abs(TurnToYear(T * LineStep)));222 Textout( x - TextWidth(s) div 2, Border - 16, s);219 MoveTo(X, Border); 220 LineTo(X, InnerHeight - Border); 221 S := IntToStr(abs(TurnToYear(T * LineStep))); 222 Textout(X - TextWidth(S) div 2, Border - 16, S); 223 223 end; 224 224 225 225 y0 := 0; 226 if max > 0 then226 if Max > 0 then 227 227 begin 228 for p:= 0 to nPl - 1 do229 if (G.Difficulty[ p] > 0) and230 (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then228 for P := 0 to nPl - 1 do 229 if (G.Difficulty[P] > 0) and 230 (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then 231 231 begin 232 Pen.Color := Tribe[ p].Color;232 Pen.Color := Tribe[P].Color; 233 233 Stop := MyRO.Turn - 1; 234 234 while (Stop > 0) and (List[Stop] = 0) do 235 dec(Stop);235 Dec(Stop); 236 236 for T := 0 to Stop do 237 237 begin 238 r:= Round(T);239 x:= Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1);240 y:= InnerHeight - Border - (InnerHeight - 2 * Border) *241 r div max;238 R := Round(T); 239 X := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1); 240 Y := InnerHeight - Border - (InnerHeight - 2 * Border) * 241 R div Max; 242 242 if T = 0 then 243 MoveTo( x, y)243 MoveTo(X, Y) 244 244 // else if Mode=stTerritory then 245 245 // begin LineTo(x,y0); LineTo(x,y) end 246 246 else if RoundPixels[Mode] = 0 then 247 247 begin 248 if ( y<> y0) or (T = Stop) then249 LineTo( x, y)248 if (Y <> y0) or (T = Stop) then 249 LineTo(X, Y) 250 250 end 251 251 else 252 LineTo( x, y);253 y0 := y;252 LineTo(X, Y); 253 y0 := Y; 254 254 end; 255 255 end; … … 258 258 end 259 259 else 260 with offscreen.canvas do260 with Offscreen.Canvas do 261 261 begin 262 262 Font.Assign(UniFont[ftSmall]); 263 263 FillOffscreen(0, 0, InnerWidth, InnerHeight); 264 264 265 PaintColonyShip( offscreen.canvas, Player, 8, InnerWidth - 16, yArea);265 PaintColonyShip(Offscreen.Canvas, Player, 8, InnerWidth - 16, yArea); 266 266 267 267 ShareBar(InnerWidth div 2 - 85, InnerHeight - 62, … … 277 277 procedure TDiaDlg.FormPaint(Sender: TObject); 278 278 var 279 s: string;279 S: string; 280 280 begin 281 281 inherited; 282 canvas.Font.Assign(UniFont[ftNormal]);282 Canvas.Font.Assign(UniFont[ftNormal]); 283 283 if Kind = dkChart then 284 s:= Phrases.Lookup('DIAGRAM', Mode)285 else 286 s:= Tribe[Player].TPhrase('SHORTNAME');287 LoweredTextOut( canvas, -1, MainTexture,288 (ClientWidth - BiColorTextWidth( canvas, s)) div 2, 31, s);284 S := Phrases.Lookup('DIAGRAM', Mode) 285 else 286 S := Tribe[Player].TPhrase('SHORTNAME'); 287 LoweredTextOut(Canvas, -1, MainTexture, 288 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S); 289 289 end; 290 290 … … 309 309 end; 310 310 311 procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; p: integer);311 procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; P: Integer); 312 312 begin 313 313 Kind := dkShip; 314 if p< 0 then315 begin 316 Player := me;314 if P < 0 then 315 begin 316 Player := Me; 317 317 while MyRO.Ship[Player].Parts[spComp] + MyRO.Ship[Player].Parts[spPow] + 318 318 MyRO.Ship[Player].Parts[spHab] = 0 do … … 320 320 end 321 321 else 322 Player := p;322 Player := P; 323 323 ToggleBtn.ButtonIndex := 28; 324 324 ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT'); … … 329 329 procedure TDiaDlg.ToggleBtnClick(Sender: TObject); 330 330 var 331 p1: integer;332 m: TMenuItem;331 p1: Integer; 332 M: TMenuItem; 333 333 begin 334 334 if Kind = dkChart then … … 345 345 MyRO.Ship[p1].Parts[spHab] > 0 then 346 346 begin 347 m:= TMenuItem.Create(Popup);348 m.RadioItem := true;349 m.Caption := Tribe[p1].TPhrase('SHORTNAME');350 m.Tag := p1;351 m.OnClick := PlayerClick;347 M := TMenuItem.Create(Popup); 348 M.RadioItem := True; 349 M.Caption := Tribe[p1].TPhrase('SHORTNAME'); 350 M.Tag := p1; 351 M.OnClick := PlayerClick; 352 352 if p1 = Player then 353 m.Checked := true;354 Popup.Items.Add( m);353 M.Checked := True; 354 Popup.Items.Add(M); 355 355 end; 356 356 Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height); … … 363 363 end; 364 364 365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: word;365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: Word; 366 366 Shift: TShiftState); 367 367 begin -
trunk/LocalPlayer/Diplomacy.pas
r38 r447 7 7 8 8 function DipCommandToString(pSender, pTarget, Treaty, OppCommand, 9 Command: integer; const OppOffer, Offer: TOffer): string;9 Command: Integer; const OppOffer, Offer: TOffer): string; 10 10 11 11 implementation … … 16 16 function DipCommandToString; 17 17 18 function PriceToString( p, Price: integer): string;18 function PriceToString(P, Price: Integer): string; 19 19 begin 20 20 case Price and opMask of 21 21 opChoose: 22 result := Phrases.Lookup('PRICE_CHOOSE');22 Result := Phrases.Lookup('PRICE_CHOOSE'); 23 23 opCivilReport: 24 result := Tribe[p].TPhrase('PRICE_CIVIL');24 Result := Tribe[P].TPhrase('PRICE_CIVIL'); 25 25 opMilReport: 26 result := Tribe[p].TPhrase('PRICE_MIL');26 Result := Tribe[P].TPhrase('PRICE_MIL'); 27 27 opMap: 28 result := Tribe[p].TPhrase('PRICE_MAP');28 Result := Tribe[P].TPhrase('PRICE_MAP'); 29 29 opTreaty: 30 30 { if Price-opTreaty<Treaty then 31 31 case Treaty of 32 trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');33 trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');34 trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');35 end 36 else } result := Phrases.Lookup('TREATY', Price - opTreaty);32 trPeace: Result:=Phrases.Lookup('FRENDTREATY_PEACE'); 33 trFriendlyContact: Result:=Phrases.Lookup('FRENDTREATY_FRIENDLY'); 34 trAlliance: Result:=Phrases.Lookup('FRENDTREATY_ALLIANCE'); 35 end 36 else } Result := Phrases.Lookup('TREATY', Price - opTreaty); 37 37 opShipParts: 38 38 case Price shr 16 and $F of 39 39 0: 40 result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),40 Result := Format(Phrases.Lookup('PRICE_SHIPCOMP'), 41 41 [Price and $FFFF]); 42 42 1: 43 result := Format(Phrases.Lookup('PRICE_SHIPPOW'),43 Result := Format(Phrases.Lookup('PRICE_SHIPPOW'), 44 44 [Price and $FFFF]); 45 45 2: 46 result := Format(Phrases.Lookup('PRICE_SHIPHAB'),46 Result := Format(Phrases.Lookup('PRICE_SHIPHAB'), 47 47 [Price and $FFFF]); 48 48 end; 49 49 opMoney: 50 result := Format('%d%%c', [Price - opMoney]);50 Result := Format('%d%%c', [Price - opMoney]); 51 51 opTribute: 52 result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);52 Result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]); 53 53 opTech: 54 result := Phrases.Lookup('ADVANCES', Price - opTech);54 Result := Phrases.Lookup('ADVANCES', Price - opTech); 55 55 opAllTech: 56 result := Tribe[p].TPhrase('PRICE_ALLTECH');56 Result := Tribe[P].TPhrase('PRICE_ALLTECH'); 57 57 opModel: 58 result := Tribe[p].ModelName[Price - opModel];58 Result := Tribe[P].ModelName[Price - opModel]; 59 59 opAllModel: 60 result := Tribe[p].TPhrase('PRICE_ALLMODEL');60 Result := Tribe[P].TPhrase('PRICE_ALLMODEL'); 61 61 { opCity: 62 result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]); }62 Result:=Format(TPhrase('PRICE_CITY',P),[CityName(Price-opCity)]); } 63 63 end 64 64 end; 65 65 66 66 var 67 i: integer;67 I: Integer; 68 68 sAdd, sDeliver, sCost: string; 69 DoIntro: boolean;69 DoIntro: Boolean; 70 70 begin 71 71 DoIntro := OppCommand = scDipStart; … … 75 75 case Treaty of 76 76 trPeace: 77 result := Phrases.Lookup('FRCANCELTREATY_PEACE');77 Result := Phrases.Lookup('FRCANCELTREATY_PEACE'); 78 78 trFriendlyContact: 79 result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');79 Result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY'); 80 80 trAlliance: 81 result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');82 end; 83 DoIntro := false;81 Result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE'); 82 end; 83 DoIntro := False; 84 84 end; 85 85 scDipNotice: 86 result := Phrases.Lookup('FRNOTICE');86 Result := Phrases.Lookup('FRNOTICE'); 87 87 scDipAccept: 88 88 begin 89 89 if (OppOffer.nDeliver + OppOffer.nCost = 1) and 90 90 (OppOffer.Price[0] and opMask = opTreaty) and 91 ( integer(OppOffer.Price[0] - opTreaty) > Treaty) then91 (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then 92 92 // simple treaty offer 93 93 { if OppOffer.Price[0]-opTreaty=trCeaseFire then 94 result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')95 else } result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')94 Result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE') 95 else } Result := Tribe[pTarget].TPhrase('FRACCEPTTREATY') 96 96 else if OppOffer.nDeliver = 0 then 97 result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')97 Result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG') 98 98 else if OppOffer.nCost = 0 then 99 result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')99 Result := Tribe[pSender].TPhrase('FRACCEPTPRESENT') 100 100 else 101 result := Tribe[pSender].TPhrase('FRACCEPTOFFER');101 Result := Tribe[pSender].TPhrase('FRACCEPTOFFER'); 102 102 end; 103 103 scDipBreak: 104 104 begin 105 result := Tribe[pTarget].TPhrase('FRBREAK');106 DoIntro := false;105 Result := Tribe[pTarget].TPhrase('FRBREAK'); 106 DoIntro := False; 107 107 end; 108 108 scDipOffer: 109 109 begin 110 result := '';110 Result := ''; 111 111 if (OppCommand = scDipOffer) and 112 112 ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) and … … 115 115 if (OppOffer.nDeliver + OppOffer.nCost = 1) and 116 116 (OppOffer.Price[0] and opMask = opTreaty) and 117 ( integer(OppOffer.Price[0] - opTreaty) > Treaty) then117 (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then 118 118 // simple treaty offer 119 result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'119 Result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\' 120 120 else if OppOffer.nDeliver = 0 then 121 result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'121 Result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\' 122 122 else if OppOffer.nCost = 0 then 123 result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';123 Result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\'; 124 124 end; 125 125 126 126 sDeliver := ''; 127 for i:= 0 to Offer.nDeliver - 1 do128 begin 129 sAdd := PriceToString(pSender, Offer.Price[ i]);130 if i= 0 then127 for I := 0 to Offer.nDeliver - 1 do 128 begin 129 sAdd := PriceToString(pSender, Offer.Price[I]); 130 if I = 0 then 131 131 sDeliver := sAdd 132 132 else … … 134 134 end; 135 135 sCost := ''; 136 for i:= 0 to Offer.nCost - 1 do137 begin 138 sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + i]);139 if i= 0 then136 for I := 0 to Offer.nCost - 1 do 137 begin 138 sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + I]); 139 if I = 0 then 140 140 sCost := sAdd 141 141 else … … 147 147 if (OppCommand = scDipOffer) and 148 148 ((OppOffer.nDeliver = 0) and (OppOffer.nCost = 0)) then 149 result := Tribe[pTarget].TPhrase('FRBYE')149 Result := Tribe[pTarget].TPhrase('FRBYE') 150 150 else 151 151 begin 152 if ( result = '') and (OppCommand = scDipOffer) and152 if (Result = '') and (OppCommand = scDipOffer) and 153 153 ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) then 154 154 begin 155 155 if (OppOffer.nDeliver = 1) and (OppOffer.Price[0] = opChoose) and 156 156 not Phrases2FallenBackToEnglish then 157 result := Tribe[pSender].TString157 Result := Tribe[pSender].TString 158 158 (Phrases2.Lookup('FRNOTACCEPTANYOFFER')) + ' ' 159 159 else if (OppOffer.nCost = 1) and 160 160 (OppOffer.Price[OppOffer.nDeliver] = opChoose) and not Phrases2FallenBackToEnglish 161 161 then 162 result := Tribe[pSender].TString162 Result := Tribe[pSender].TString 163 163 (Phrases2.Lookup('FRNOTACCEPTANYWANT')) + ' ' 164 164 else 165 result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';165 Result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' '; 166 166 end; 167 result := result + Phrases.Lookup('FRDONE');168 DoIntro := false167 Result := Result + Phrases.Lookup('FRDONE'); 168 DoIntro := False 169 169 end 170 170 end 171 171 else if (Offer.nDeliver + Offer.nCost = 1) and 172 172 (Offer.Price[0] and opMask = opTreaty) and 173 ( integer(Offer.Price[0] - opTreaty) > Treaty) then173 (Integer(Offer.Price[0] - opTreaty) > Treaty) then 174 174 // simple treaty offer 175 175 begin … … 177 177 // trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE'); 178 178 trPeace: 179 result := result + Tribe[pTarget].TPhrase('FRPEACE');179 Result := Result + Tribe[pTarget].TPhrase('FRPEACE'); 180 180 trFriendlyContact: 181 result := result + Tribe[pTarget].TPhrase('FRFRIENDLY');181 Result := Result + Tribe[pTarget].TPhrase('FRFRIENDLY'); 182 182 trAlliance: 183 result := result + Tribe[pTarget].TPhrase('FRALLIANCE');183 Result := Result + Tribe[pTarget].TPhrase('FRALLIANCE'); 184 184 end 185 185 end … … 188 188 if (Treaty >= trFriendlyContact) and not Phrases2FallenBackToEnglish 189 189 then 190 result := result +190 Result := Result + 191 191 Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT') 192 192 ), [sCost]) 193 193 else 194 194 begin 195 result := result +195 Result := Result + 196 196 Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'), [sCost]); 197 DoIntro := false197 DoIntro := False 198 198 end 199 199 end 200 200 else if Offer.nCost = 0 then // present 201 result := result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),201 Result := Result + Format(Tribe[pTarget].TPhrase('FRPRESENT'), 202 202 [sDeliver]) 203 203 else if (Offer.nDeliver = 1) and (Offer.Price[0] = opChoose) then 204 result := result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])204 Result := Result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost]) 205 205 else if (Offer.nCost = 1) and (Offer.Price[Offer.nDeliver] = opChoose) 206 206 then 207 result := result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])207 Result := Result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver]) 208 208 else 209 result := result + Format(Phrases.Lookup('FROFFER'),209 Result := Result + Format(Phrases.Lookup('FROFFER'), 210 210 [sDeliver, sCost]); 211 211 end; … … 213 213 if DoIntro then 214 214 if Treaty < trPeace then 215 result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + result215 Result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + Result 216 216 else 217 result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + result217 Result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + Result 218 218 end; 219 219 -
trunk/LocalPlayer/Draft.pas
r442 r447 20 20 procedure CloseBtnClick(Sender: TObject); 21 21 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 22 Shift: TShiftState; x, y: integer);22 Shift: TShiftState; X, Y: Integer); 23 23 procedure OKBtnClick(Sender: TObject); 24 24 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 25 Shift: TShiftState; x, y: integer);25 Shift: TShiftState; X, Y: Integer); 26 26 public 27 27 procedure ShowNewContent(NewMode: TWindowMode); … … 30 30 private 31 31 Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView, 32 IncCap, DecCap: integer;33 code: array [0 .. nFeature - 1] of integer;32 IncCap, DecCap: Integer; 33 Code: array [0 .. nFeature - 1] of Integer; 34 34 Template, Back: TBitmap; 35 function IsFeatureInList( d, i: integer): boolean;36 procedure SetDomain( d: integer);35 function IsFeatureInList(D, I: Integer): Boolean; 36 procedure SetDomain(D: Integer); 37 37 end; 38 38 … … 108 108 procedure TDraftDlg.OffscreenPaint; 109 109 110 function DomainAvailable( d: integer): boolean;111 begin 112 result := (upgrade[d, 0].Preq = preNone) or113 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable);110 function DomainAvailable(D: Integer): Boolean; 111 begin 112 Result := (upgrade[D, 0].Preq = preNone) or 113 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable); 114 114 end; 115 115 116 116 procedure PaintTotalBars; 117 117 var 118 i, y, dx, num, w: integer;119 s: string;120 begin 121 with offscreen.Canvas do118 I, Y, dx, num, W: Integer; 119 S: string; 120 begin 121 with Offscreen.Canvas do 122 122 begin 123 123 // strength bar 124 y:= yTotal;125 DarkGradient( offscreen.Canvas, xTotal - 6, y+ 1, 184, 2);126 DarkGradient( offscreen.Canvas, xTotal2 + 172, y+ 1, 95, 2);127 RisedTextOut( offscreen.Canvas, xTotal - 2, y,124 Y := yTotal; 125 DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2); 126 DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2); 127 RisedTextOut(Offscreen.Canvas, xTotal - 2, Y, 128 128 Phrases.Lookup('UNITSTRENGTH')); 129 RisedTextOut( offscreen.Canvas, xTotal + 112 + 30, y,129 RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y, 130 130 'x' + IntToStr(MyRO.DevModel.MStrength)); 131 RisedTextOut( offscreen.Canvas, xTotal2 + 148 + 30, y, '=');132 s:= IntToStr(MyRO.DevModel.Attack) + '/' +131 RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '='); 132 S := IntToStr(MyRO.DevModel.Attack) + '/' + 133 133 IntToStr(MyRO.DevModel.Defense); 134 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 -135 BiColorTextWidth( offscreen.Canvas, s), y, s);134 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 135 BiColorTextWidth(Offscreen.Canvas, S), Y, S); 136 136 137 137 // transport bar 138 138 if MyRO.DevModel.MTrans > 0 then 139 139 begin 140 y:= yTotal + 19;141 DarkGradient( offscreen.Canvas, xTotal - 6, y+ 1, 184, 1);142 DarkGradient( offscreen.Canvas, xTotal2 + 172, y+ 1, 95, 1);143 RisedTextOut( offscreen.Canvas, xTotal - 2, y,140 Y := yTotal + 19; 141 DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1); 142 DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1); 143 RisedTextOut(Offscreen.Canvas, xTotal - 2, Y, 144 144 Phrases.Lookup('UNITTRANSPORT')); 145 RisedTextOut( offscreen.Canvas, xTotal + 112 + 30, y,145 RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y, 146 146 'x' + IntToStr(MyRO.DevModel.MTrans)); 147 RisedTextOut( offscreen.Canvas, xTotal2 + 148 + 30, y, '=');147 RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '='); 148 148 149 149 Font.Color := $000000; 150 150 dx := -237 - 30; 151 for i:= mcFirstNonCap - 1 downto 3 do152 if iin [mcSeaTrans, mcCarrier, mcAirTrans] then151 for I := mcFirstNonCap - 1 downto 3 do 152 if I in [mcSeaTrans, mcCarrier, mcAirTrans] then 153 153 begin 154 num := MyRO.DevModel.Cap[ i] * MyRO.DevModel.MTrans;154 num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans; 155 155 if num > 0 then 156 156 begin 157 inc(dx, 15);157 Inc(dx, 15); 158 158 Brush.Color := $C0C0C0; 159 FrameRect(Rect(xTotal2 - 3 - dx, y+ 2,160 xTotal2 + 11 - dx, y+ 16));159 FrameRect(Rect(xTotal2 - 3 - dx, Y + 2, 160 xTotal2 + 11 - dx, Y + 16)); 161 161 Brush.Style := bsClear; 162 Sprite( offscreen, HGrSystem, xTotal2 - 1 - dx, y+ 4, 10, 10,163 66 + i mod 11 * 11, 137 + idiv 11 * 11);162 Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10, 163 66 + I mod 11 * 11, 137 + I div 11 * 11); 164 164 if num > 1 then 165 165 begin 166 s:= IntToStr(num);167 w := TextWidth(s);168 inc(dx, w+ 1);166 S := IntToStr(num); 167 W := TextWidth(S); 168 Inc(dx, W + 1); 169 169 Brush.Color := $FFFFFF; 170 FillRect(Rect(xTotal2 - 3 - dx, y+ 2,171 xTotal2 + w - 1 - dx, y+ 16));170 FillRect(Rect(xTotal2 - 3 - dx, Y + 2, 171 xTotal2 + W - 1 - dx, Y + 16)); 172 172 Brush.Style := bsClear; 173 Textout(xTotal2 - 3 - dx + 1, y, s);173 Textout(xTotal2 - 3 - dx + 1, Y, S); 174 174 end; 175 175 end; … … 178 178 179 179 // speed bar 180 y:= yTotal + 38;181 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,180 Y := yTotal + 38; 181 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 182 182 Phrases.Lookup('UNITSPEED')); 183 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,183 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 184 184 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 185 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,185 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 186 186 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 187 s:= MovementToString(MyRO.DevModel.Speed);188 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 -189 TextWidth( s), y, s);187 S := MovementToString(MyRO.DevModel.Speed); 188 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 189 TextWidth(S), Y, S); 190 190 191 191 // cost bar 192 y:= yTotal + 57;193 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,192 Y := yTotal + 57; 193 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 194 194 Phrases.Lookup('UNITCOST')); 195 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,195 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y, 196 196 'x' + IntToStr(MyRO.DevModel.MCost)); 197 LoweredTextOut( offscreen.Canvas, -1, MainTexture,198 xTotal2 + 148 + 30, y, '=');199 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,197 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 198 xTotal2 + 148 + 30, Y, '='); 199 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 200 200 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 201 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,201 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 202 202 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 203 s:= IntToStr(MyRO.DevModel.Cost);204 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -205 TextWidth( s), y, s);206 Sprite( offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y+ 4, 10,203 S := IntToStr(MyRO.DevModel.Cost); 204 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 - 205 TextWidth(S), Y, S); 206 Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10, 207 207 10, 88, 115); 208 208 209 if G.Difficulty[ me] <> 2 then209 if G.Difficulty[Me] <> 2 then 210 210 begin // corrected cost bar 211 y:= yTotal + 76;212 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,213 Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[ me])));214 LoweredTextOut( offscreen.Canvas, -1, MainTexture,215 xTotal2 + 148 + 30, y, '=');216 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,211 Y := yTotal + 76; 212 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 213 Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me]))); 214 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 215 xTotal2 + 148 + 30, Y, '='); 216 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 217 217 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 218 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,218 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 219 219 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 220 s:= IntToStr(MyRO.DevModel.Cost * BuildCostMod221 [G.Difficulty[ me]] div 12);222 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -223 TextWidth( s), y, s);224 Sprite( offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y+ 4, 10,220 S := IntToStr(MyRO.DevModel.Cost * BuildCostMod 221 [G.Difficulty[Me]] div 12); 222 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 - 223 TextWidth(S), Y, S); 224 Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10, 225 225 10, 88, 115); 226 226 end; … … 229 229 230 230 var 231 i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;231 I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer; 232 232 begin 233 233 inherited; … … 253 253 Template.Height - 64 - Cut); 254 254 255 BitBltCanvas( offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,255 BitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight, 256 256 Back.Canvas, 0, 0); 257 257 258 offscreen.Canvas.Font.Assign(UniFont[ftCaption]);259 RisedTextOut( offscreen.Canvas, 10, 7, Caption);260 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);258 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 259 RisedTextOut(Offscreen.Canvas, 10, 7, Caption); 260 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 261 261 262 262 with MyRO.DevModel do 263 263 begin 264 264 DomainCount := 0; 265 for d:= 0 to nDomains - 1 do266 if DomainAvailable( d) then267 inc(DomainCount);265 for D := 0 to nDomains - 1 do 266 if DomainAvailable(D) then 267 Inc(DomainCount); 268 268 if DomainCount > 1 then 269 269 begin 270 for d:= 0 to nDomains - 1 do271 if DomainAvailable( d) then270 for D := 0 to nDomains - 1 do 271 if DomainAvailable(D) then 272 272 begin 273 x := xDomain + d* DomainPitch;274 if d= Domain then275 ImageOp_BCC( offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,273 X := xDomain + D * DomainPitch; 274 if D = Domain then 275 ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36, 276 276 36, 0, $00C0FF) 277 277 else 278 ImageOp_BCC( offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,278 ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36, 279 279 36, 0, $606060); 280 280 end; 281 Frame( offscreen.Canvas, xDomain - 11, yDomain - 3,281 Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3, 282 282 xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF); 283 RFrame( offscreen.Canvas, xDomain - 12, yDomain - 4,283 RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4, 284 284 xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0); 285 285 end; … … 294 294 295 295 // display weight 296 with offscreen.Canvas do297 begin 298 for i:= 0 to MaxWeight - 1 do299 if i< Weight then300 ImageOp_BCC( offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),296 with Offscreen.Canvas do 297 begin 298 for I := 0 to MaxWeight - 1 do 299 if I < Weight then 300 ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight), 301 301 WeightOn.BoundsRect, 0, $949494) 302 302 else 303 ImageOp_BCC( offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),303 ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight), 304 304 WeightOff.BoundsRect, 0, $949494); 305 305 end; 306 306 307 with offscreen.Canvas do308 for i:= 0 to Lines - 1 do307 with Offscreen.Canvas do 308 for I := 0 to Lines - 1 do 309 309 begin 310 if not( code[i] in AutoFeature) then310 if not(Code[I] in AutoFeature) then 311 311 begin 312 312 // paint +/- butttons 313 if code[i] < mcFirstNonCap then313 if Code[I] < mcFirstNonCap then 314 314 begin 315 Dump( offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *316 i, 12, 12, 169, 172);317 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *318 i, 12, 12, 169, 159);319 RFrame( offscreen.Canvas, xFeature - (21 + 1),320 yFeature + 2 + LinePitch * i- 1, xFeature - (21 - 24),321 yFeature + 2 + LinePitch * i+ 12, MainTexture.ColorBevelShade,315 Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch * 316 I, 12, 12, 169, 172); 317 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 318 I, 12, 12, 169, 159); 319 RFrame(Offscreen.Canvas, xFeature - (21 + 1), 320 yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24), 321 yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade, 322 322 MainTexture.ColorBevelLight); 323 323 end 324 324 else 325 325 begin 326 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *327 i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);328 RFrame( offscreen.Canvas, xFeature - (9 + 1),329 yFeature + 2 + LinePitch * i- 1, xFeature - (21 - 24),330 yFeature + 2 + LinePitch * i+ 12, MainTexture.ColorBevelShade,326 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 327 I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]); 328 RFrame(Offscreen.Canvas, xFeature - (9 + 1), 329 yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24), 330 yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade, 331 331 MainTexture.ColorBevelLight); 332 332 end; 333 333 334 334 // paint cost 335 LightGradient( offscreen.Canvas, xFeature + 34,336 yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels335 LightGradient(Offscreen.Canvas, xFeature + 34, 336 yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels 337 337 [187, 137]); 338 if (Domain = dGround) and ( code[i] = mcDefense) then338 if (Domain = dGround) and (Code[I] = mcDefense) then 339 339 CapWeight := 2 340 340 else 341 CapWeight := Feature[ code[i]].Weight;342 n := CapWeight + Feature[code[i]].Cost;343 d:= 6;344 while ( n - 1) * d* 2 > 48 - 10 do345 dec(d);346 for j := 0 to n- 1 do347 if j< CapWeight then348 Sprite( offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,349 yFeature + 2 + LinePitch * i+ 1, 10, 10, 88, 126)341 CapWeight := Feature[Code[I]].Weight; 342 N := CapWeight + Feature[Code[I]].Cost; 343 D := 6; 344 while (N - 1) * D * 2 > 48 - 10 do 345 Dec(D); 346 for J := 0 to N - 1 do 347 if J < CapWeight then 348 Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D, 349 yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126) 350 350 else 351 Sprite( offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,352 yFeature + 2 + LinePitch * i+ 1, 10, 10, 88, 115);351 Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D, 352 yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115); 353 353 end; // if not (code[i] in AutoFeature) 354 DarkGradient( offscreen.Canvas, xFeature + 17,355 yFeature + LinePitch * i, 16, 1);356 ScreenTools.Frame( offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,357 xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,354 DarkGradient(Offscreen.Canvas, xFeature + 17, 355 yFeature + LinePitch * I, 16, 1); 356 ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I, 357 xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I, 358 358 $C0C0C0, $C0C0C0); 359 Sprite( offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch360 * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);361 362 if MyRO.DevModel.Cap[ code[i]] > 0 then359 Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch 360 * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11); 361 362 if MyRO.DevModel.Cap[Code[I]] > 0 then 363 363 TextColor := MainTexture.ColorLitText 364 364 else 365 365 TextColor := -1; 366 366 367 if code[i] < mcFirstNonCap then368 LoweredTextOut( offscreen.Canvas, TextColor, MainTexture, xFeature + 7,369 yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));370 LoweredTextOut( offscreen.Canvas, TextColor, MainTexture, xFeature + 88,371 yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));367 if Code[I] < mcFirstNonCap then 368 LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7, 369 yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]])); 370 LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88, 371 yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I])); 372 372 end; 373 373 end; 374 374 375 375 // free features 376 j:= 0;377 for i:= 0 to nFeature - 1 do378 if ( i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and379 (Feature[ i].Preq <> preNA) and380 ((Feature[ i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)381 or (Feature[ i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)382 ) and not((Feature[ i].Preq = adSteamEngine) and376 J := 0; 377 for I := 0 to nFeature - 1 do 378 if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and 379 (Feature[I].Preq <> preNA) and 380 ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me) 381 or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable) 382 ) and not((Feature[I].Preq = adSteamEngine) and 383 383 (MyRO.Tech[adNuclearPower] >= tsApplicable)) then 384 384 begin 385 DarkGradient( offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch386 * j, 16, 1);387 Frame( offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,388 xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);389 Sprite( offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,390 10, 10, 66 + i mod 11 * 11, 137 + idiv 11 * 11);391 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xWeight + 26,392 yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));393 inc(j);394 end; 395 396 with Tribe[ me].ModelPicture[MyRO.nModel] do397 begin 398 FrameImage( offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,385 DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch 386 * J, 16, 1); 387 Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J, 388 xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0); 389 Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J, 390 10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11); 391 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26, 392 yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I)); 393 Inc(J); 394 end; 395 396 with Tribe[Me].ModelPicture[MyRO.nModel] do 397 begin 398 FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig, 399 399 ySizeBig, 0, 0); 400 Sprite( offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,400 Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1, 401 401 pix div 10 * 49 + 1); 402 402 end; … … 404 404 end; 405 405 406 procedure TDraftDlg.SetDomain( d: integer);407 408 function Prio(fix: integer): integer;406 procedure TDraftDlg.SetDomain(D: Integer); 407 408 function Prio(fix: Integer): Integer; 409 409 var 410 FeaturePreq: integer;410 FeaturePreq: Integer; 411 411 begin 412 412 FeaturePreq := Feature[fix].Preq; 413 assert(FeaturePreq <> preNA);413 Assert(FeaturePreq <> preNA); 414 414 if fix < mcFirstNonCap then 415 result := 10000 + fix415 Result := 10000 + fix 416 416 else if FeaturePreq = preNone then 417 result := 20000417 Result := 20000 418 418 else if FeaturePreq < 0 then 419 result := 40000419 Result := 40000 420 420 else 421 result := 30000 + AdvValue[FeaturePreq];421 Result := 30000 + AdvValue[FeaturePreq]; 422 422 if not(fix in AutoFeature) then 423 inc(result, 90000);423 Inc(Result, 90000); 424 424 end; 425 425 426 426 var 427 i, j, x: integer;428 begin 429 Domain := d;427 I, J, X: Integer; 428 begin 429 Domain := D; 430 430 Lines := 0; 431 for i:= 0 to nFeature - 1 do432 if IsFeatureInList(Domain, i) then433 begin 434 code[Lines] := i;435 inc(Lines);431 for I := 0 to nFeature - 1 do 432 if IsFeatureInList(Domain, I) then 433 begin 434 Code[Lines] := I; 435 Inc(Lines); 436 436 end; 437 437 yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2; 438 438 439 439 // sort features 440 for i:= 0 to Lines - 2 do441 for j := i+ 1 to Lines - 1 do442 if Prio( code[i]) > Prio(code[j]) then440 for I := 0 to Lines - 2 do 441 for J := I + 1 to Lines - 1 do 442 if Prio(Code[I]) > Prio(Code[J]) then 443 443 begin // exchange 444 x := code[i];445 code[i] := code[j];446 code[j] := x;444 X := Code[I]; 445 Code[I] := Code[J]; 446 Code[J] := X; 447 447 end; 448 448 end; 449 449 450 function TDraftDlg.IsFeatureInList( d, i: integer): boolean;451 begin 452 result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and453 (Feature[ i].Preq <> preNA) and454 ((Feature[ i].Preq = preNone) or (Feature[i].Preq = preSun) and455 (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and456 (MyRO.Tech[Feature[ i].Preq] >= tsApplicable));450 function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean; 451 begin 452 Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and 453 (Feature[I].Preq <> preNA) and 454 ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and 455 (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and 456 (MyRO.Tech[Feature[I].Preq] >= tsApplicable)); 457 457 end; 458 458 459 459 procedure TDraftDlg.FormShow(Sender: TObject); 460 460 var 461 count, d, i: integer;461 count, D, I: Integer; 462 462 begin 463 463 Domain := dGround; 464 464 while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and 465 465 (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do 466 inc(Domain);466 Inc(Domain); 467 467 468 468 // count max number of features in any domain 469 469 MaxLines := 0; 470 for d:= 0 to nDomains - 1 do471 if (upgrade[ d, 0].Preq = preNone) or472 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable) then470 for D := 0 to nDomains - 1 do 471 if (upgrade[D, 0].Preq = preNone) or 472 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then 473 473 begin 474 474 count := 0; 475 for i:= 0 to nFeature - 1 do476 if IsFeatureInList( d, i) then477 inc(count);475 for I := 0 to nFeature - 1 do 476 if IsFeatureInList(D, I) then 477 Inc(count); 478 478 if count > MaxLines then 479 479 MaxLines := count; … … 493 493 494 494 SetDomain(Domain); 495 Server(sCreateDevModel, me, Domain, nil^);495 Server(sCreateDevModel, Me, Domain, nil^); 496 496 MyModel[MyRO.nModel] := MyRO.DevModel; 497 InitMyModel(MyRO.nModel, false);497 InitMyModel(MyRO.nModel, False); 498 498 OffscreenPaint; 499 499 IncCap := -1; … … 507 507 508 508 procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 509 Shift: TShiftState; x, y: integer);509 Shift: TShiftState; X, Y: Integer); 510 510 var 511 i, d: integer;511 I, D: Integer; 512 512 begin 513 513 if Button = mbLeft then 514 514 begin 515 for d:= 0 to nDomains - 1 do516 if ( d <> Domain) and ((upgrade[d, 0].Preq = preNone) or517 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable)) and518 ( x >= xDomain + d* DomainPitch) and519 ( x < xDomain + d * DomainPitch + 36) and (y>= yDomain) and520 ( y< yDomain + 36) then515 for D := 0 to nDomains - 1 do 516 if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or 517 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and 518 (X >= xDomain + D * DomainPitch) and 519 (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and 520 (Y < yDomain + 36) then 521 521 begin 522 SetDomain( d);523 Server(sCreateDevModel, me, Domain, nil^);522 SetDomain(D); 523 Server(sCreateDevModel, Me, Domain, nil^); 524 524 MyModel[MyRO.nModel] := MyRO.DevModel; 525 InitMyModel(MyRO.nModel, false);525 InitMyModel(MyRO.nModel, False); 526 526 SmartUpdateContent; 527 527 end; 528 528 529 if ( y >= yFeature) and (y< yFeature + LinePitch * Lines) then530 begin 531 i := (y- yFeature) div LinePitch;532 if ( x >= xFeature - 21) and (x< ClientWidth) and (ssShift in Shift) then533 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, code[i])534 else if not( code[i] in AutoFeature) then529 if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then 530 begin 531 I := (Y - yFeature) div LinePitch; 532 if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then 533 HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I]) 534 else if not(Code[I] in AutoFeature) then 535 535 begin 536 if ( code[i] < mcFirstNonCap) and (x>= xFeature - 21) and537 ( x< xFeature - 21 + 12) then536 if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and 537 (X < xFeature - 21 + 12) then 538 538 begin 539 IncCap := code[i];540 Dump( offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *541 i, 12, 12, 182, 172);539 IncCap := Code[I]; 540 Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch * 541 I, 12, 12, 182, 172); 542 542 SmartInvalidate; 543 543 end 544 else if ( x >= xFeature - 9) and (x< xFeature - 9 + 12) then544 else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then 545 545 begin 546 DecCap := code[i];547 if code[i] < mcFirstNonCap then548 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *549 i, 12, 12, 182, 159)546 DecCap := Code[I]; 547 if Code[I] < mcFirstNonCap then 548 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 549 I, 12, 12, 182, 159) 550 550 else 551 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *552 i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);551 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 552 I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]); 553 553 SmartInvalidate; 554 554 end; … … 559 559 560 560 procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 561 Shift: TShiftState; x, y: integer);561 Shift: TShiftState; X, Y: Integer); 562 562 var 563 NewValue: integer;563 NewValue: Integer; 564 564 begin 565 565 if IncCap >= 0 then 566 566 begin 567 567 NewValue := MyRO.DevModel.Cap[IncCap] + 1; 568 Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);568 Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^); 569 569 MyModel[MyRO.nModel] := MyRO.DevModel; 570 InitMyModel(MyRO.nModel, false);570 InitMyModel(MyRO.nModel, False); 571 571 SmartUpdateContent; 572 572 IncCap := -1; … … 579 579 if DecCap >= mcFirstNonCap then 580 580 NewValue := -NewValue; 581 Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);581 Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^); 582 582 MyModel[MyRO.nModel] := MyRO.DevModel; 583 InitMyModel(MyRO.nModel, false);583 InitMyModel(MyRO.nModel, False); 584 584 end; 585 585 SmartUpdateContent; -
trunk/LocalPlayer/Enhance.pas
r442 r447 37 37 NoMap: TIsoMap; 38 38 public 39 procedure ShowNewContent(NewMode: TWindowMode; TerrType: integer = -1);39 procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1); 40 40 protected 41 Page: integer;41 Page: Integer; 42 42 procedure OffscreenPaint; override; 43 43 end; … … 56 56 procedure TEnhanceDlg.FormCreate(Sender: TObject); 57 57 var 58 TerrType: integer;59 m: TMenuItem;58 TerrType: Integer; 59 M: TMenuItem; 60 60 begin 61 61 inherited; … … 71 71 if TerrType <> fJungle then 72 72 begin 73 m:= TMenuItem.Create(Popup);74 m.RadioItem := true;73 M := TMenuItem.Create(Popup); 74 M.RadioItem := True; 75 75 if TerrType = fGrass then 76 m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),76 M.Caption := Format(Phrases.Lookup('TWOTERRAINS'), 77 77 [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN', 78 78 fGrass + 12)]) 79 79 else if TerrType = fForest then 80 m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),80 M.Caption := Format(Phrases.Lookup('TWOTERRAINS'), 81 81 [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN', 82 82 fJungle)]) 83 83 else 84 m.Caption := Phrases.Lookup('TERRAIN', TerrType);85 m.Tag := TerrType;86 m.OnClick := TerrClick;87 Popup.Items.Add( m);84 M.Caption := Phrases.Lookup('TERRAIN', TerrType); 85 M.Tag := TerrType; 86 M.OnClick := TerrClick; 87 Popup.Items.Add(M); 88 88 end; 89 89 end; … … 96 96 procedure TEnhanceDlg.FormPaint(Sender: TObject); 97 97 var 98 i: integer;98 I: Integer; 99 99 begin 100 100 inherited; … … 103 103 BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width, 104 104 job3.Top + job3.Height), MainTexture); 105 for i:= 0 to ControlCount - 1 do106 if Controls[ i] is TButtonC then107 BitBltCanvas(Canvas, Controls[ i].Left + 2, Controls[i].Top - 11, 8, 8,108 HGrSystem.Data.Canvas, 121 + Controls[ i].Tag mod 7 * 9,109 1 + Controls[ i].Tag div 7 * 9);105 for I := 0 to ControlCount - 1 do 106 if Controls[I] is TButtonC then 107 BitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8, 108 HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9, 109 1 + Controls[I].Tag div 7 * 9); 110 110 end; 111 111 … … 115 115 end; 116 116 117 procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: integer);117 procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer); 118 118 begin 119 119 if (TerrType < fGrass) or (TerrType > fMountains) then … … 126 126 procedure TEnhanceDlg.OffscreenPaint; 127 127 var 128 i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;129 s: string;128 I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer; 129 S: string; 130 130 Done: Set of jNone .. jTrans; 131 TypeChanged: boolean;131 TypeChanged: Boolean; 132 132 begin 133 133 OffscreenUser := self; 134 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);134 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 135 135 FillOffscreen(0, 0, InnerWidth, InnerHeight); 136 136 137 137 EndStage := 0; 138 138 while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do 139 inc(EndStage);139 Inc(EndStage); 140 140 with NoMap do 141 x:= InnerWidth div 2 - xxt - (xxt + 3) * EndStage;141 X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage; 142 142 143 143 TerrType := Page; … … 149 149 if stage > 0 then 150 150 begin 151 Sprite( offscreen, HGrSystem, x- 10, 66, 14, 14, 80, 1);151 Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1); 152 152 case MyData.EnhancementJobs[Page, stage - 1] of 153 153 jRoad: 154 154 begin 155 inc(Cost, Terrain[TerrType].MoveCost * RoadWork);155 Inc(Cost, Terrain[TerrType].MoveCost * RoadWork); 156 156 TileImp := TileImp or fRoad; 157 157 end; 158 158 jRR: 159 159 begin 160 inc(Cost, Terrain[TerrType].MoveCost * RRWork);160 Inc(Cost, Terrain[TerrType].MoveCost * RRWork); 161 161 TileImp := TileImp or fRR; 162 162 end; 163 163 jIrr: 164 164 begin 165 inc(Cost, Terrain[TerrType].IrrClearWork);165 Inc(Cost, Terrain[TerrType].IrrClearWork); 166 166 TileImp := TileImp and not fTerImp or tiIrrigation; 167 167 end; 168 168 jFarm: 169 169 begin 170 inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);170 Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork); 171 171 TileImp := TileImp and not fTerImp or tiFarm; 172 172 end; 173 173 jMine: 174 174 begin 175 inc(Cost, Terrain[TerrType].MineAfforestWork);175 Inc(Cost, Terrain[TerrType].MineAfforestWork); 176 176 TileImp := TileImp and not fTerImp or tiMine; 177 177 end; 178 178 jClear: 179 179 begin 180 inc(Cost, Terrain[TerrType].IrrClearWork);180 Inc(Cost, Terrain[TerrType].IrrClearWork); 181 181 TerrType := Terrain[TerrType].ClearTerrain; 182 182 end; 183 183 jAfforest: 184 184 begin 185 inc(Cost, Terrain[TerrType].MineAfforestWork);185 Inc(Cost, Terrain[TerrType].MineAfforestWork); 186 186 TerrType := Terrain[TerrType].AfforestTerrain; 187 187 end; 188 188 jTrans: 189 189 begin 190 inc(Cost, Terrain[TerrType].TransWork);190 Inc(Cost, Terrain[TerrType].TransWork); 191 191 TerrType := Terrain[TerrType].TransTerrain; 192 192 end; 193 193 end; 194 include(Done, MyData.EnhancementJobs[Page, stage - 1]);194 Include(Done, MyData.EnhancementJobs[Page, stage - 1]); 195 195 end; 196 196 197 197 with NoMap do begin 198 198 if TerrType < fForest then 199 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,199 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 200 200 1 + TerrType * (xxt * 2 + 1), 1 + yyt) 201 201 else 202 202 begin 203 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,203 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 204 204 1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1)); 205 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,205 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 206 206 1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) * 207 207 (yyt * 3 + 1)); 208 208 end; 209 209 if TileImp and fTerImp = tiFarm then 210 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,210 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 211 211 1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1)) 212 212 else if TileImp and fTerImp = tiIrrigation then 213 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,213 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1, 214 214 1 + yyt + 12 * (yyt * 3 + 1)); 215 215 if TileImp and fRR <> 0 then 216 216 begin 217 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,217 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 218 218 1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1)); 219 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,219 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 220 220 1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1)); 221 221 end 222 222 else if TileImp and fRoad <> 0 then 223 223 begin 224 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,224 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 225 225 1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1)); 226 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,226 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 227 227 1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1)); 228 228 end; 229 229 if TileImp and fTerImp = tiMine then 230 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,230 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 231 231 1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1)); 232 inc(x, xxt * 2 + 6);233 end; 234 end; 235 236 for i:= 0 to Popup.Items.Count - 1 do237 if Popup.Items[ i].Tag = Page then238 s := Popup.Items[i].Caption;232 Inc(X, xxt * 2 + 6); 233 end; 234 end; 235 236 for I := 0 to Popup.Items.Count - 1 do 237 if Popup.Items[I].Tag = Page then 238 S := Popup.Items[I].Caption; 239 239 if Cost > 0 then 240 s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);241 LoweredTextOut( offscreen.Canvas, -1, MainTexture,242 (InnerWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2, 12, s);240 S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]); 241 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 242 (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S); 243 243 244 244 if EndStage > 0 then … … 289 289 (Terrain[TerrType].MineEff > 0); 290 290 job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and 291 ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or291 ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or 292 292 (LastJob = jClear); 293 293 job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0) … … 306 306 procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject); 307 307 var 308 i: integer;309 begin 310 for i:= 0 to Popup.Items.Count - 1 do311 Popup.Items[ i].Checked := Popup.Items[i].Tag = Page;308 I: Integer; 309 begin 310 for I := 0 to Popup.Items.Count - 1 do 311 Popup.Items[I].Checked := Popup.Items[I].Tag = Page; 312 312 Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height); 313 313 end; … … 321 321 procedure TEnhanceDlg.JobClick(Sender: TObject); 322 322 var 323 stage, NewJob: integer;323 stage, NewJob: Integer; 324 324 Done: Set of jNone .. jTrans; 325 325 326 procedure RemoveJob( j: integer);326 procedure RemoveJob(J: Integer); 327 327 begin // remove job 328 328 stage := 0; 329 329 while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do 330 330 begin 331 if (MyData.EnhancementJobs[Page, stage] = j) or (j= jRoad) and332 (MyData.EnhancementJobs[Page, stage] = jRR) or ( j= jIrr) and331 if (MyData.EnhancementJobs[Page, stage] = J) or (J = jRoad) and 332 (MyData.EnhancementJobs[Page, stage] = jRR) or (J = jIrr) and 333 333 (MyData.EnhancementJobs[Page, stage] = jFarm) then 334 334 begin 335 335 if stage < 4 then 336 move(MyData.EnhancementJobs[Page, stage + 1],336 Move(MyData.EnhancementJobs[Page, stage + 1], 337 337 MyData.EnhancementJobs[Page, stage], 4 - stage); 338 338 MyData.EnhancementJobs[Page, 4] := jNone; 339 339 end 340 340 else 341 inc(stage);341 Inc(stage); 342 342 end; 343 343 end; … … 349 349 while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do 350 350 begin 351 include(Done, MyData.EnhancementJobs[Page, stage]);352 inc(stage);351 Include(Done, MyData.EnhancementJobs[Page, stage]); 352 Inc(stage); 353 353 end; 354 354 if NewJob in Done then … … 363 363 begin 364 364 MyData.EnhancementJobs[Page, stage] := jRoad; 365 inc(stage);365 Inc(stage); 366 366 end; 367 367 if (NewJob = jFarm) and not(jIrr in Done) then 368 368 begin 369 369 MyData.EnhancementJobs[Page, stage] := jIrr; 370 inc(stage);370 Inc(stage); 371 371 end; 372 372 MyData.EnhancementJobs[Page, stage] := NewJob; -
trunk/LocalPlayer/Help.pas
r431 r447 41 41 THyperText = class(TStringList) 42 42 public 43 procedure AddLine( s: String = ''; Format: integer = 0; Picpix: Integer = 0;44 LinkCategory: integer = 0; LinkIndex: integer = 0);43 procedure AddLine(S: String = ''; Format: Integer = 0; Picpix: Integer = 0; 44 LinkCategory: Integer = 0; LinkIndex: Integer = 0); 45 45 procedure LineFeed; 46 46 procedure AppendList(Source: THyperText); … … 78 78 procedure CloseBtnClick(Sender: TObject); 79 79 procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 80 x, y: integer);80 X, Y: Integer); 81 81 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 82 Shift: TShiftState; x, y: integer);82 Shift: TShiftState; X, Y: Integer); 83 83 procedure BackBtnClick(Sender: TObject); 84 84 procedure TopBtnClick(Sender: TObject); … … 104 104 NoMap: TIsoMap; 105 105 x0: array [-2..180] of Integer; 106 procedure PaintTerrIcon( x, y, xSrc, ySrc: Integer);106 procedure PaintTerrIcon(X, Y, xSrc, ySrc: Integer); 107 107 procedure ScrollBarUpdate(Sender: TObject); 108 procedure Line(ca: TCanvas; i: Integer; lit: Boolean);108 procedure Line(ca: TCanvas; I: Integer; lit: Boolean); 109 109 procedure Prepare(sbPos: Integer = 0); 110 110 procedure ShowNewContentProcExecute(NewMode: TWindowMode; HelpContext: string); … … 176 176 end; 177 177 178 procedure THyperText.AddLine( s: String; Format: integer; Picpix: integer;179 LinkCategory: integer; LinkIndex: integer);178 procedure THyperText.AddLine(S: String; Format: Integer; Picpix: Integer; 179 LinkCategory: Integer; LinkIndex: Integer); 180 180 var 181 181 HelpLineInfo: THelpLineInfo; … … 187 187 HelpLineInfo.Picpix := Picpix; 188 188 HelpLineInfo.Link := LinkCategory shl 8 + LinkIndex; 189 AddObject( s, TObject(HelpLineInfo));189 AddObject(S, TObject(HelpLineInfo)); 190 190 end; 191 191 … … 263 263 264 264 nTerrainHelp = 14; 265 TerrainHelp: array [0 .. nTerrainHelp - 1] of integer = (fGrass, fGrass + 12,265 TerrainHelp: array [0 .. nTerrainHelp - 1] of Integer = (fGrass, fGrass + 12, 266 266 fPrairie, fForest, fJungle, fHills, fMountains, fSwamp, fTundra, fArctic, 267 267 fDesert, 3 * 12 { DeadLands } , fShore, fOcean); 268 268 269 269 nJobHelp = 8; 270 JobHelp: array [0 .. nJobHelp - 1] of integer = (jRoad, jRR, jCanal, jIrr,270 JobHelp: array [0 .. nJobHelp - 1] of Integer = (jRoad, jRR, jCanal, jIrr, 271 271 jFarm, jMine, jFort, jBase); 272 272 … … 280 280 CaptionLeft := BackBtn.Left + BackBtn.Width; 281 281 CaptionRight := SearchBtn.Left; 282 inc(ModalFrameIndent, 29);282 Inc(ModalFrameIndent, 29); 283 283 MainText := THyperText.Create; 284 284 MainText.OwnsObjects := True; … … 356 356 if ScrollBar.Process(Msg) then begin 357 357 Sel := -1; 358 SmartUpdateContent( true)358 SmartUpdateContent(True) 359 359 end; 360 360 } … … 364 364 begin 365 365 if Sel <> -1 then begin 366 Line(Canvas, Sel, false);366 Line(Canvas, Sel, False); 367 367 Sel := -1 368 368 end; … … 380 380 end; 381 381 382 procedure THelpDlg.Line(ca: TCanvas; i: Integer; lit: Boolean);382 procedure THelpDlg.Line(ca: TCanvas; I: Integer; lit: Boolean); 383 383 var 384 TextColor, x, y: Integer;384 TextColor, X, Y: Integer; 385 385 TextSize: TSize; 386 s: string;387 begin 388 s := MainText[ScrollBar.Position + i];389 if s= '' then386 S: string; 387 begin 388 S := MainText[ScrollBar.Position + I]; 389 if S = '' then 390 390 Exit; 391 x := x0[i];392 y := 2 + i* 24;391 X := x0[I]; 392 Y := 2 + I * 24; 393 393 if ca = Canvas then 394 394 begin 395 x := x+ SideFrame;396 y := y+ WideFrame397 end; 398 if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format395 X := X + SideFrame; 396 Y := Y + WideFrame 397 end; 398 if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format 399 399 in [pkCaption, pkBigTer, pkRightIcon, pkBigFeature] then 400 400 begin 401 401 ca.Font.Assign(CaptionFont); 402 402 { ca.brush.color:=CaptionColor; 403 ca.FillRect(rect( x,i*24,x+24,i*24+24));404 ca. brush.color:=$FFFFFF;405 ca.FrameRect(rect( x+1,i*24+1,x+24-1,i*24+24-1));403 ca.FillRect(rect(X,I*24,X+24,I*24+24)); 404 ca.Brush.Color:=$FFFFFF; 405 ca.FrameRect(rect(X+1,I*24+1,X+24-1,I*24+24-1)); 406 406 ca.Brush.Style:=bsClear; } 407 BitBltCanvas(ca, x, y- 4, 24, 24, HGrSystem.Data.Canvas, 1,407 BitBltCanvas(ca, X, Y - 4, 24, 24, HGrSystem.Data.Canvas, 1, 408 408 146); 409 BiColorTextOut(ca, $FFFFFF, $7F007F, x + 10 - ca.Textwidth(s[1]) div 2,410 y - 3, s[1]);411 BiColorTextOut(ca, CaptionColor, $7F007F, x + 24, y - 3, copy(s, 2, 255));409 BiColorTextOut(ca, $FFFFFF, $7F007F, X + 10 - ca.Textwidth(S[1]) div 2, 410 Y - 3, S[1]); 411 BiColorTextOut(ca, CaptionColor, $7F007F, X + 24, Y - 3, Copy(S, 2, 255)); 412 412 ca.Font.Assign(UniFont[ftNormal]); 413 413 end 414 else if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format = pkSection414 else if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format = pkSection 415 415 then 416 416 begin 417 417 ca.Font.Assign(CaptionFont); 418 BiColorTextOut(ca, CaptionColor, $7F007F, x, y - 3, s);418 BiColorTextOut(ca, CaptionColor, $7F007F, X, Y - 3, S); 419 419 ca.Font.Assign(UniFont[ftNormal]); 420 420 end … … 426 426 if ca = Canvas then 427 427 begin 428 TextSize.cx := BiColorTextWidth(ca, s);429 TextSize.cy := ca.TextHeight( s);430 if y+ TextSize.cy >= WideFrame + InnerHeight then431 TextSize.cy := WideFrame + InnerHeight - y;432 FillSeamless(ca, x, y, TextSize.cx, TextSize.cy, -SideFrame,428 TextSize.cx := BiColorTextWidth(ca, S); 429 TextSize.cy := ca.TextHeight(S); 430 if Y + TextSize.cy >= WideFrame + InnerHeight then 431 TextSize.cy := WideFrame + InnerHeight - Y; 432 FillSeamless(ca, X, Y, TextSize.cx, TextSize.cy, -SideFrame, 433 433 ScrollBar.Position * 24 - WideFrame, Paper); 434 434 end; 435 BiColorTextOut(ca, TextColor, $7F007F, x, y, s);435 BiColorTextOut(ca, TextColor, $7F007F, X, Y, S); 436 436 if lit then 437 437 with ca do … … 439 439 Assert(ca = Canvas); 440 440 Pen.Color := TextColor; 441 MoveTo( x + 1, y+ TextSize.cy - 2);442 LineTo( x + TextSize.cx, y+ TextSize.cy - 2);441 MoveTo(X + 1, Y + TextSize.cy - 2); 442 LineTo(X + TextSize.cx, Y + TextSize.cy - 2); 443 443 end; 444 444 if (Kind = hkMisc) and (no = miscMain) then … … 447 447 end; 448 448 449 procedure THelpDlg.WaterSign(x0, y0, iix: integer);449 procedure THelpDlg.WaterSign(x0, y0, iix: Integer); 450 450 const 451 451 nHeaven = 28; 452 452 MaxSum = 9 * 9 * 255 * 75 div 100; 453 453 var 454 x, y, dx, dy, xSrc, ySrc, Sum, xx: integer;455 Heaven: array [0..nHeaven] of integer;454 X, Y, dx, dy, xSrc, ySrc, Sum, xx: Integer; 455 Heaven: array [0..nHeaven] of Integer; 456 456 PaintPtr: TPixelPointer; 457 457 CoalPtr: TPixelPointer; … … 471 471 for dy := -1 to 1 do 472 472 ImpPtr[dy] := PixelPointer(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc)); 473 for y:= 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin474 if ((ScaleToNative(y0) + y) >= 0) and ((ScaleToNative(y0) + y) < ScaleToNative(InnerHeight)) then begin473 for Y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin 474 if ((ScaleToNative(y0) + Y) >= 0) and ((ScaleToNative(y0) + Y) < ScaleToNative(InnerHeight)) then begin 475 475 for dy := -1 to 1 do 476 if ((Max( y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(y+ ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then477 ImpPtr[dy].SetXY(0, Max( y+ ScaleToNative(dy), 0) shr 1);478 for x:= 0 to ScaleToNative(xSizeBig * 2) - 1 do begin476 if ((Max(Y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(Y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then 477 ImpPtr[dy].SetXY(0, Max(Y + ScaleToNative(dy), 0) shr 1); 478 for X := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin 479 479 Sum := 0; 480 480 for dx := -1 to 1 do begin 481 xx := Max(( x+ ScaleToNative(dx)), 0) shr 1;481 xx := Max((X + ScaleToNative(dx)), 0) shr 1; 482 482 for dy := -1 to 1 do begin 483 483 ImpPtr[dy].SetX(xx); 484 if (( y + ScaleToNative(dy)) shr 1 < 0) or ((y+ ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or485 (( x + ScaleToNative(dx)) shr 1 < 0) or ((x+ ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or486 (( y+ ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and484 if ((Y + ScaleToNative(dy)) shr 1 < 0) or ((Y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or 485 ((X + ScaleToNative(dx)) shr 1 < 0) or ((X + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or 486 ((Y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and 487 487 (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 + 488 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative( y+ ScaleToNative(dy))) shr 1]) then488 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(Y + ScaleToNative(dy))) shr 1]) then 489 489 Sum := Sum + 9 * 255 490 490 else … … 510 510 end; 511 511 512 procedure THelpDlg.PaintTerrIcon( x, y, xSrc, ySrc: integer);512 procedure THelpDlg.PaintTerrIcon(X, Y, xSrc, ySrc: Integer); 513 513 begin 514 514 with NoMap do begin 515 Frame(OffScreen.Canvas, x - 1, y - 1, x + xSizeBig, y+ ySizeBig,515 Frame(OffScreen.Canvas, X - 1, Y - 1, X + xSizeBig, Y + ySizeBig, 516 516 $000000, $000000); 517 517 if 2 * yyt < 40 then begin 518 Sprite(OffScreen, HGrTerrain, x, y, 56, 2 * yyt, xSrc, ySrc);519 Sprite(OffScreen, HGrTerrain, x, y+ 2 * yyt, 56, 40 - 2 * yyt,518 Sprite(OffScreen, HGrTerrain, X, Y, 56, 2 * yyt, xSrc, ySrc); 519 Sprite(OffScreen, HGrTerrain, X, Y + 2 * yyt, 56, 40 - 2 * yyt, 520 520 xSrc, ySrc); 521 521 end else 522 Sprite(OffScreen, HGrTerrain, x, y, 56, 40, xSrc, ySrc);523 Sprite(OffScreen, HGrTerrain, x, y, xxt, yyt, xSrc + xxt, ySrc + yyt);524 Sprite(OffScreen, HGrTerrain, x, y+ yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);525 Sprite(OffScreen, HGrTerrain, x + xxt, y, 56 - xxt, yyt, xSrc, ySrc + yyt);526 Sprite(OffScreen, HGrTerrain, x + xxt, y+ yyt, 56 - xxt, 40 - yyt,522 Sprite(OffScreen, HGrTerrain, X, Y, 56, 40, xSrc, ySrc); 523 Sprite(OffScreen, HGrTerrain, X, Y, xxt, yyt, xSrc + xxt, ySrc + yyt); 524 Sprite(OffScreen, HGrTerrain, X, Y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc); 525 Sprite(OffScreen, HGrTerrain, X + xxt, Y, 56 - xxt, yyt, xSrc, ySrc + yyt); 526 Sprite(OffScreen, HGrTerrain, X + xxt, Y + yyt, 56 - xxt, 40 - yyt, 527 527 xSrc, ySrc); 528 528 end; … … 531 531 procedure THelpDlg.OffscreenPaint; 532 532 var 533 i, j, yl, srcno, ofs, cnt, y: Integer;534 s: string;533 I, J, yl, srcno, ofs, cnt, Y: Integer; 534 S: string; 535 535 HelpLineInfo: THelpLineInfo; 536 536 begin … … 542 542 begin 543 543 Font.Assign(UniFont[ftNormal]); 544 for i:= -ScrollBar.Position to InnerHeight div 24 do545 if ScrollBar.Position + i< MainText.Count then544 for I := -ScrollBar.Position to InnerHeight div 24 do 545 if ScrollBar.Position + I < MainText.Count then 546 546 begin 547 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);547 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]); 548 548 if HelpLineInfo.Format = pkExternal then 549 549 begin 550 550 yl := ExtPic.Height; 551 if 4 + i* 24 + yl > InnerHeight then552 yl := InnerHeight - (4 + i* 24);553 BitBltCanvas(OffScreen.Canvas, 8, 4 + i* 24, ExtPic.Width, yl, ExtPic.Canvas,551 if 4 + I * 24 + yl > InnerHeight then 552 yl := InnerHeight - (4 + I * 24); 553 BitBltCanvas(OffScreen.Canvas, 8, 4 + I * 24, ExtPic.Width, yl, ExtPic.Canvas, 554 554 0, 0); 555 555 end; 556 556 end; 557 for i:= -2 to InnerHeight div 24 do558 if (ScrollBar.Position + i >= 0) and (ScrollBar.Position + i< MainText.Count) then557 for I := -2 to InnerHeight div 24 do 558 if (ScrollBar.Position + I >= 0) and (ScrollBar.Position + I < MainText.Count) then 559 559 begin 560 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);560 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]); 561 561 if HelpLineInfo.Link <> 0 then 562 562 begin 563 563 if (Kind = hkMisc) and (no = miscSearchResult) then 564 Sprite(OffScreen, HGrSystem, 18, 9 + i* 24, 8, 8, 90, 16)564 Sprite(OffScreen, HGrSystem, 18, 9 + I * 24, 8, 8, 90, 16) 565 565 else if HelpLineInfo.Format in [pkSmallIcon_AsPreq, pkAdvIcon_AsPreq] 566 566 then 567 Sprite(OffScreen, HGrSystem, 12, i* 24 + 5, 14, 14, 65, 20)567 Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 65, 20) 568 568 else if HelpLineInfo.Link and (hkCrossLink shl 8) <> 0 then 569 Sprite(OffScreen, HGrSystem, 12, i* 24 + 5, 14, 14, 80, 1)569 Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 80, 1) 570 570 else if not((Kind = hkMisc) and (no = miscMain)) then 571 Sprite(OffScreen, HGrSystem, 10, i* 24 + 6, 14, 14, 65, 1);572 x0[ i] := 24;571 Sprite(OffScreen, HGrSystem, 10, I * 24 + 6, 14, 14, 65, 1); 572 x0[I] := 24; 573 573 end 574 574 else 575 x0[ i] := 0;575 x0[I] := 0; 576 576 case HelpLineInfo.Format of 577 577 pkLogo: 578 578 begin 579 Server(sGetVersion, 0, 0, j);580 s := Format('%d.%d.%d', [j shr 16 and $FF, jshr 8 and $FF,581 jand $FF]);582 PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, i* 24 + 1,579 Server(sGetVersion, 0, 0, J); 580 S := Format('%d.%d.%d', [J shr 16 and $FF, J shr 8 and $FF, 581 J and $FF]); 582 PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, I * 24 + 1, 583 583 HGrSystem.Data.Canvas.Pixels[95, 1], $000000); 584 584 Font.Assign(UniFont[ftSmall]); 585 585 BiColorTextOut(OffScreen.Canvas, $000000, $7F007F, 586 (InnerWidth - Textwidth( s)) div 2, i * 24 + 26, s);586 (InnerWidth - Textwidth(S)) div 2, I * 24 + 26, S); 587 587 Font.Assign(UniFont[ftNormal]); 588 588 end; 589 589 pkSmallIcon, pkSmallIcon_AsPreq: 590 590 begin 591 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[ i], 2 - 1 + i* 24,592 8 + xSizeSmall + x0[ i], 2 + 20 + i* 24, $000000, $000000);591 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 592 8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000); 593 593 if HelpLineInfo.Picpix = imPalace then 594 BitBltCanvas(OffScreen.Canvas, 8 + x0[ i], 2 + i* 24,594 BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 595 595 xSizeSmall, ySizeSmall, SmallImp.Canvas, 596 596 0 * xSizeSmall, 1 * ySizeSmall) 597 597 else 598 BitBltCanvas(OffScreen.Canvas, 8 + x0[ i], 2 + i* 24,598 BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 599 599 xSizeSmall, ySizeSmall, SmallImp.Canvas, 600 600 HelpLineInfo.Picpix mod 7 * xSizeSmall, 601 601 (HelpLineInfo.Picpix + SystemIconLines * 7) div 7 * 602 602 ySizeSmall); 603 x0[ i] := x0[i] + (8 + 8 + 36);603 x0[I] := x0[I] + (8 + 8 + 36); 604 604 end; 605 605 pkBigIcon: 606 606 begin 607 FrameImage(OffScreen.Canvas, BigImp, x0[ i] + 12, i* 24 - 7, 56,607 FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 56, 608 608 40, HelpLineInfo.Picpix mod 7 * xSizeBig, 609 609 HelpLineInfo.Picpix div 7 * ySizeBig); 610 x0[ i] := 64 + 8 + 8 + x0[i];610 x0[I] := 64 + 8 + 8 + x0[I]; 611 611 end; 612 612 pkSpecialIcon: … … 615 615 0: 616 616 FrameImage(OffScreen.Canvas, HGrSystem2.Data, 617 12 + x0[ i], -7 + i* 24, 56, 40, 137, 127);617 12 + x0[I], -7 + I * 24, 56, 40, 137, 127); 618 618 1: 619 619 with NoMap do begin 620 PaintTerrIcon(12 + x0[ i], -7 + i* 24,620 PaintTerrIcon(12 + x0[I], -7 + I * 24, 621 621 1 + 3 * (xxt * 2 + 1), 1 + yyt); 622 622 if 2 * yyt < 40 then 623 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,623 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 624 624 56, 2 * yyt, 1 + 3 * (xxt * 2 + 1) + xxt - 28, 625 625 1 + yyt + 1 * (yyt * 3 + 1)) 626 626 else 627 Sprite(OffScreen, HGrTerrain, 12 + x0[ i],628 -7 + 4 + i* 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt627 Sprite(OffScreen, HGrTerrain, 12 + x0[I], 628 -7 + 4 + I * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt 629 629 - 28, 1 + yyt + 1 * (yyt * 3 + 1) + yyt - 20); 630 630 end; 631 631 2: 632 632 with NoMap do begin 633 PaintTerrIcon(12 + x0[ i], -7 + i* 24,633 PaintTerrIcon(12 + x0[I], -7 + I * 24, 634 634 1 + 7 * (xxt * 2 + 1), 1 + yyt + 4 * (yyt * 3 + 1)); 635 635 if 2 * yyt < 40 then 636 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,636 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 637 637 56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28, 638 638 1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16) 639 639 else 640 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,640 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 641 641 56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28, 642 642 1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16) 643 643 end; 644 644 end; 645 x0[ i] := 64 + 8 + 8 + x0[i];645 x0[I] := 64 + 8 + 8 + x0[I]; 646 646 end; 647 647 pkDomain: 648 648 begin 649 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[ i], 2 - 1 + i* 24,650 8 + 36 + x0[ i], 2 + 20 + i* 24, $000000, $000000);651 Dump(OffScreen, HGrSystem, 8 + x0[ i], 2 + i* 24, 36, 20,649 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 650 8 + 36 + x0[I], 2 + 20 + I * 24, $000000, $000000); 651 Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20, 652 652 75 + HelpLineInfo.Picpix * 37, 295); 653 x0[ i] := x0[i] + (8 + 8 + 36);653 x0[I] := x0[I] + (8 + 8 + 36); 654 654 end; 655 655 pkAdvIcon, pkAdvIcon_AsPreq: 656 656 begin 657 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[ i], 2 - 1 + i* 24,658 8 + xSizeSmall + x0[ i], 2 + ySizeSmall + i* 24,657 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 658 8 + xSizeSmall + x0[I], 2 + ySizeSmall + I * 24, 659 659 $000000, $000000); 660 660 if AdvIcon[HelpLineInfo.Picpix] < 84 then 661 BitBltCanvas(OffScreen.Canvas, 8 + x0[ i], 2 + i* 24,661 BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 662 662 xSizeSmall, ySizeSmall, SmallImp.Canvas, 663 663 (AdvIcon[HelpLineInfo.Picpix] + SystemIconLines * 7) mod 7 * … … 665 665 7) div 7 * ySizeSmall) 666 666 else 667 Dump(OffScreen, HGrSystem, 8 + x0[ i], 2 + i* 24, 36, 20,667 Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20, 668 668 1 + (AdvIcon[HelpLineInfo.Picpix] - 84) mod 8 * 37, 669 669 295 + (AdvIcon[HelpLineInfo.Picpix] - 84) div 8 * 21); 670 j:= AdvValue[HelpLineInfo.Picpix] div 1000;671 BitBltCanvas(OffScreen.Canvas, x0[ i] + 4, 4 + i* 24, 14, 14,672 HGrSystem.Mask.Canvas, 127 + j* 15, 85, SRCAND);673 Sprite(OffScreen, HGrSystem, x0[ i] + 3, 3 + i* 24, 14, 14,674 127 + j* 15, 85);675 x0[ i] := x0[i] + (8 + 8 + 36);670 J := AdvValue[HelpLineInfo.Picpix] div 1000; 671 BitBltCanvas(OffScreen.Canvas, x0[I] + 4, 4 + I * 24, 14, 14, 672 HGrSystem.Mask.Canvas, 127 + J * 15, 85, SRCAND); 673 Sprite(OffScreen, HGrSystem, x0[I] + 3, 3 + I * 24, 14, 14, 674 127 + J * 15, 85); 675 x0[I] := x0[I] + (8 + 8 + 36); 676 676 end; 677 677 pkRightIcon: 678 678 begin 679 679 if Imp[HelpLineInfo.Picpix].Kind <> ikWonder then 680 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), i* 24,680 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), I * 24, 681 681 HelpLineInfo.Picpix, gDespotism) 682 682 else 683 WaterSign(InnerWidth - (40 + 2 * xSizeBig), i* 24 - 8,683 WaterSign(InnerWidth - (40 + 2 * xSizeBig), I * 24 - 8, 684 684 HelpLineInfo.Picpix + 7); 685 x0[ i] := x0[i] + 8;685 x0[I] := x0[I] + 8; 686 686 end; 687 687 pkIllu: 688 WaterSign(8, i* 24 - 8, HelpLineInfo.Picpix);688 WaterSign(8, I * 24 - 8, HelpLineInfo.Picpix); 689 689 pkBigFeature: 690 690 begin 691 691 cnt := 0; 692 for j:= nDomains - 1 downto 0 do693 if 1 shl jand Feature[HelpLineInfo.Picpix].Domains <> 0 then692 for J := nDomains - 1 downto 0 do 693 if 1 shl J and Feature[HelpLineInfo.Picpix].Domains <> 0 then 694 694 begin 695 inc(cnt);695 Inc(cnt); 696 696 Dump(OffScreen, HGrSystem, InnerWidth - 38 - 38 * cnt, 697 i * 24 + 1, 36, 20, 75 + j* 37, 295);698 ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, i* 24,699 InnerWidth - 2 - 38 * cnt, i* 24 + 21, $000000, $000000);697 I * 24 + 1, 36, 20, 75 + J * 37, 295); 698 ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, I * 24, 699 InnerWidth - 2 - 38 * cnt, I * 24 + 21, $000000, $000000); 700 700 end; 701 701 DarkGradient(OffScreen.Canvas, InnerWidth - 38 - 38 * cnt, 702 i* 24 + 23, cnt * 38 - 2, 1);702 I * 24 + 23, cnt * 38 - 2, 1); 703 703 ofs := InnerWidth - (39 + 7) - 19 * cnt; 704 704 with OffScreen.Canvas do 705 705 begin 706 Brush. color := $C0C0C0;707 FrameRect(Rect(ofs, 1 + 23 + i* 24, ofs + 14,708 15 + 23 + i* 24));706 Brush.Color := $C0C0C0; 707 FrameRect(Rect(ofs, 1 + 23 + I * 24, ofs + 14, 708 15 + 23 + I * 24)); 709 709 Brush.Style := bsClear; 710 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + i* 24, 10, 10,710 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + I * 24, 10, 10, 711 711 66 + HelpLineInfo.Picpix mod 11 * 11, 712 712 137 + HelpLineInfo.Picpix div 11 * 11); 713 713 end; 714 x0[ i] := x0[i] + 8;714 x0[I] := x0[I] + 8; 715 715 end; 716 716 pkTer, pkBigTer: 717 717 with NoMap do begin 718 718 if HelpLineInfo.Format = pkBigTer then 719 y := i* 24 - 3 + yyt719 Y := I * 24 - 3 + yyt 720 720 else 721 y := i* 24 + 13;721 Y := I * 24 + 13; 722 722 if HelpLineInfo.Picpix >= 3 * 12 then 723 723 srcno := 2 * 9 + 6 … … 730 730 if HelpLineInfo.Format = pkTer then 731 731 begin 732 ofs := x0[ i] + 8;733 x0[ i] := 2 * xxt + 8 + ofs;732 ofs := x0[I] + 8; 733 x0[I] := 2 * xxt + 8 + ofs; 734 734 end 735 735 else 736 736 begin 737 737 ofs := InnerWidth - (2 * xxt + 38); 738 x0[ i] := x0[i] + 8;738 x0[I] := x0[I] + 8; 739 739 end; 740 740 if srcno >= fJungle then 741 741 begin 742 Sprite(OffScreen, HGrTerrain, ofs + 4, y- yyt + 2, xxt * 2 - 8,742 Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, 743 743 yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1), 744 744 3 + yyt + 2 * (yyt * 3 + 1)); 745 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,745 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 746 746 yyt * 3 - 2, 1 + srcno mod 9 * (xxt * 2 + 1), 747 747 1 + srcno div 9 * (yyt * 3 + 1)); 748 748 end 749 749 else 750 Sprite(OffScreen, HGrTerrain, ofs + 4, y- yyt + 2, xxt * 2 - 8,750 Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, 751 751 yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1), 752 752 3 + yyt + srcno div 9 * (yyt * 3 + 1)); 753 753 if HelpLineInfo.Picpix >= 3 * 12 then { rare resource } 754 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,754 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 755 755 yyt * 3, 1 + 8 * (xxt * 2 + 1), 756 756 1 + (HelpLineInfo.Picpix - 2 * 12) * (yyt * 3 + 1)) … … 764 764 srcno := 18 + 8 + (HelpLineInfo.Picpix mod 12 - 9) * 18; 765 765 srcno := srcno + HelpLineInfo.Picpix div 12 * 9; 766 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,766 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 767 767 yyt * 3, 1 + srcno mod 9 * (xxt * 2 + 1), 768 768 1 + srcno div 9 * (yyt * 3 + 1)); … … 774 774 if HelpLineInfo.Picpix = 5 then 775 775 begin // display mine on hills 776 Sprite(OffScreen, HGrTerrain, ofs + 4, i* 24 + 13 - yyt,776 Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt, 777 777 xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1), 778 778 3 + yyt + 2 * (yyt * 3 + 1)); … … 781 781 else 782 782 srcno := fPrairie; // display on prairie 783 Sprite(OffScreen, HGrTerrain, ofs + 4, i* 24 + 13 - yyt,783 Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt, 784 784 xxt * 2 - 8, yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1), 785 785 3 + yyt + srcno div 9 * (yyt * 3 + 1)); 786 786 if HelpLineInfo.Picpix = 12 then { river } 787 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - yyt, xxt * 2,787 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - yyt, xxt * 2, 788 788 yyt * 2, 1 + 5 * (xxt * 2 + 1), 1 + yyt + 13 * (yyt * 3 + 1)) 789 789 else if HelpLineInfo.Picpix >= 3 then { improvement 2 } 790 790 begin 791 791 if HelpLineInfo.Picpix = 6 then 792 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,792 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 793 793 xxt * 2, yyt * 3, 1 + 7 * (xxt * 2 + 1), 794 794 1 + 12 * (yyt * 3 + 1)); 795 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,795 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 796 796 xxt * 2, yyt * 3, 1 + (HelpLineInfo.Picpix - 3) * 797 797 (xxt * 2 + 1), 1 + 12 * (yyt * 3 + 1)) … … 799 799 else { improvement 1 } 800 800 begin 801 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,801 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 802 802 xxt * 2, yyt * 3, 1 + 2 * (xxt * 2 + 1), 803 803 1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1)); 804 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,804 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 805 805 xxt * 2, yyt * 3, 1 + 5 * (xxt * 2 + 1), 806 806 1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1)) 807 807 end; 808 x0[ i] := x0[i] + 8;808 x0[I] := x0[I] + 8; 809 809 end; 810 810 pkModel: 811 811 begin 812 FrameImage(OffScreen.Canvas, BigImp, x0[ i] + 12, i* 24 - 7,812 FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 813 813 56, 40, 0, 0); 814 Sprite(OffScreen, HGrStdUnits, x0[ i] + 8, i* 24 - 11, 64, 44,814 Sprite(OffScreen, HGrStdUnits, x0[I] + 8, I * 24 - 11, 64, 44, 815 815 1 + HelpLineInfo.Picpix mod 10 * 65, 816 816 1 + HelpLineInfo.Picpix div 10 * 49); 817 x0[ i] := 64 + 8 + 8 + x0[i];817 x0[I] := 64 + 8 + 8 + x0[I]; 818 818 end; 819 819 pkFeature: 820 820 begin 821 DarkGradient(OffScreen.Canvas, x0[ i] + 8 - 1,822 7 + i* 24 - 3, 16, 1);823 ScreenTools.Frame(OffScreen.Canvas, x0[ i] + 8, 7 + i * 24 - 2, x0[i] + 8 + 13,824 7 + i* 24 - 2 + 13, $C0C0C0, $C0C0C0);825 Sprite(OffScreen, HGrSystem, x0[ i] + 8 + 2, 7 + i* 24, 10, 10,821 DarkGradient(OffScreen.Canvas, x0[I] + 8 - 1, 822 7 + I * 24 - 3, 16, 1); 823 ScreenTools.Frame(OffScreen.Canvas, x0[I] + 8, 7 + I * 24 - 2, x0[I] + 8 + 13, 824 7 + I * 24 - 2 + 13, $C0C0C0, $C0C0C0); 825 Sprite(OffScreen, HGrSystem, x0[I] + 8 + 2, 7 + I * 24, 10, 10, 826 826 66 + HelpLineInfo.Picpix mod 11 * 11, 827 827 137 + HelpLineInfo.Picpix div 11 * 11); 828 x0[ i] := x0[i] + 8 + 8 + 2 + 13;828 x0[I] := x0[I] + 8 + 8 + 2 + 13; 829 829 end; 830 830 pkExp: 831 831 begin 832 ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + i* 24, 20 + 12,833 8 + 11 + i* 24, $000000, $000000);834 Dump(OffScreen, HGrSystem, 20, 8 - 3 + i* 24, 12, 14,832 ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + I * 24, 20 + 12, 833 8 + 11 + I * 24, $000000, $000000); 834 Dump(OffScreen, HGrSystem, 20, 8 - 3 + I * 24, 12, 14, 835 835 121 + HelpLineInfo.Picpix * 13, 28); 836 x0[ i] := 20 + 8 + 11;836 x0[I] := 20 + 8 + 11; 837 837 end; 838 838 pkAITStat: 839 839 begin 840 Sprite(OffScreen, HGrSystem, 20, 6 + i* 24, 14, 14,840 Sprite(OffScreen, HGrSystem, 20, 6 + I * 24, 14, 14, 841 841 1 + HelpLineInfo.Picpix * 15, 316); 842 x0[ i] := 20 + 8 + 11;842 x0[I] := 20 + 8 + 11; 843 843 end; 844 844 pkGov: 845 845 begin 846 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[ i], 2 - 1 + i* 24,847 8 + xSizeSmall + x0[ i], 2 + 20 + i* 24, $000000, $000000);848 BitBltCanvas(OffScreen.Canvas, 8 + x0[ i], 2 + i* 24, xSizeSmall,846 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 847 8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000); 848 BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, xSizeSmall, 849 849 ySizeSmall, SmallImp.Canvas, (HelpLineInfo.Picpix - 1) * 850 850 xSizeSmall, ySizeSmall); 851 x0[ i] := x0[i] + (8 + 8 + 36);851 x0[I] := x0[I] + (8 + 8 + 36); 852 852 end; 853 853 pkDot: 854 854 begin 855 Sprite(OffScreen, HGrSystem, x0[ i] + 18, 9 + i* 24, 8,855 Sprite(OffScreen, HGrSystem, x0[I] + 18, 9 + I * 24, 8, 856 856 8, 81, 16); 857 x0[ i] := 20 + 8 + 4;857 x0[I] := 20 + 8 + 4; 858 858 end; 859 859 pkNormal_Dot: 860 x0[ i] := 20 + 8 + 4;860 x0[I] := 20 + 8 + 4; 861 861 pkNormal_64: 862 x0[ i] := 64 + 8 + 8;862 x0[I] := 64 + 8 + 8; 863 863 else 864 x0[ i] := x0[i] + 8;864 x0[I] := x0[I] + 8; 865 865 end; 866 Self.Line(OffScreen.Canvas, i, False)866 Self.Line(OffScreen.Canvas, I, False) 867 867 end; 868 868 end; … … 873 873 begin 874 874 Sel := -1; 875 SmartUpdateContent( true)876 end; 877 878 procedure THelpDlg.Prepare(sbPos: integer = 0);875 SmartUpdateContent(True) 876 end; 877 878 procedure THelpDlg.Prepare(sbPos: Integer = 0); 879 879 var 880 i, j, Special, Domain, Headline, TerrType, TerrSubType: integer;881 s: string;882 ps: pchar;880 I, J, Special, Domain, Headline, TerrType, TerrSubType: Integer; 881 S: string; 882 ps: PChar; 883 883 List: THyperText; 884 884 CheckSeeAlso: Boolean; 885 885 886 procedure AddAdvance( i: integer);887 begin 888 MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,889 hkAdv + hkCrossLink, i);890 end; 891 892 procedure AddPreqAdv( i: integer);893 begin 894 MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon_AsPreq, i,895 hkAdv + hkCrossLink, i);896 end; 897 898 procedure AddImprovement( i: integer);899 begin 900 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,901 hkImp + hkCrossLink, i);902 end; 903 904 procedure AddPreqImp( i: integer);905 begin 906 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon_AsPreq, i,907 hkImp + hkCrossLink, i);908 end; 909 910 procedure AddTerrain( i: integer);886 procedure AddAdvance(I: Integer); 887 begin 888 MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I, 889 hkAdv + hkCrossLink, I); 890 end; 891 892 procedure AddPreqAdv(I: Integer); 893 begin 894 MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon_AsPreq, I, 895 hkAdv + hkCrossLink, I); 896 end; 897 898 procedure AddImprovement(I: Integer); 899 begin 900 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 901 hkImp + hkCrossLink, I); 902 end; 903 904 procedure AddPreqImp(I: Integer); 905 begin 906 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon_AsPreq, I, 907 hkImp + hkCrossLink, I); 908 end; 909 910 procedure AddTerrain(I: Integer); 911 911 begin 912 912 if MainText.Count > 1 then … … 914 914 MainText.LineFeed; 915 915 end; 916 MainText.AddLine(Phrases.Lookup('TERRAIN', i), pkTer, i, hkTer, i);917 end; 918 919 procedure AddFeature( i: integer);920 begin 921 MainText.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,922 hkFeature + hkCrossLink, i);923 end; 924 925 procedure AddModel( i: integer);916 MainText.AddLine(Phrases.Lookup('TERRAIN', I), pkTer, I, hkTer, I); 917 end; 918 919 procedure AddFeature(I: Integer); 920 begin 921 MainText.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I, 922 hkFeature + hkCrossLink, I); 923 end; 924 925 procedure AddModel(I: Integer); 926 926 var 927 pix: integer;927 pix: Integer; 928 928 Name: string; 929 929 begin 930 930 if MainText.Count > 1 then 931 931 MainText.LineFeed; 932 FindStdModelPicture(SpecialModelPictureCode[ i], pix, Name);933 MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, i)932 FindStdModelPicture(SpecialModelPictureCode[I], pix, Name); 933 MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, I) 934 934 end; 935 935 936 936 procedure AddStandardBlock(Item: string); 937 937 var 938 i: integer;938 I: Integer; 939 939 begin 940 940 with MainText do … … 947 947 else if Item = 'TECHFORMULA' then 948 948 begin 949 i:= Difficulty;950 if i= 0 then951 i:= 2;952 AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[ i],953 TechFormula_D[ i]]))949 I := Difficulty; 950 if I = 0 then 951 I := 2; 952 AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[I], 953 TechFormula_D[I]])) 954 954 end 955 955 else if Item = 'EXPERIENCE' then 956 for i:= 0 to nExp - 1 do957 AddLine(Phrases.Lookup('EXPERIENCE', i), pkExp, i)956 for I := 0 to nExp - 1 do 957 AddLine(Phrases.Lookup('EXPERIENCE', I), pkExp, I) 958 958 else if Item = 'MODERN' then 959 for i:= 1 to 3 do959 for I := 1 to 3 do 960 960 begin 961 961 LineFeed; 962 AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + i), pkTer, 3 * 12 + i);962 AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + I), pkTer, 3 * 12 + I); 963 963 end 964 964 else if Item = 'SAVED' then 965 965 AddLine(DataDir + 'Saved', pkNormal) 966 966 else if Item = 'AITSTAT' then 967 for i:= 0 to 3 do968 AddLine(Phrases2.Lookup('AITSTAT', i), pkAITStat, i)967 for I := 0 to 3 do 968 AddLine(Phrases2.Lookup('AITSTAT', I), pkAITStat, I) 969 969 end 970 970 end; 971 971 972 procedure DecodeItem( s: string; var Category, Index: Integer);972 procedure DecodeItem(S: string; var Category, Index: Integer); 973 973 var 974 i: Integer;975 begin 976 if (Length( s) > 0) and (s[1] = ':') then begin974 I: Integer; 975 begin 976 if (Length(S) > 0) and (S[1] = ':') then begin 977 977 Category := hkMisc; 978 978 Index := 0; 979 for i := 3 to length(s) do980 Index := Index * 10 + Ord( s[i]) - 48;981 case s[2] of979 for I := 3 to Length(S) do 980 Index := Index * 10 + Ord(S[I]) - 48; 981 case S[2] of 982 982 'A': Category := hkAdv; 983 983 'B': Category := hkImp; … … 994 994 end else begin 995 995 Category := hkText; 996 Index := HelpText.Gethandle(Copy( s, 1, 255));996 Index := HelpText.Gethandle(Copy(S, 1, 255)); 997 997 end; 998 998 end; 999 999 1000 procedure AddTextual( s: string);1000 procedure AddTextual(S: string); 1001 1001 var 1002 i: Integer;1003 p: Integer;1004 l: Integer;1002 I: Integer; 1003 P: Integer; 1004 L: Integer; 1005 1005 ofs: Integer; 1006 1006 CurrentFormat: Integer; … … 1015 1015 RightMargin := InnerWidth - 16 - GetSystemMetrics(SM_CXVSCROLL); 1016 1016 FollowFormat := pkNormal; 1017 while s<> '' do1017 while S <> '' do 1018 1018 begin 1019 1019 Picpix := 0; 1020 1020 LinkCategory := 0; 1021 1021 LinkIndex := 0; 1022 if s[1] = '$' then1022 if S[1] = '$' then 1023 1023 begin // window caption 1024 p:= 1;1024 P := 1; 1025 1025 repeat 1026 inc(p)1027 until ( p > Length(s)) or (s[p] = '\');1028 Caption := Copy( s, 2, p- 2);1029 Delete( s, 1, p);1026 Inc(P); 1027 until (P > Length(S)) or (S[P] = '\'); 1028 Caption := Copy(S, 2, P - 2); 1029 Delete(S, 1, P); 1030 1030 end 1031 else if s[1] = '&' then1031 else if S[1] = '&' then 1032 1032 begin // standard block 1033 p:= 1;1033 P := 1; 1034 1034 repeat 1035 inc(p)1036 until ( p > Length(s)) or (s[p] = '\');1037 AddStandardBlock(Copy( s, 2, p- 2));1038 Delete( s, 1, p);1035 Inc(P); 1036 until (P > Length(S)) or (S[P] = '\'); 1037 AddStandardBlock(Copy(S, 2, P - 2)); 1038 Delete(S, 1, P); 1039 1039 end 1040 else if s[1] = '@' then1040 else if S[1] = '@' then 1041 1041 begin // image 1042 if (Length( s) >= 2) and (s[2] = '@') then1042 if (Length(S) >= 2) and (S[2] = '@') then 1043 1043 begin // generate from icon 1044 1044 Picpix := 0; 1045 p:= 3;1046 while ( p <= Length(s)) and (s[p] <> '\') do1045 P := 3; 1046 while (P <= Length(S)) and (S[P] <> '\') do 1047 1047 begin 1048 Picpix := Picpix * 10 + Ord( s[p]) - 48;1049 inc(p)1048 Picpix := Picpix * 10 + Ord(S[P]) - 48; 1049 Inc(P); 1050 1050 end; 1051 1051 if (Picpix < 0) or (Picpix >= nImp) then … … 1057 1057 else 1058 1058 begin // external image 1059 p:= 1;1059 P := 1; 1060 1060 repeat 1061 Inc( p)1062 until ( p > Length(s)) or (s[p] = '\');1061 Inc(P); 1062 until (P > Length(S)) or (S[P] = '\'); 1063 1063 if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' + 1064 DirectorySeparator + Copy( s, 2, p- 2)) + '.png') then1064 DirectorySeparator + Copy(S, 2, P - 2)) + '.png') then 1065 1065 begin 1066 1066 MainText.AddLine('', pkExternal); 1067 for i:= 0 to (ExtPic.Height - 12) div 24 do1067 for I := 0 to (ExtPic.Height - 12) div 24 do 1068 1068 MainText.LineFeed; 1069 1069 end; 1070 1070 end; 1071 Delete( s, 1, p);1071 Delete(S, 1, P); 1072 1072 end 1073 1073 else 1074 1074 begin 1075 case s[1] of1075 case S[1] of 1076 1076 ':', ';': 1077 1077 begin // link 1078 p:= 1;1078 P := 1; 1079 1079 repeat 1080 inc(p)1081 until ( p > Length(s)) or (s[p] = '\') or (s[p] = ' ');1082 DecodeItem(Copy( s, 2, p- 2), LinkCategory, LinkIndex);1080 Inc(P) 1081 until (P > Length(S)) or (S[P] = '\') or (S[P] = ' '); 1082 DecodeItem(Copy(S, 2, P - 2), LinkCategory, LinkIndex); 1083 1083 CurrentFormat := 0; 1084 1084 if (LinkCategory <> hkText) and (LinkIndex < 200) then … … 1112 1112 end; 1113 1113 end; 1114 if s[1] = ':' then1114 if S[1] = ':' then 1115 1115 LinkCategory := LinkCategory + hkCrossLink; 1116 if ( p > Length(s)) or (s[p] = ' ') then1117 Delete( s, 1, p)1116 if (P > Length(S)) or (S[P] = ' ') then 1117 Delete(S, 1, P) 1118 1118 else 1119 Delete( s, 1, p- 1)1119 Delete(S, 1, P - 1) 1120 1120 end; 1121 1121 '!': // highlited 1122 if (Length( s) >= 2) and (s[2] = '!') then1122 if (Length(S) >= 2) and (S[2] = '!') then 1123 1123 begin 1124 1124 if MainText.Count > 1 then … … 1126 1126 FollowFormat := pkCaption; 1127 1127 CurrentFormat := pkCaption; 1128 Delete( s, 1, 2);1128 Delete(S, 1, 2); 1129 1129 end 1130 1130 else … … 1132 1132 FollowFormat := pkSection; 1133 1133 CurrentFormat := pkSection; 1134 Delete( s, 1, 1);1134 Delete(S, 1, 1); 1135 1135 end; 1136 1136 '-': … … 1138 1138 FollowFormat := pkNormal_Dot; 1139 1139 CurrentFormat := pkDot; 1140 Delete( s, 1, 1);1140 Delete(S, 1, 1); 1141 1141 end; 1142 1142 else … … 1147 1147 else 1148 1148 ofs := 8; 1149 p:= 0;1149 P := 0; 1150 1150 repeat 1151 1151 repeat 1152 Inc( p)1153 until ( p > Length(s)) or (s[p] = ' ') or (s[p] = '\');1154 if (BiColorTextWidth(OffScreen.Canvas, Copy( s, 1, p- 1)) <=1152 Inc(P) 1153 until (P > Length(S)) or (S[P] = ' ') or (S[P] = '\'); 1154 if (BiColorTextWidth(OffScreen.Canvas, Copy(S, 1, P - 1)) <= 1155 1155 RightMargin - ofs) then 1156 l := p- 11156 L := P - 1 1157 1157 else 1158 1158 Break; 1159 until ( p >= Length(s)) or (s[l+ 1] = '\');1160 Text := Copy( s, 1, l);1161 if LinkCategory and $3 f= hkInternet then begin1159 until (P >= Length(S)) or (S[L + 1] = '\'); 1160 Text := Copy(S, 1, L); 1161 if LinkCategory and $3F = hkInternet then begin 1162 1162 if LinkIndex = 1 then Text := AITemplateManual 1163 1163 else if LinkIndex = 2 then Text := CevoHomepageShort … … 1166 1166 MainText.AddLine(Text, CurrentFormat, Picpix, LinkCategory, 1167 1167 LinkIndex); 1168 if ( l < Length(s)) and (s[l+ 1] = '\') then1168 if (L < Length(S)) and (S[L + 1] = '\') then 1169 1169 FollowFormat := pkNormal; 1170 Delete( s, 1, l+ 1);1170 Delete(S, 1, L + 1); 1171 1171 end 1172 1172 end … … 1178 1178 end; 1179 1179 1180 procedure AddModelText( i: Integer);1180 procedure AddModelText(I: Integer); 1181 1181 var 1182 1182 pix: Integer; 1183 s: string;1183 S: string; 1184 1184 begin 1185 1185 with MainText do begin … … 1188 1188 LineFeed; 1189 1189 end; 1190 FindStdModelPicture(SpecialModelPictureCode[ i], pix, s);1191 AddLine( s, pkSection);1192 AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[ i].Attack,1193 SpecialModel[ i].Defense]), pkNormal_64);1190 FindStdModelPicture(SpecialModelPictureCode[I], pix, S); 1191 AddLine(S, pkSection); 1192 AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[I].Attack, 1193 SpecialModel[I].Defense]), pkNormal_64); 1194 1194 AddLine(Format(HelpText.Lookup('SPEED'), 1195 [MovementToString(SpecialModel[ i].Speed)]), pkModel, pix);1195 [MovementToString(SpecialModel[I].Speed)]), pkModel, pix); 1196 1196 if Difficulty = 0 then 1197 AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[ i].Cost]),1197 AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[I].Cost]), 1198 1198 pkNormal_64) 1199 1199 else 1200 1200 AddLine(Format(HelpText.Lookup('BUILDCOST'), 1201 [SpecialModel[ i].Cost * BuildCostMod[Difficulty] div 12]),1201 [SpecialModel[I].Cost * BuildCostMod[Difficulty] div 12]), 1202 1202 pkNormal_64); 1203 s := HelpText.LookupByHandle(hSPECIALMODEL, i);1204 if ( s <> '') and (s<> '*') then1205 AddTextual( s);1206 if SpecialModelPreq[ i] >= 0 then1207 AddPreqAdv(SpecialModelPreq[ i])1208 else if SpecialModelPreq[ i] = preLighthouse then1203 S := HelpText.LookupByHandle(hSPECIALMODEL, I); 1204 if (S <> '') and (S <> '*') then 1205 AddTextual(S); 1206 if SpecialModelPreq[I] >= 0 then 1207 AddPreqAdv(SpecialModelPreq[I]) 1208 else if SpecialModelPreq[I] = preLighthouse then 1209 1209 AddPreqImp(woLighthouse) 1210 else if SpecialModelPreq[ i] = preBuilder then1210 else if SpecialModelPreq[I] = preBuilder then 1211 1211 AddPreqImp(woPyramids) 1212 else if SpecialModelPreq[ i] = preLeo then1212 else if SpecialModelPreq[I] = preLeo then 1213 1213 AddPreqImp(woLeo); 1214 if SpecialModelPreq[ i] <> preNone then1214 if SpecialModelPreq[I] <> preNone then 1215 1215 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1216 1216 [MainText[Count - 1]]); … … 1220 1220 procedure AddJobList; 1221 1221 var 1222 i, JobCost: Integer;1222 I, JobCost: Integer; 1223 1223 begin 1224 1224 with MainText do begin 1225 for i:= 0 to nJobHelp - 1 do begin1226 if i> 0 then begin1225 for I := 0 to nJobHelp - 1 do begin 1226 if I > 0 then begin 1227 1227 LineFeed; 1228 1228 LineFeed; 1229 1229 end; 1230 AddLine(Phrases.Lookup('JOBRESULT', JobHelp[ i]), pkSection);1230 AddLine(Phrases.Lookup('JOBRESULT', JobHelp[I]), pkSection); 1231 1231 AddLine; 1232 AddLine('', pkTerImp, i);1232 AddLine('', pkTerImp, I); 1233 1233 AddLine; 1234 AddTextual(HelpText.LookupByHandle(hJOBHELP, i));1234 AddTextual(HelpText.LookupByHandle(hJOBHELP, I)); 1235 1235 JobCost := -1; 1236 case JobHelp[ i] of1236 case JobHelp[I] of 1237 1237 jCanal: JobCost := CanalWork; 1238 1238 jFort: JobCost := FortWork; … … 1244 1244 else 1245 1245 AddTextual(HelpText.Lookup('JOBCOSTVAR')); 1246 if JobPreq[JobHelp[ i]] <> preNone then begin1247 AddPreqAdv(JobPreq[JobHelp[ i]]);1246 if JobPreq[JobHelp[I]] <> preNone then begin 1247 AddPreqAdv(JobPreq[JobHelp[I]]); 1248 1248 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1249 1249 [MainText[Count - 1]]); … … 1255 1255 procedure AddGraphicCredits; 1256 1256 var 1257 i: Integer;1258 s: string;1257 I: Integer; 1258 S: string; 1259 1259 sr: TSearchRec; 1260 1260 List, Plus: TStringList; … … 1271 1271 1272 1272 List.Sort; 1273 i:= 1;1274 while i< List.Count do1275 if List[ i] = List[i- 1] then1276 List.Delete( i)1273 I := 1; 1274 while I < List.Count do 1275 if List[I] = List[I - 1] then 1276 List.Delete(I) 1277 1277 else 1278 Inc( i);1279 1280 for i:= 0 to List.Count - 1 do begin1281 s := List[i];1282 while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -1278 Inc(I); 1279 1280 for I := 0 to List.Count - 1 do begin 1281 S := List[I]; 1282 while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 - 1283 1283 GetSystemMetrics(SM_CXVSCROLL) do 1284 Delete( s, length(s), 1);1285 MainText.AddLine( s);1284 Delete(S, Length(S), 1); 1285 MainText.AddLine(S); 1286 1286 end; 1287 1287 FreeAndNil(List); … … 1290 1290 procedure AddSoundCredits; 1291 1291 var 1292 i: Integer;1293 s: string;1292 I: Integer; 1293 S: string; 1294 1294 List: TStringList; 1295 1295 begin 1296 1296 List := TStringList.Create; 1297 1297 List.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.credits.txt'); 1298 for i:= 0 to List.Count - 1 do begin1299 s := List[i];1300 while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -1298 for I := 0 to List.Count - 1 do begin 1299 S := List[I]; 1300 while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 - 1301 1301 GetSystemMetrics(SM_CXVSCROLL) do 1302 Delete( s, length(s), 1);1303 MainText.AddLine( s);1302 Delete(S, Length(S), 1); 1303 MainText.AddLine(S); 1304 1304 end; 1305 1305 FreeAndNil(List); … … 1349 1349 hkAdv, 200); 1350 1350 LineFeed; 1351 FindStdModelPicture(SpecialModelPictureCode[6], i, s);1352 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, i,1351 FindStdModelPicture(SpecialModelPictureCode[6], I, S); 1352 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, I, 1353 1353 hkModel, 0); 1354 1354 LineFeed; … … 1402 1402 begin 1403 1403 Caption := HelpText.Lookup('HELPTITLE_GOVLIST'); 1404 for i:= 1 to nGov do1404 for I := 1 to nGov do 1405 1405 begin 1406 AddLine(Phrases.Lookup('GOVERNMENT', imod nGov), pkSection);1406 AddLine(Phrases.Lookup('GOVERNMENT', I mod nGov), pkSection); 1407 1407 LineFeed; 1408 if i= nGov then1408 if I = nGov then 1409 1409 AddLine('', pkBigIcon, 7 * SystemIconLines + imPalace) 1410 1410 else 1411 AddLine('', pkBigIcon, i+ 6);1411 AddLine('', pkBigIcon, I + 6); 1412 1412 LineFeed; 1413 AddTextual(HelpText.LookupByHandle(hGOVHELP, imod nGov));1414 if imod nGov >= 2 then1413 AddTextual(HelpText.LookupByHandle(hGOVHELP, I mod nGov)); 1414 if I mod nGov >= 2 then 1415 1415 begin 1416 AddPreqAdv(GovPreq[ imod nGov]);1416 AddPreqAdv(GovPreq[I mod nGov]); 1417 1417 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1418 1418 [MainText[Count - 1]]); 1419 1419 end; 1420 if i< nGov then1420 if I < nGov then 1421 1421 begin 1422 1422 LineFeed; … … 1440 1440 List := THyperText.Create; 1441 1441 List.OwnsObjects := True; 1442 for j:= 0 to 3 do1442 for J := 0 to 3 do 1443 1443 begin 1444 if j> 0 then1444 if J > 0 then 1445 1445 begin 1446 1446 LineFeed; 1447 1447 LineFeed; 1448 1448 end; 1449 AddLine(HelpText.Lookup('TECHAGE', j), pkSection);1450 if j= 1 then1449 AddLine(HelpText.Lookup('TECHAGE', J), pkSection); 1450 if J = 1 then 1451 1451 AddLine(Phrases.Lookup('ADVANCES', adScience) + ' ' + 1452 1452 HelpText.Lookup('BASETECH'), pkAdvIcon, adScience, hkAdv, 1453 1453 adScience); 1454 if j= 2 then1454 if J = 2 then 1455 1455 AddLine(Phrases.Lookup('ADVANCES', adMassProduction) + ' ' + 1456 1456 HelpText.Lookup('BASETECH'), pkAdvIcon, adMassProduction, hkAdv, 1457 1457 adMassProduction); 1458 1458 List.Clear; 1459 for i:= 0 to nAdv - 1 do1460 if ( i <> adScience) and (i<> adMassProduction) and1461 (AdvValue[ i] div 1000 = j) then1462 List.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,1463 hkAdv, i);1459 for I := 0 to nAdv - 1 do 1460 if (I <> adScience) and (I <> adMassProduction) and 1461 (AdvValue[I] div 1000 = J) then 1462 List.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I, 1463 hkAdv, I); 1464 1464 List.Sort; 1465 1465 AppendList(List); … … 1487 1487 else 1488 1488 NextSection('PREREQ'); 1489 for i:= 0 to 2 do1490 if AdvPreq[no, i] <> preNone then1491 AddPreqAdv(AdvPreq[no, i]);1489 for I := 0 to 2 do 1490 if AdvPreq[no, I] <> preNone then 1491 AddPreqAdv(AdvPreq[no, I]); 1492 1492 NextSection('GOVALLOW'); 1493 for i:= 2 to nGov - 1 do1494 if GovPreq[ i] = no then1495 AddLine(Phrases.Lookup('GOVERNMENT', i), pkGov, i,1493 for I := 2 to nGov - 1 do 1494 if GovPreq[I] = no then 1495 AddLine(Phrases.Lookup('GOVERNMENT', I), pkGov, I, 1496 1496 hkMisc + hkCrossLink, miscGovList); 1497 1497 NextSection('BUILDALLOW'); 1498 for i:= 0 to nWonder - 1 do1499 if Imp[ i].Preq = no then1500 AddImprovement( i);1501 for i:= nWonder to nImp - 1 do1502 if (Imp[ i].Preq = no) and (Imp[i].Kind <> ikCommon) then1503 AddImprovement( i);1504 for i:= nWonder to nImp - 1 do1505 if (Imp[ i].Preq = no) and (Imp[i].Kind = ikCommon) then1506 AddImprovement( i);1498 for I := 0 to nWonder - 1 do 1499 if Imp[I].Preq = no then 1500 AddImprovement(I); 1501 for I := nWonder to nImp - 1 do 1502 if (Imp[I].Preq = no) and (Imp[I].Kind <> ikCommon) then 1503 AddImprovement(I); 1504 for I := nWonder to nImp - 1 do 1505 if (Imp[I].Preq = no) and (Imp[I].Kind = ikCommon) then 1506 AddImprovement(I); 1507 1507 NextSection('MODELALLOW'); 1508 for i:= 0 to nSpecialModel - 1 do1509 if SpecialModelPreq[ i] = no then1510 AddModel( i);1508 for I := 0 to nSpecialModel - 1 do 1509 if SpecialModelPreq[I] = no then 1510 AddModel(I); 1511 1511 NextSection('FEATALLOW'); 1512 for i:= 0 to nFeature - 1 do1513 if Feature[ i].Preq = no then1514 AddFeature( i);1512 for I := 0 to nFeature - 1 do 1513 if Feature[I].Preq = no then 1514 AddFeature(I); 1515 1515 NextSection('FOLLOWADV'); 1516 for i:= 0 to nAdv - 1 do1517 if (AdvPreq[ i, 0] = no) or (AdvPreq[i, 1] = no) or1518 (AdvPreq[ i, 2] = no) then1519 AddAdvance( i);1516 for I := 0 to nAdv - 1 do 1517 if (AdvPreq[I, 0] = no) or (AdvPreq[I, 1] = no) or 1518 (AdvPreq[I, 2] = no) then 1519 AddAdvance(I); 1520 1520 NextSection('UPGRADEALLOW'); 1521 1521 for Domain := 0 to nDomains - 1 do 1522 for i:= 1 to nUpgrade - 1 do1523 if upgrade[Domain, i].Preq = no then1522 for I := 1 to nUpgrade - 1 do 1523 if upgrade[Domain, I].Preq = no then 1524 1524 begin 1525 if upgrade[Domain, i].Strength > 0 then1525 if upgrade[Domain, I].Strength > 0 then 1526 1526 AddLine(Format(HelpText.Lookup('STRENGTHUP'), 1527 1527 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, 1528 i].Strength]), pkDomain, Domain);1529 if upgrade[Domain, i].Trans > 0 then1528 I].Strength]), pkDomain, Domain); 1529 if upgrade[Domain, I].Trans > 0 then 1530 1530 AddLine(Format(HelpText.Lookup('TRANSUP'), 1531 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, i].Trans]1531 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, I].Trans] 1532 1532 ), pkDomain, Domain); 1533 1533 if no in FutureTech then 1534 1534 AddLine(Format(HelpText.Lookup('COSTUP'), 1535 [upgrade[Domain, i].Cost]), pkNormal_Dot)1535 [upgrade[Domain, I].Cost]), pkNormal_Dot) 1536 1536 else 1537 1537 AddLine(Format(HelpText.Lookup('COSTMIN'), 1538 [upgrade[Domain, i].Cost]), pkNormal_Dot)1538 [upgrade[Domain, I].Cost]), pkNormal_Dot) 1539 1539 end; 1540 1540 NextSection('EXPIRATION'); 1541 for i:= 0 to nWonder - 1 do1542 if (Imp[ i].Preq <> preNA) and (Imp[i].Expiration = no) then1543 AddImprovement( i);1541 for I := 0 to nWonder - 1 do 1542 if (Imp[I].Preq <> preNA) and (Imp[I].Expiration = no) then 1543 AddImprovement(I); 1544 1544 NextSection('ADVEFFECT'); 1545 s:= HelpText.LookupByHandle(hADVHELP, no);1546 if s<> '*' then1547 AddTextual( s);1545 S := HelpText.LookupByHandle(hADVHELP, no); 1546 if S <> '*' then 1547 AddTextual(S); 1548 1548 NextSection('SEEALSO'); 1549 CheckSeeAlso := true1549 CheckSeeAlso := True 1550 1550 end; 1551 1551 … … 1557 1557 List := THyperText.Create; 1558 1558 List.OwnsObjects := True; 1559 for i:= nWonder to nImp - 1 do1560 if ( i <> imTrGoods) and (Imp[i].Preq <> preNA) and1561 (Imp[ i].Kind = ikCommon) then1562 List.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon,1563 i, hkImp, i);1559 for I := nWonder to nImp - 1 do 1560 if (I <> imTrGoods) and (Imp[I].Preq <> preNA) and 1561 (Imp[I].Kind = ikCommon) then 1562 List.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, 1563 I, hkImp, I); 1564 1564 List.Sort; 1565 1565 AppendList(List); … … 1570 1570 Caption := HelpText.Lookup('HELPTITLE_UNIQUELIST'); 1571 1571 // AddLine(HelpText.Lookup('HELPTITLE_UNIQUELIST'),pkSection); 1572 for i:= nWonder to nImp - 1 do1573 if (Imp[ i].Preq <> preNA) and1574 ((Imp[ i].Kind = ikNatLocal) or (Imp[i].Kind = ikNatGlobal)) then1575 AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,1576 hkImp, i);1572 for I := nWonder to nImp - 1 do 1573 if (Imp[I].Preq <> preNA) and 1574 ((Imp[I].Kind = ikNatLocal) or (Imp[I].Kind = ikNatGlobal)) then 1575 AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 1576 hkImp, I); 1577 1577 { LineFeed; 1578 1578 LineFeed; 1579 1579 AddLine(HelpText.Lookup('HELPTITLE_SHIPPARTLIST'),pkSection); 1580 for i:= nWonder to nImp-1 do1581 if (Imp[ i].Preq<>preNA) and (Imp[i].Kind=ikShipPart) then1582 AddLine(Phrases.Lookup('IMPROVEMENTS', i),pkSmallIcon,i,hkImp,i); }1580 for I:= nWonder to nImp-1 do 1581 if (Imp[I].Preq<>preNA) and (Imp[I].Kind=ikShipPart) then 1582 AddLine(Phrases.Lookup('IMPROVEMENTS',I),pkSmallIcon,I,hkImp,I); } 1583 1583 end 1584 1584 else if no = 202 then … … 1586 1586 Caption := HelpText.Lookup('HELPTITLE_WONDERLIST'); 1587 1587 // AddLine(HelpText.Lookup('HELPTITLE_WONDERLIST'),pkSection); 1588 for i:= 0 to nWonder - 1 do1589 if Imp[ i].Preq <> preNA then1590 AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,1591 hkImp, i);1588 for I := 0 to nWonder - 1 do 1589 if Imp[I].Preq <> preNA then 1590 AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 1591 hkImp, I); 1592 1592 end 1593 1593 else … … 1627 1627 NextSection('COSTS'); 1628 1628 if Difficulty = 0 then 1629 s:= Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])1629 S := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost]) 1630 1630 else 1631 s:= Format(HelpText.Lookup('BUILDCOST'),1631 S := Format(HelpText.Lookup('BUILDCOST'), 1632 1632 [Imp[no].Cost * BuildCostMod[Difficulty] div 12]); 1633 AddLine( s);1633 AddLine(S); 1634 1634 if Imp[no].Maint > 0 then 1635 1635 AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[no].Maint])); 1636 j:= 0;1637 for i:= 0 to nImpReplacement - 1 do1638 if ImpReplacement[ i].NewImp = no then1639 begin 1640 if j= 0 then1636 J := 0; 1637 for I := 0 to nImpReplacement - 1 do 1638 if ImpReplacement[I].NewImp = no then 1639 begin 1640 if J = 0 then 1641 1641 begin 1642 1642 NextSection('REPLACE'); 1643 1643 AddItem('REPLACETEXT'); 1644 j:= 1;1644 J := 1; 1645 1645 end; 1646 AddImprovement(ImpReplacement[ i].OldImp);1646 AddImprovement(ImpReplacement[I].OldImp); 1647 1647 end; 1648 1648 if Imp[no].Kind = ikShipPart then … … 1650 1650 LineFeed; 1651 1651 if no = imShipComp then 1652 i:= 11652 I := 1 1653 1653 else if no = imShipPow then 1654 i:= 21654 I := 2 1655 1655 else { if no=imShipHab then } 1656 i:= 3;1656 I := 3; 1657 1657 AddLine(Format(HelpText.Lookup('RAREREQUIRED'), 1658 [Phrases.Lookup('TERRAIN', 3 * 12 + i)]), pkTer, 3 * 12 + i);1658 [Phrases.Lookup('TERRAIN', 3 * 12 + I)]), pkTer, 3 * 12 + I); 1659 1659 end; 1660 1660 if (no < nWonder) and (Imp[no].Expiration >= 0) then 1661 1661 begin 1662 1662 NextSection('EXPIRATION'); 1663 s:= Format(HelpText.Lookup('EXPWITH'),1663 S := Format(HelpText.Lookup('EXPWITH'), 1664 1664 [Phrases.Lookup('ADVANCES', Imp[no].Expiration)]); 1665 1665 if no = woPyramids then 1666 s := s+ ' ' + HelpText.Lookup('EXPSLAVE');1667 AddTextual( s);1666 S := S + ' ' + HelpText.Lookup('EXPSLAVE'); 1667 AddTextual(S); 1668 1668 end; 1669 1669 NextSection('SEEALSO'); 1670 1670 if (no < nWonder) and (Imp[no].Expiration >= 0) then 1671 1671 AddImprovement(woEiffel); 1672 for i:= 0 to nImpReplacement - 1 do1673 if ImpReplacement[ i].OldImp = no then1674 AddImprovement(ImpReplacement[ i].NewImp);1672 for I := 0 to nImpReplacement - 1 do 1673 if ImpReplacement[I].OldImp = no then 1674 AddImprovement(ImpReplacement[I].NewImp); 1675 1675 if no = imSupermarket then 1676 1676 AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0, 1677 1677 hkMisc + hkCrossLink, miscJobList); 1678 CheckSeeAlso := true;1678 CheckSeeAlso := True; 1679 1679 end; 1680 1680 … … 1684 1684 Caption := HelpText.Lookup('HELPTITLE_TERLIST'); 1685 1685 // AddLine(HelpText.Lookup('HELPTITLE_TERLIST'),pkSection); 1686 for i:= 0 to nTerrainHelp - 1 do1687 AddTerrain(TerrainHelp[ i]);1686 for I := 0 to nTerrainHelp - 1 do 1687 AddTerrain(TerrainHelp[I]); 1688 1688 end 1689 1689 else … … 1746 1746 begin 1747 1747 LineFeed; 1748 i:= TransTerrain;1749 if (TerrType <> fGrass) and ( i<> fGrass) then1750 i := i+ TerrSubType * 12;1748 I := TransTerrain; 1749 if (TerrType <> fGrass) and (I <> fGrass) then 1750 I := I + TerrSubType * 12; 1751 1751 // trafo to same Special resource group 1752 1752 AddLine(Format(HelpText.Lookup('TRAFO'), 1753 [Phrases.Lookup('TERRAIN', i)]), pkTer, i,1754 hkTer + hkCrossLink, i);1753 [Phrases.Lookup('TERRAIN', I)]), pkTer, I, 1754 hkTer + hkCrossLink, I); 1755 1755 if no = fSwamp + 12 then 1756 1756 begin … … 1760 1760 TransTerrain + 24, hkTer + hkCrossLink, TransTerrain + 24); 1761 1761 end 1762 else if i= fGrass then1762 else if I = fGrass then 1763 1763 begin 1764 1764 LineFeed; … … 1790 1790 AddLine(Phrases.Lookup('TERRAIN', no + Special * 12), pkTer, 1791 1791 no + Special * 12); 1792 i:= FoodRes[Special] - FoodRes[0];1793 if i<> 0 then1792 I := FoodRes[Special] - FoodRes[0]; 1793 if I <> 0 then 1794 1794 MainText[Count - 1] := MainText[Count - 1] + 1795 Format(HelpText.Lookup('SPECIALFOOD'), [ i]);1796 i:= ProdRes[Special] - ProdRes[0];1797 if i<> 0 then1795 Format(HelpText.Lookup('SPECIALFOOD'), [I]); 1796 I := ProdRes[Special] - ProdRes[0]; 1797 if I <> 0 then 1798 1798 MainText[Count - 1] := MainText[Count - 1] + 1799 Format(HelpText.Lookup('SPECIALPROD'), [ i]);1800 i:= TradeRes[Special] - TradeRes[0];1801 if i<> 0 then1799 Format(HelpText.Lookup('SPECIALPROD'), [I]); 1800 I := TradeRes[Special] - TradeRes[0]; 1801 if I <> 0 then 1802 1802 MainText[Count - 1] := MainText[Count - 1] + 1803 Format(HelpText.Lookup('SPECIALTRADE'), [ i]);1803 Format(HelpText.Lookup('SPECIALTRADE'), [I]); 1804 1804 end; 1805 1805 end; … … 1813 1813 NextSection('SEEALSO'); 1814 1814 AddImprovement(woGardens); 1815 CheckSeeAlso := true1815 CheckSeeAlso := True 1816 1816 end; 1817 1817 end; … … 1837 1837 end; 1838 1838 List.Clear; 1839 for i:= 0 to nFeature - 1 do1840 if Feature[ i].Preq <> preNA then1839 for I := 0 to nFeature - 1 do 1840 if Feature[I].Preq <> preNA then 1841 1841 begin 1842 if i< mcFirstNonCap then1843 j:= 01844 else if iin AutoFeature then1845 j:= 21842 if I < mcFirstNonCap then 1843 J := 0 1844 else if I in AutoFeature then 1845 J := 2 1846 1846 else 1847 j:= 1;1848 if j= Special then1849 List.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,1850 hkFeature, i);1847 J := 1; 1848 if J = Special then 1849 List.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I, 1850 hkFeature, I); 1851 1851 end; 1852 1852 List.Sort; … … 1871 1871 begin 1872 1872 NextSection('COSTS'); 1873 s:= IntToStr(Feature[no].Cost);1873 S := IntToStr(Feature[no].Cost); 1874 1874 if Feature[no].Cost >= 0 then 1875 s := '+' + s;1876 AddLine(Format(HelpText.Lookup('COSTBASE'), [ s]));1875 S := '+' + S; 1876 AddLine(Format(HelpText.Lookup('COSTBASE'), [S])); 1877 1877 if Feature[no].Weight > 0 then 1878 1878 begin … … 1901 1901 begin 1902 1902 Caption := HelpText.Lookup('HELPTITLE_MODELLIST'); 1903 for i:= 0 to nSpecialModel - 1 do1904 if i<> 2 then1905 AddModelText( i);1903 for I := 0 to nSpecialModel - 1 do 1904 if I <> 2 then 1905 AddModelText(I); 1906 1906 LineFeed; 1907 1907 AddItem('MODELNOTE'); … … 1910 1910 end; 1911 1911 if CheckSeeAlso then 1912 for i:= 0 to nSeeAlso - 1 do1913 if (SeeAlso[ i].Kind = Kind) and (SeeAlso[i].no = no) then1914 case SeeAlso[ i].SeeKind of1915 hkImp: AddImprovement(SeeAlso[ i].SeeNo);1916 hkAdv: AddAdvance(SeeAlso[ i].SeeNo);1917 hkFeature: AddFeature(SeeAlso[ i].SeeNo);1912 for I := 0 to nSeeAlso - 1 do 1913 if (SeeAlso[I].Kind = Kind) and (SeeAlso[I].no = no) then 1914 case SeeAlso[I].SeeKind of 1915 hkImp: AddImprovement(SeeAlso[I].SeeNo); 1916 hkAdv: AddAdvance(SeeAlso[I].SeeNo); 1917 hkFeature: AddFeature(SeeAlso[I].SeeNo); 1918 1918 end; 1919 1919 if (Headline >= 0) and (Count = Headline + 1) then … … 1949 1949 1950 1950 procedure THelpDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 1951 x, y: integer);1951 X, Y: Integer); 1952 1952 var 1953 1953 i0, Sel0: Integer; 1954 1954 begin 1955 y := y- WideFrame;1955 Y := Y - WideFrame; 1956 1956 i0 := ScrollBar.Position; 1957 1957 Sel0 := Sel; 1958 if ( x >= SideFrame) and (x < SideFrame + InnerWidth) and (y>= 0) and1959 ( y < InnerHeight) and (ymod 24 >= 8) then1960 Sel := ydiv 241958 if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and 1959 (Y < InnerHeight) and (Y mod 24 >= 8) then 1960 Sel := Y div 24 1961 1961 else 1962 1962 Sel := -1; … … 1974 1974 1975 1975 procedure THelpDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 1976 Shift: TShiftState; x, y: integer);1976 Shift: TShiftState; X, Y: Integer); 1977 1977 begin 1978 1978 if Sel >= 0 then … … 1987 1987 begin 1988 1988 if (Link >= $8000) and (Link and $3FFF = liInvalid) then 1989 exit; // invalid link;1989 Exit; // invalid link; 1990 1990 if Link >= $8000 then 1991 1991 ShowNewContent(FWindowMode, hkText, Link and $3FFF) … … 2079 2079 procedure THelpDlg.Search(SearchString: string); 2080 2080 var 2081 h, i, PrevHandle, PrevIndex, p, RightMargin: Integer;2082 s: string;2081 H, I, PrevHandle, PrevIndex, P, RightMargin: Integer; 2082 S: string; 2083 2083 mADVHELP, mIMPHELP, mFEATUREHELP: set of 0 .. 255; 2084 2084 bGOVHELP, bSPECIALMODEL, bJOBHELP: Boolean; … … 2094 2094 // search in generic reference 2095 2095 SearchString := UpperCase(SearchString); 2096 for i:= 0 to 35 + 4 do begin2097 s := Phrases.Lookup('TERRAIN', i);2098 if pos(SearchString, UpperCase(s)) > 0 then2099 if i< 36 then2100 SearchResult.AddLine( s+ ' ' + HelpText.Lookup('HELPSPEC_TER'),2101 pkNormal, 0, hkTer + hkCrossLink, i)2096 for I := 0 to 35 + 4 do begin 2097 S := Phrases.Lookup('TERRAIN', I); 2098 if Pos(SearchString, UpperCase(S)) > 0 then 2099 if I < 36 then 2100 SearchResult.AddLine(S + ' ' + HelpText.Lookup('HELPSPEC_TER'), 2101 pkNormal, 0, hkTer + hkCrossLink, I) 2102 2102 else 2103 2103 begin … … 2105 2105 HelpText.Lookup('HELPSPEC_TER'), pkNormal, 0, 2106 2106 hkTer + hkCrossLink, 36); 2107 if i> 36 then2107 if I > 36 then 2108 2108 SearchResult.AddLine(Phrases.Lookup('IMPROVEMENTS', 2109 imShipComp + i- 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),2110 pkNormal, 0, hkImp + hkCrossLink, imShipComp + i- 37);2109 imShipComp + I - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'), 2110 pkNormal, 0, hkImp + hkCrossLink, imShipComp + I - 37); 2111 2111 Break; 2112 2112 end; 2113 2113 end; 2114 for i:= 0 to nJobHelp - 1 do2115 if pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[i]))) > 02114 for I := 0 to nJobHelp - 1 do 2115 if Pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[I]))) > 0 2116 2116 then 2117 2117 begin … … 2121 2121 Break; 2122 2122 end; 2123 for i:= 0 to nAdv - 1 do2124 begin 2125 s := Phrases.Lookup('ADVANCES', i);2126 if pos(SearchString, UpperCase(s)) > 0 then2123 for I := 0 to nAdv - 1 do 2124 begin 2125 S := Phrases.Lookup('ADVANCES', I); 2126 if Pos(SearchString, UpperCase(S)) > 0 then 2127 2127 begin 2128 if iin FutureTech then2129 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FUTURE')2128 if I in FutureTech then 2129 S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE') 2130 2130 else 2131 s := s+ ' ' + HelpText.Lookup('HELPSPEC_ADV');2132 SearchResult.AddLine( s, pkNormal, 0, hkAdv + hkCrossLink, i);2133 include(mADVHELP, i);2131 S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV'); 2132 SearchResult.AddLine(S, pkNormal, 0, hkAdv + hkCrossLink, I); 2133 Include(mADVHELP, I); 2134 2134 end; 2135 2135 end; 2136 for i:= 0 to nSpecialModel - 1 do2137 begin 2138 FindStdModelPicture(SpecialModelPictureCode[ i], h, s);2139 if pos(SearchString, UpperCase(s)) > 0 then2136 for I := 0 to nSpecialModel - 1 do 2137 begin 2138 FindStdModelPicture(SpecialModelPictureCode[I], H, S); 2139 if Pos(SearchString, UpperCase(S)) > 0 then 2140 2140 begin 2141 2141 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 0, … … 2145 2145 end; 2146 2146 end; 2147 for i:= 0 to nFeature - 1 do2148 begin 2149 s := Phrases.Lookup('FEATURES', i);2150 if Pos(SearchString, UpperCase( s)) > 0 then2147 for I := 0 to nFeature - 1 do 2148 begin 2149 S := Phrases.Lookup('FEATURES', I); 2150 if Pos(SearchString, UpperCase(S)) > 0 then 2151 2151 begin 2152 if i< mcFirstNonCap then2153 s := s+ ' ' + HelpText.Lookup('HELPSPEC_CAP')2154 else if iin AutoFeature then2155 s := s+ ' ' + HelpText.Lookup('HELPSPEC_STANDARD')2152 if I < mcFirstNonCap then 2153 S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP') 2154 else if I in AutoFeature then 2155 S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD') 2156 2156 else 2157 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FEATURE');2158 SearchResult.AddLine( s, pkNormal, 0, hkFeature + hkCrossLink, i);2159 Include(mFEATUREHELP, i);2157 S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE'); 2158 SearchResult.AddLine(S, pkNormal, 0, hkFeature + hkCrossLink, I); 2159 Include(mFEATUREHELP, I); 2160 2160 end; 2161 2161 end; 2162 for i:= 0 to nImp - 1 do2163 begin 2164 s := Phrases.Lookup('IMPROVEMENTS', i);2165 if Pos(SearchString, UpperCase( s)) > 0 then2162 for I := 0 to nImp - 1 do 2163 begin 2164 S := Phrases.Lookup('IMPROVEMENTS', I); 2165 if Pos(SearchString, UpperCase(S)) > 0 then 2166 2166 begin 2167 case Imp[ i].Kind of2167 case Imp[I].Kind of 2168 2168 ikWonder: 2169 s := s+ ' ' + HelpText.Lookup('HELPSPEC_WONDER');2169 S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER'); 2170 2170 ikCommon: 2171 s := s+ ' ' + HelpText.Lookup('HELPSPEC_IMP');2171 S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP'); 2172 2172 ikShipPart: 2173 s := s+ ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');2173 S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'); 2174 2174 else 2175 s := s+ ' ' + HelpText.Lookup('HELPSPEC_NAT')2175 S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT') 2176 2176 end; 2177 SearchResult.AddLine( s, pkNormal, 0, hkImp + hkCrossLink, i);2178 Include(mIMPHELP, i);2177 SearchResult.AddLine(S, pkNormal, 0, hkImp + hkCrossLink, I); 2178 Include(mIMPHELP, I); 2179 2179 end 2180 2180 end; 2181 for i:= 0 to nGov - 1 do2182 if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', i))) > 0 then2181 for I := 0 to nGov - 1 do 2182 if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', I))) > 0 then 2183 2183 begin 2184 2184 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0, … … 2189 2189 2190 2190 // full text search 2191 h:= -1;2191 H := -1; 2192 2192 repeat 2193 PrevHandle := h;2194 PrevIndex := i;2195 if not HelpText.Search(SearchString, h, i) then2193 PrevHandle := H; 2194 PrevIndex := I; 2195 if not HelpText.Search(SearchString, H, I) then 2196 2196 Break; 2197 if h= hADVHELP then2197 if H = hADVHELP then 2198 2198 begin 2199 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2200 not( iin mADVHELP) then2199 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2200 not(I in mADVHELP) then 2201 2201 begin 2202 s := Phrases.Lookup('ADVANCES', i);2203 if iin FutureTech then2204 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FUTURE')2202 S := Phrases.Lookup('ADVANCES', I); 2203 if I in FutureTech then 2204 S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE') 2205 2205 else 2206 s := s+ ' ' + HelpText.Lookup('HELPSPEC_ADV');2207 SearchResult.AddLine( s, pkNormal, 0, hkAdv + hkCrossLink, i)2206 S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV'); 2207 SearchResult.AddLine(S, pkNormal, 0, hkAdv + hkCrossLink, I) 2208 2208 end; 2209 2209 end 2210 else if h= hIMPHELP then2210 else if H = hIMPHELP then 2211 2211 begin 2212 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2213 not( iin mIMPHELP) then2212 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2213 not(I in mIMPHELP) then 2214 2214 begin 2215 s := Phrases.Lookup('IMPROVEMENTS', i);2216 case Imp[ i].Kind of2215 S := Phrases.Lookup('IMPROVEMENTS', I); 2216 case Imp[I].Kind of 2217 2217 ikWonder: 2218 s := s+ ' ' + HelpText.Lookup('HELPSPEC_WONDER');2218 S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER'); 2219 2219 ikCommon: 2220 s := s+ ' ' + HelpText.Lookup('HELPSPEC_IMP');2220 S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP'); 2221 2221 ikShipPart: 2222 s := s+ ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');2222 S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'); 2223 2223 else 2224 s := s+ ' ' + HelpText.Lookup('HELPSPEC_NAT')2224 S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT') 2225 2225 end; 2226 SearchResult.AddLine( s, pkNormal, 0, hkImp + hkCrossLink, i)2226 SearchResult.AddLine(S, pkNormal, 0, hkImp + hkCrossLink, I) 2227 2227 end; 2228 2228 end 2229 else if h= hFEATUREHELP then2229 else if H = hFEATUREHELP then 2230 2230 begin 2231 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2232 not( iin mFEATUREHELP) then2231 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2232 not(I in mFEATUREHELP) then 2233 2233 begin 2234 s := Phrases.Lookup('FEATURES', i);2235 if i< mcFirstNonCap then2236 s := s+ ' ' + HelpText.Lookup('HELPSPEC_CAP')2237 else if iin AutoFeature then2238 s := s+ ' ' + HelpText.Lookup('HELPSPEC_STANDARD')2234 S := Phrases.Lookup('FEATURES', I); 2235 if I < mcFirstNonCap then 2236 S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP') 2237 else if I in AutoFeature then 2238 S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD') 2239 2239 else 2240 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FEATURE');2241 SearchResult.AddLine( s, pkNormal, 0, hkFeature + hkCrossLink, i);2240 S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE'); 2241 SearchResult.AddLine(S, pkNormal, 0, hkFeature + hkCrossLink, I); 2242 2242 end; 2243 2243 end 2244 else if h= hGOVHELP then2244 else if H = hGOVHELP then 2245 2245 begin 2246 if ( i >= 0) and (h<> PrevHandle) and not bGOVHELP then2246 if (I >= 0) and (H <> PrevHandle) and not bGOVHELP then 2247 2247 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0, 2248 2248 hkMisc + hkCrossLink, miscGovList) 2249 2249 end 2250 else if h= hSPECIALMODEL then2250 else if H = hSPECIALMODEL then 2251 2251 begin 2252 if ( i >= 0) and (h<> PrevHandle) and not bSPECIALMODEL then2252 if (I >= 0) and (H <> PrevHandle) and not bSPECIALMODEL then 2253 2253 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 2254 2254 0, hkModel + hkCrossLink, 0) 2255 2255 end 2256 else if h= hJOBHELP then2256 else if H = hJOBHELP then 2257 2257 begin 2258 if ( i >= 0) and (h<> PrevHandle) and not bJOBHELP then2258 if (I >= 0) and (H <> PrevHandle) and not bJOBHELP then 2259 2259 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0, 2260 2260 hkMisc + hkCrossLink, miscJobList) 2261 2261 end 2262 else if { (h<>hMAIN) and } ( h<> PrevHandle) then2262 else if { (h<>hMAIN) and } (H <> PrevHandle) then 2263 2263 begin 2264 s := HelpText.LookupByHandle(h);2265 p := Pos('$', s);2266 if p> 0 then2264 S := HelpText.LookupByHandle(H); 2265 P := Pos('$', S); 2266 if P > 0 then 2267 2267 begin 2268 s := Copy(s, p+ 1, maxint);2269 p := Pos('\', s);2270 if p> 0 then2271 s := Copy(s, 1, p- 1);2272 SearchResult.AddLine( s, pkNormal, 0, hkText + hkCrossLink, h);2268 S := Copy(S, P + 1, maxint); 2269 P := Pos('\', S); 2270 if P > 0 then 2271 S := Copy(S, 1, P - 1); 2272 SearchResult.AddLine(S, pkNormal, 0, hkText + hkCrossLink, H); 2273 2273 end; 2274 2274 end; … … 2278 2278 RightMargin := InnerWidth - 16 - GetSystemMetrics(SM_CXVSCROLL); 2279 2279 OffScreen.Canvas.Font.Assign(UniFont[ftNormal]); 2280 for i:= 0 to SearchResult.Count - 1 do2280 for I := 0 to SearchResult.Count - 1 do 2281 2281 begin 2282 while BiColorTextWidth(OffScreen.Canvas, SearchResult[ i]) >2282 while BiColorTextWidth(OffScreen.Canvas, SearchResult[I]) > 2283 2283 RightMargin - 32 do 2284 SearchResult[ i] := copy(SearchResult[i], 1, length(SearchResult[i]) - 1)2284 SearchResult[I] := Copy(SearchResult[I], 1, Length(SearchResult[I]) - 1) 2285 2285 end; 2286 2286 end; -
trunk/LocalPlayer/IsoEngine.pas
r442 r447 13 13 14 14 type 15 TInitEnemyModelEvent = function(emix: integer): boolean;15 TInitEnemyModelEvent = function(emix: Integer): Boolean; 16 16 TTileSize = (tsSmall, tsMedium, tsBig); 17 17 … … 33 33 Dirx: array [0..7] of Integer = (1, 2, 1, 0, -1, -2, -1, 0); 34 34 Diry: array [0..7] of Integer = (-1, 0, 1, 2, 1, 0, -1, -2); 35 procedure CityGrid(xm, ym: integer; CityAllowClick: Boolean);36 function IsShoreTile(Loc: integer): boolean;35 procedure CityGrid(xm, ym: Integer; CityAllowClick: Boolean); 36 function IsShoreTile(Loc: Integer): Boolean; 37 37 procedure MakeDark(Line: PPixelPointer; Length: Integer); 38 38 procedure SetTileSize(AValue: TTileSize); 39 procedure ShadeOutside(x0, y0, Width, Height, xm, ym: integer);39 procedure ShadeOutside(x0, y0, Width, Height, xm, ym: Integer); 40 40 protected 41 41 FOutput: TBitmap; … … 65 65 ShowDebug: Boolean; 66 66 FoW: Boolean; 67 function Connection4(Loc, Mask, Value: integer): integer;68 function Connection8(Loc, Mask: integer): integer;69 function OceanConnection(Loc: integer): integer;70 procedure PaintShore( x, y, Loc: integer);71 procedure PaintTileExtraTerrain( x, y, Loc: integer);72 procedure PaintTileObjects( x, y, Loc, CityLoc, CityOwner: integer;73 UseBlink: boolean);74 procedure PaintGrid( x, y, nx, ny: integer);75 procedure FillRect( x, y, Width, Height, Color: integer);76 procedure Textout( x, y, Color: integer; const s: string);77 procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);78 procedure TSprite(xDst, yDst, grix: integer; PureBlack: boolean = false);67 function Connection4(Loc, Mask, Value: Integer): Integer; 68 function Connection8(Loc, Mask: Integer): Integer; 69 function OceanConnection(Loc: Integer): Integer; 70 procedure PaintShore(X, Y, Loc: Integer); 71 procedure PaintTileExtraTerrain(X, Y, Loc: Integer); 72 procedure PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer; 73 UseBlink: Boolean); 74 procedure PaintGrid(X, Y, nx, ny: Integer); 75 procedure FillRect(X, Y, Width, Height, Color: Integer); 76 procedure Textout(X, Y, Color: Integer; const S: string); 77 procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 78 procedure TSprite(xDst, yDst, grix: Integer; PureBlack: Boolean = False); 79 79 procedure ApplyTileSize(ATileSize: TTileSize); 80 80 public … … 89 89 procedure Reset; 90 90 procedure SetOutput(Output: TBitmap); 91 procedure SetPaintBounds(Left, Top, Right, Bottom: integer);92 procedure Paint( x, y, Loc, nx, ny, CityLoc, CityOwner: integer;93 UseBlink: boolean = false; CityAllowClick: boolean = false);94 procedure PaintUnit( x, y: integer; const UnitInfo: TUnitInfo;95 Status: integer);96 procedure PaintCity( x, y: integer; const CityInfo: TCityInfo;97 accessory: boolean = true);98 procedure BitBltBitmap(Src: TBitmap; x, y, Width, Height, xSrc, ySrc,99 Rop: integer);91 procedure SetPaintBounds(Left, Top, Right, Bottom: Integer); 92 procedure Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer; 93 UseBlink: Boolean = False; CityAllowClick: Boolean = False); 94 procedure PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo; 95 Status: Integer); 96 procedure PaintCity(X, Y: Integer; const CityInfo: TCityInfo; 97 accessory: Boolean = True); 98 procedure BitBltBitmap(Src: TBitmap; X, Y, Width, Height, xSrc, ySrc, 99 Rop: Integer); 100 100 procedure AttackBegin(const ShowMove: TShowMove); 101 101 procedure AttackEffect(const ShowMove: TShowMove); 102 102 procedure AttackEnd; 103 103 procedure ReduceTerrainIconsSize; 104 property AdviceLoc: integer read FAdviceLoc write FAdviceLoc;104 property AdviceLoc: Integer read FAdviceLoc write FAdviceLoc; 105 105 property TileSize: TTileSize read FTileSize write SetTileSize; 106 106 end; … … 127 127 (X: 72; Y: 36)); 128 128 129 function IsJungle( y: integer): boolean;129 function IsJungle(Y: Integer): Boolean; 130 130 procedure Init(InitEnemyModelHandler: TInitEnemyModelEvent); 131 131 … … 173 173 IsoMapCache: array[TTileSize] of TIsoMapCache; 174 174 175 function IsJungle( y: integer): boolean;176 begin 177 result := (y > (G.ly - 2) div 4) and (G.ly - 1 - y> (G.ly - 2) div 4)175 function IsJungle(Y: Integer): Boolean; 176 begin 177 Result := (Y > (G.ly - 2) div 4) and (G.ly - 1 - Y > (G.ly - 2) div 4) 178 178 end; 179 179 … … 254 254 Mask24.BeginUpdate; 255 255 for ySrc := 0 to TerrainIconLines - 1 do begin 256 for i:= 0 to yyt * 3 - 1 do257 MaskLine[ i] := PixelPointer(Mask24, ScaleToNative(0),258 ScaleToNative(1 + ySrc * (yyt * 3 + 1) + i));256 for I := 0 to yyt * 3 - 1 do 257 MaskLine[I] := PixelPointer(Mask24, ScaleToNative(0), 258 ScaleToNative(1 + ySrc * (yyt * 3 + 1) + I)); 259 259 for xSrc := 0 to TerrainIconCols - 1 do begin 260 i:= ySrc * 9 + xSrc;261 TSpriteSize[ i].Left := 0;260 I := ySrc * 9 + xSrc; 261 TSpriteSize[I].Left := 0; 262 262 repeat 263 Border := true;264 for y:= 0 to yyt * 3 - 1 do begin265 MaskLine[ y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[i].Left));266 if MaskLine[ y].Pixel^.B = 0 then Border := false;263 Border := True; 264 for Y := 0 to yyt * 3 - 1 do begin 265 MaskLine[Y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[I].Left)); 266 if MaskLine[Y].Pixel^.B = 0 then Border := False; 267 267 end; 268 if Border then Inc(TSpriteSize[ i].Left);269 until not Border or (TSpriteSize[ i].Left = xxt * 2 - 1);270 TSpriteSize[ i].Top := 0;268 if Border then Inc(TSpriteSize[I].Left); 269 until not Border or (TSpriteSize[I].Left = xxt * 2 - 1); 270 TSpriteSize[I].Top := 0; 271 271 repeat 272 Border := true;273 for x:= 0 to xxt * 2 - 1 do begin274 MaskLine[TSpriteSize[ i].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));275 if MaskLine[TSpriteSize[ i].Top].Pixel^.B = 0 then Border := false;272 Border := True; 273 for X := 0 to xxt * 2 - 1 do begin 274 MaskLine[TSpriteSize[I].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X)); 275 if MaskLine[TSpriteSize[I].Top].Pixel^.B = 0 then Border := False; 276 276 end; 277 if Border then inc(TSpriteSize[i].Top);278 until not Border or (TSpriteSize[ i].Top = yyt * 3 - 1);279 TSpriteSize[ i].Right := xxt * 2;277 if Border then Inc(TSpriteSize[I].Top); 278 until not Border or (TSpriteSize[I].Top = yyt * 3 - 1); 279 TSpriteSize[I].Right := xxt * 2; 280 280 repeat 281 Border := true;282 for y:= 0 to yyt * 3 - 1 do begin283 MaskLine[ y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[i].Right));284 if MaskLine[ y].Pixel^.B = 0 then Border := false;281 Border := True; 282 for Y := 0 to yyt * 3 - 1 do begin 283 MaskLine[Y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[I].Right)); 284 if MaskLine[Y].Pixel^.B = 0 then Border := False; 285 285 end; 286 if Border then Dec(TSpriteSize[ i].Right);287 until not Border or (TSpriteSize[ i].Right = TSpriteSize[i].Left);288 TSpriteSize[ i].Bottom := yyt * 3;286 if Border then Dec(TSpriteSize[I].Right); 287 until not Border or (TSpriteSize[I].Right = TSpriteSize[I].Left); 288 TSpriteSize[I].Bottom := yyt * 3; 289 289 repeat 290 Border := true;291 for x:= 0 to xxt * 2 - 1 do begin292 MaskLine[TSpriteSize[ i].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));293 if MaskLine[TSpriteSize[ i].Bottom - 1].Pixel^.B = 0 then Border := false;290 Border := True; 291 for X := 0 to xxt * 2 - 1 do begin 292 MaskLine[TSpriteSize[I].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X)); 293 if MaskLine[TSpriteSize[I].Bottom - 1].Pixel^.B = 0 then Border := False; 294 294 end; 295 if Border then Dec(TSpriteSize[ i].Bottom);296 until not Border or (TSpriteSize[ i].Bottom = TSpriteSize[i].Top);295 if Border then Dec(TSpriteSize[I].Bottom); 296 until not Border or (TSpriteSize[I].Bottom = TSpriteSize[I].Top); 297 297 end; 298 298 end; … … 303 303 procedure TIsoMap.ApplyTileSize(ATileSize: TTileSize); 304 304 var 305 x: Integer;306 y: Integer;305 X: Integer; 306 Y: Integer; 307 307 xSrc: Integer; 308 308 ySrc: Integer; … … 361 361 1 + yyt + 15 * (yyt * 3 + 1), SRCAND); 362 362 363 for x:= -1 to 6 do begin364 if x= -1 then begin363 for X := -1 to 6 do begin 364 if X = -1 then begin 365 365 xSrc := ShoreDither * (xxt * 2 + 1) + 1; 366 366 ySrc := 1 + yyt; 367 367 end 368 else if x= 6 then begin368 else if X = 6 then begin 369 369 xSrc := 1 + (xxt * 2 + 1) * 2; 370 370 ySrc := 1 + yyt + (yyt * 3 + 1) * 2; 371 371 end else begin 372 xSrc := ( x+ 2) * (xxt * 2 + 1) + 1;372 xSrc := (X + 2) * (xxt * 2 + 1) + 1; 373 373 ySrc := 1 + yyt; 374 374 end; 375 for y:= -1 to 6 do376 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt,375 for Y := -1 to 6 do 376 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, 377 377 xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc); 378 for y:= -2 to 6 do379 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt, xxt,378 for Y := -2 to 6 do 379 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt, 380 380 yyt, HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, 381 381 SRCPAINT); 382 for y:= -2 to 6 do383 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2) + xxt, (y+ 2) * yyt,382 for Y := -2 to 6 do 383 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt, 384 384 xxt, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, 385 385 SRCPAINT); 386 for y:= -2 to 6 do387 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt, xxt,386 for Y := -2 to 6 do 387 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt, 388 388 yyt, DitherMask.Canvas, xxt, yyt, SRCAND); 389 for y:= -2 to 6 do390 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2) + xxt, (y+ 2) * yyt,389 for Y := -2 to 6 do 390 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt, 391 391 xxt, yyt, DitherMask.Canvas, 0, yyt, SRCAND); 392 392 end; 393 393 394 for y:= -1 to 6 do begin395 if y= -1 then begin394 for Y := -1 to 6 do begin 395 if Y = -1 then begin 396 396 xSrc := ShoreDither * (xxt * 2 + 1) + 1; 397 397 ySrc := 1 + yyt; 398 398 end 399 else if y= 6 then begin399 else if Y = 6 then begin 400 400 xSrc := 1 + 2 * (xxt * 2 + 1); 401 401 ySrc := 1 + yyt + 2 * (yyt * 3 + 1); 402 402 end else begin 403 xSrc := ( y+ 2) * (xxt * 2 + 1) + 1;403 xSrc := (Y + 2) * (xxt * 2 + 1) + 1; 404 404 ySrc := 1 + yyt; 405 405 end; 406 for x:= -2 to 6 do407 BitBltCanvas(LandMore.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt,406 for X := -2 to 6 do 407 BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, 408 408 xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc); 409 BitBltCanvas(LandMore.Canvas, xxt * 2, ( y+ 2) * yyt, xxt, yyt,409 BitBltCanvas(LandMore.Canvas, xxt * 2, (Y + 2) * yyt, xxt, yyt, 410 410 HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, SRCPAINT); 411 for x:= 0 to 7 do412 BitBltCanvas(LandMore.Canvas, ( x + 2) * (xxt * 2) - xxt, (y+ 2) * yyt,411 for X := 0 to 7 do 412 BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt, 413 413 xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, 414 414 SRCPAINT); 415 for x:= -2 to 6 do416 BitBltCanvas(LandMore.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt,415 for X := -2 to 6 do 416 BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, 417 417 xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND); 418 418 end; 419 419 420 for x:= 0 to 3 do begin421 for y:= 0 to 3 do begin422 if ( x = 1) and (y= 1) then xSrc := 1420 for X := 0 to 3 do begin 421 for Y := 0 to 3 do begin 422 if (X = 1) and (Y = 1) then xSrc := 1 423 423 else 424 xSrc := ( xmod 2) * (xxt * 2 + 1) + 1;424 xSrc := (X mod 2) * (xxt * 2 + 1) + 1; 425 425 ySrc := 1 + yyt; 426 if ( x >= 1) = (y>= 2) then427 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,426 if (X >= 1) = (Y >= 2) then 427 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt, 428 428 HGrTerrain.Data.Canvas, xSrc, ySrc); 429 if ( x >= 1) and ((y < 2) or (x>= 2)) then429 if (X >= 1) and ((Y < 2) or (X >= 2)) then 430 430 begin 431 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,431 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 432 432 HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, 433 433 SRCPAINT); 434 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,434 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt, 435 435 HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT); 436 436 end; 437 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,437 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 438 438 DitherMask.Canvas, xxt, yyt, SRCAND); 439 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,439 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt, 440 440 DitherMask.Canvas, 0, yyt, SRCAND); 441 441 end; 442 442 end; 443 443 444 for y:= 0 to 3 do begin445 for x:= 0 to 3 do begin446 if ( x = 1) and (y= 1) then xSrc := 1444 for Y := 0 to 3 do begin 445 for X := 0 to 3 do begin 446 if (X = 1) and (Y = 1) then xSrc := 1 447 447 else 448 xSrc := ( ymod 2) * (xxt * 2 + 1) + 1;448 xSrc := (Y mod 2) * (xxt * 2 + 1) + 1; 449 449 ySrc := 1 + yyt; 450 if ( x < 1) or (y>= 2) then451 BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,450 if (X < 1) or (Y >= 2) then 451 BitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt, 452 452 HGrTerrain.Data.Canvas, xSrc, ySrc); 453 if ( x = 1) and (y < 2) or (x >= 2) and (y>= 1) then453 if (X = 1) and (Y < 2) or (X >= 2) and (Y >= 1) then 454 454 begin 455 BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,455 BitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 456 456 HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, 457 457 SRCPAINT); 458 BitBltCanvas(OceanMore.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,458 BitBltCanvas(OceanMore.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt, 459 459 HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT); 460 460 end; 461 BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,461 BitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt, 462 462 DitherMask.Canvas, 0, 0, SRCAND); 463 463 end; … … 469 469 HGrTerrain.Mask.Canvas, 1, 1 + yyt, SRCPAINT); 470 470 471 for x:= -1 to 6 do472 for y:= -2 to 6 do473 BitBltCanvas(LandPatch.Canvas, ( x + 2) * (xxt * 2), (y+ 2) * yyt,471 for X := -1 to 6 do 472 for Y := -2 to 6 do 473 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, 474 474 xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND); 475 475 476 for y:= -1 to 6 do477 for x:= -2 to 7 do478 BitBltCanvas(LandMore.Canvas, ( x + 2) * (xxt * 2) - xxt, (y+ 2) * yyt,476 for Y := -1 to 6 do 477 for X := -2 to 7 do 478 BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt, 479 479 xxt * 2, yyt, DitherMask.Canvas, 0, yyt, SRCAND); 480 480 … … 482 482 LandMore.Canvas, 0, 0, SRCPAINT); 483 483 484 for x:= 0 to 3 do485 for y:= 0 to 3 do486 BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,484 for X := 0 to 3 do 485 for Y := 0 to 3 do 486 BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt, 487 487 DitherMask.Canvas, 0, 0, SRCAND); 488 488 489 for y:= 0 to 3 do490 for x:= 0 to 4 do491 BitBltCanvas(OceanMore.Canvas, x * (xxt * 2) - xxt, y* yyt, xxt * 2,489 for Y := 0 to 3 do 490 for X := 0 to 4 do 491 BitBltCanvas(OceanMore.Canvas, X * (xxt * 2) - xxt, Y * yyt, xxt * 2, 492 492 yyt, DitherMask.Canvas, 0, yyt, SRCAND); 493 493 … … 502 502 HGrTerrain.Mask.Canvas, 1, 1 + yyt); 503 503 504 for x:= 0 to 6 do505 BitBltCanvas(LandPatch.Canvas, ( x+ 2) * (xxt * 2), yyt, xxt * 2, yyt,504 for X := 0 to 6 do 505 BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), yyt, xxt * 2, yyt, 506 506 DitherMask.Canvas, 0, 0, SRCAND); 507 507 BitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas, 508 508 0, 0, DSTINVERT); 509 509 510 for y:= 0 to 6 do511 BitBltCanvas(LandPatch.Canvas, xxt * 2, ( y+ 2) * yyt, xxt * 2, yyt,510 for Y := 0 to 6 do 511 BitBltCanvas(LandPatch.Canvas, xxt * 2, (Y + 2) * yyt, xxt * 2, yyt, 512 512 DitherMask.Canvas, 0, 0, SRCAND); 513 513 … … 555 555 end; 556 556 557 procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: integer);557 procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: Integer); 558 558 begin 559 559 FLeft := Left; … … 563 563 end; 564 564 565 procedure TIsoMap.FillRect( x, y, Width, Height, Color: integer);566 begin 567 if x< FLeft then568 begin 569 Width := Width - (FLeft - x);570 x:= FLeft;571 end; 572 if y< FTop then573 begin 574 Height := Height - (FTop - y);575 y:= FTop;576 end; 577 if x+ Width >= FRight then578 Width := FRight - x;579 if y+ Height >= FBottom then580 Height := FBottom - y;565 procedure TIsoMap.FillRect(X, Y, Width, Height, Color: Integer); 566 begin 567 if X < FLeft then 568 begin 569 Width := Width - (FLeft - X); 570 X := FLeft; 571 end; 572 if Y < FTop then 573 begin 574 Height := Height - (FTop - Y); 575 Y := FTop; 576 end; 577 if X + Width >= FRight then 578 Width := FRight - X; 579 if Y + Height >= FBottom then 580 Height := FBottom - Y; 581 581 if (Width <= 0) or (Height <= 0) then 582 exit;582 Exit; 583 583 584 584 FOutput.Canvas.Brush.Color := Color; 585 FOutput.Canvas.FillRect(Rect( x, y, x + Width, y+ Height));585 FOutput.Canvas.FillRect(Rect(X, Y, X + Width, Y + Height)); 586 586 FOutput.Canvas.Brush.Style := bsClear; 587 587 end; 588 588 589 procedure TIsoMap.Textout( x, y, Color: integer; const s: string);589 procedure TIsoMap.Textout(X, Y, Color: Integer; const S: string); 590 590 begin 591 591 FOutput.Canvas.Font.Color := Color; 592 FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), x, y, s)593 end; 594 595 procedure TIsoMap.BitBltBitmap(Src: TBitmap; x, y, Width, Height, xSrc, ySrc,596 Rop: integer);597 begin 598 if x< FLeft then599 begin 600 Width := Width - (FLeft - x);601 xSrc := xSrc + (FLeft - x);602 x:= FLeft;603 end; 604 if y< FTop then605 begin 606 Height := Height - (FTop - y);607 ySrc := ySrc + (FTop - y);608 y:= FTop;609 end; 610 if x+ Width >= FRight then611 Width := FRight - x;612 if y+ Height >= FBottom then613 Height := FBottom - y;592 FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), X, Y, S) 593 end; 594 595 procedure TIsoMap.BitBltBitmap(Src: TBitmap; X, Y, Width, Height, xSrc, ySrc, 596 Rop: Integer); 597 begin 598 if X < FLeft then 599 begin 600 Width := Width - (FLeft - X); 601 xSrc := xSrc + (FLeft - X); 602 X := FLeft; 603 end; 604 if Y < FTop then 605 begin 606 Height := Height - (FTop - Y); 607 ySrc := ySrc + (FTop - Y); 608 Y := FTop; 609 end; 610 if X + Width >= FRight then 611 Width := FRight - X; 612 if Y + Height >= FBottom then 613 Height := FBottom - Y; 614 614 if (Width <= 0) or (Height <= 0) then 615 exit;616 617 BitBltCanvas(FOutput.Canvas, x, y, Width, Height, Src.Canvas, xSrc, ySrc, Rop);618 end; 619 620 procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);615 Exit; 616 617 BitBltCanvas(FOutput.Canvas, X, Y, Width, Height, Src.Canvas, xSrc, ySrc, Rop); 618 end; 619 620 procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 621 621 begin 622 622 BitBltBitmap(HGr.Mask, xDst, yDst, Width, Height, xGr, yGr, SRCAND); … … 624 624 end; 625 625 626 procedure TIsoMap.TSprite(xDst, yDst, grix: integer;627 PureBlack: boolean = false);626 procedure TIsoMap.TSprite(xDst, yDst, grix: Integer; 627 PureBlack: Boolean = False); 628 628 var 629 629 Width: Integer; 630 630 Height: Integer; 631 631 xSrc: Integer; 632 ySrc: integer;632 ySrc: Integer; 633 633 begin 634 634 Width := TSpriteSize[grix].Right - TSpriteSize[grix].Left; … … 653 653 Height := FBottom - yDst; 654 654 if (Width <= 0) or (Height <= 0) then 655 exit;655 Exit; 656 656 657 657 BitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND); … … 660 660 end; 661 661 662 procedure TIsoMap.PaintUnit( x, y: integer; const UnitInfo: TUnitInfo;663 Status: integer);664 var 665 xsh, ysh, xGr, yGr, j, mixShow: integer;662 procedure TIsoMap.PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo; 663 Status: Integer); 664 var 665 xsh, ysh, xGr, yGr, J, mixShow: Integer; 666 666 begin 667 667 with UnitInfo do 668 if (Owner = me) or (emix <> $FFFF) then668 if (Owner = Me) or (emix <> $FFFF) then 669 669 begin 670 670 if Job = jCity then … … 675 675 (@OnInitEnemyModel <> nil) then 676 676 if not OnInitEnemyModel(emix) then 677 exit;677 Exit; 678 678 xsh := Tribe[Owner].ModelPicture[mixShow].xShield; 679 679 ysh := Tribe[Owner].ModelPicture[mixShow].yShield; 680 680 {$IFNDEF SCR} if Status and usStay <> 0 then 681 j:= 19681 J := 19 682 682 else if Status and usRecover <> 0 then 683 j:= 16683 J := 16 684 684 else if Status and (usGoto or usEnhance) = usGoto or usEnhance then 685 j:= 18685 J := 18 686 686 else if Status and usEnhance <> 0 then 687 j:= 17687 J := 17 688 688 else if Status and usGoto <> 0 then 689 j:= 20689 J := 20 690 690 else {$ENDIF} if Job = jCity then 691 j:= jNone691 J := jNone 692 692 else 693 j:= Job;693 J := Job; 694 694 if Flags and unMulti <> 0 then 695 Sprite(Tribe[Owner].symHGr, x + xsh - 1 + 4, y+ ysh - 2, 14, 12,695 Sprite(Tribe[Owner].symHGr, X + xsh - 1 + 4, Y + ysh - 2, 14, 12, 696 696 33 + Tribe[Owner].sympix mod 10 * 65, 697 697 1 + Tribe[Owner].sympix div 10 * 49); 698 Sprite(Tribe[Owner].symHGr, x + xsh - 1, y+ ysh - 2, 14, 12,698 Sprite(Tribe[Owner].symHGr, X + xsh - 1, Y + ysh - 2, 14, 12, 699 699 18 + Tribe[Owner].sympix mod 10 * 65, 700 700 1 + Tribe[Owner].sympix div 10 * 49); 701 FillRect( x + xsh, y+ ysh + 5, 1 + Health * 11 div 100, 3,701 FillRect(X + xsh, Y + ysh + 5, 1 + Health * 11 div 100, 3, 702 702 ColorOfHealth(Health)); 703 if j> 0 then703 if J > 0 then 704 704 begin 705 xGr := 121 + jmod 7 * 9;706 yGr := 1 + jdiv 7 * 9;707 BitBltBitmap(HGrSystem.Mask, x + xsh + 3, y+ ysh + 9, 8, 8, xGr,705 xGr := 121 + J mod 7 * 9; 706 yGr := 1 + J div 7 * 9; 707 BitBltBitmap(HGrSystem.Mask, X + xsh + 3, Y + ysh + 9, 8, 8, xGr, 708 708 yGr, SRCAND); 709 Sprite(HGrSystem, x + xsh + 2, y+ ysh + 8, 8, 8, xGr, yGr);709 Sprite(HGrSystem, X + xsh + 2, Y + ysh + 8, 8, 8, xGr, yGr); 710 710 end; 711 711 with Tribe[Owner].ModelPicture[mixShow] do 712 Sprite(HGr, x, y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1);712 Sprite(HGr, X, Y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1); 713 713 if Flags and unFortified <> 0 then 714 714 begin 715 715 { DataCanvas:=HGrTerrain.Data.Canvas; 716 716 MaskCanvas:=HGrTerrain.Mask.Canvas; 717 TSprite( x,y+16,12*9+7); }718 Sprite(HGrStdUnits, x, y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1);717 TSprite(X,Y+16,12*9+7); } 718 Sprite(HGrStdUnits, X, Y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1); 719 719 end; 720 720 end; 721 721 end; 722 722 723 procedure TIsoMap.PaintCity( x, y: integer; const CityInfo: TCityInfo;724 accessory: boolean);723 procedure TIsoMap.PaintCity(X, Y: Integer; const CityInfo: TCityInfo; 724 accessory: Boolean); 725 725 var 726 726 age: Integer; … … 733 733 LabelLength: Integer; 734 734 cpic: TCityPicture; 735 s: string;735 S: string; 736 736 begin 737 737 age := GetAge(CityInfo.Owner); … … 752 752 (cHGr.Data.Canvas.Pixels[(xGr + 4) * 65, cpix * 49 + 48] = $00FFFF) 753 753 then 754 Sprite(cHGr, x - xxc, y- 2 * yyc, xxc * 2, yyc * 3,754 Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3, 755 755 xGr * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1)); 756 756 if ciWalled and CityInfo.Flags <> 0 then 757 Sprite(cHGr, x - xxc, y- 2 * yyc, xxc * 2, yyc * 3,757 Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3, 758 758 (xGr + 4) * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1)); 759 759 end … … 761 761 begin 762 762 if ciWalled and CityInfo.Flags <> 0 then 763 Sprite(HGrCities, x - xxt, y- 2 * yyt, 2 * xxt, 3 * yyt,763 Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt, 764 764 (xGr + 4) * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1)) 765 765 else 766 Sprite(HGrCities, x - xxt, y- 2 * yyt, 2 * xxt, 3 * yyt,766 Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt, 767 767 xGr * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1)); 768 768 end; 769 769 770 770 if not accessory then 771 exit;771 Exit; 772 772 773 773 { if ciCapital and CityInfo.Flags<>0 then 774 Sprite(Tribe[CityInfo.Owner].symHGr, x+cpic.xf,y-13+cpic.yf,13,14,774 Sprite(Tribe[CityInfo.Owner].symHGr,X+cpic.xf,Y-13+cpic.yf,13,14, 775 775 1+Tribe[CityInfo.Owner].sympix mod 10 *65, 776 776 1+Tribe[CityInfo.Owner].sympix div 10 *49); {capital -- paint flag } … … 781 781 begin 782 782 cpic := Tribe[CityInfo.Owner].CityPicture[xGr]; 783 xShield := x- xxc + cpic.xShield;784 yShield := y- 2 * yyc + cpic.yShield;783 xShield := X - xxc + cpic.xShield; 784 yShield := Y - 2 * yyc + cpic.yShield; 785 785 end 786 786 else 787 787 begin 788 788 cpic := CitiesPictures.Pictures[age, xGr]; 789 xShield := x- xxt + cpic.xShield;790 yShield := y- 2 * yyt + cpic.yShield;789 xShield := X - xxt + cpic.xShield; 790 yShield := Y - 2 * yyt + cpic.yShield; 791 791 end; 792 s:= IntToStr(CityInfo.size);793 LabelLength := FOutput.Canvas.TextWidth( s);792 S := IntToStr(CityInfo.size); 793 LabelLength := FOutput.Canvas.TextWidth(S); 794 794 FillRect(xShield, yShield, LabelLength + 4, 16, $000000); 795 795 if MyMap[CityInfo.Loc] and (fUnit or fObserved) = fObserved then … … 802 802 LabelTextColor := $000000; 803 803 end; 804 Textout(xShield + 2, yShield - 1, LabelTextColor, s);805 end; 806 end; 807 808 function PoleTile(Loc: integer): integer;804 Textout(xShield + 2, yShield - 1, LabelTextColor, S); 805 end; 806 end; 807 808 function PoleTile(Loc: Integer): Integer; 809 809 begin { virtual pole tile } 810 result := fUNKNOWN;810 Result := fUNKNOWN; 811 811 if Loc < -2 * G.lx then 812 812 else if Loc < -G.lx then … … 815 815 (MyMap[dLoc(Loc, -2, 2)] and fTerrain <> fUNKNOWN) and 816 816 (MyMap[dLoc(Loc, 2, 2)] and fTerrain <> fUNKNOWN) then 817 result := fArctic;817 Result := fArctic; 818 818 if (MyMap[dLoc(Loc, 0, 2)] and fObserved <> 0) and 819 819 (MyMap[dLoc(Loc, -2, 2)] and fObserved <> 0) and 820 820 (MyMap[dLoc(Loc, 2, 2)] and fObserved <> 0) then 821 result := result or fObserved;821 Result := Result or fObserved; 822 822 end 823 823 else if Loc < 0 then … … 825 825 if (MyMap[dLoc(Loc, -1, 1)] and fTerrain <> fUNKNOWN) and 826 826 (MyMap[dLoc(Loc, 1, 1)] and fTerrain <> fUNKNOWN) then 827 result := fArctic;827 Result := fArctic; 828 828 if (MyMap[dLoc(Loc, -1, 1)] and fObserved <> 0) and 829 829 (MyMap[dLoc(Loc, 1, 1)] and fObserved <> 0) then 830 result := result or fObserved;830 Result := Result or fObserved; 831 831 end 832 832 else if Loc < G.lx * (G.ly + 1) then … … 834 834 if (MyMap[dLoc(Loc, -1, -1)] and fTerrain <> fUNKNOWN) and 835 835 (MyMap[dLoc(Loc, 1, -1)] and fTerrain <> fUNKNOWN) then 836 result := fArctic;836 Result := fArctic; 837 837 if (MyMap[dLoc(Loc, -1, -1)] and fObserved <> 0) and 838 838 (MyMap[dLoc(Loc, 1, -1)] and fObserved <> 0) then 839 result := result or fObserved;839 Result := Result or fObserved; 840 840 end 841 841 else if Loc < G.lx * (G.ly + 2) then … … 844 844 (MyMap[dLoc(Loc, -2, -2)] and fTerrain <> fUNKNOWN) and 845 845 (MyMap[dLoc(Loc, 2, -2)] and fTerrain <> fUNKNOWN) then 846 result := fArctic;846 Result := fArctic; 847 847 if (MyMap[dLoc(Loc, 0, -2)] and fObserved <> 0) and 848 848 (MyMap[dLoc(Loc, -2, -2)] and fObserved <> 0) and 849 849 (MyMap[dLoc(Loc, 2, -2)] and fObserved <> 0) then 850 result := result or fObserved;851 end; 852 end; 853 854 function TIsoMap.Connection4(Loc, Mask, Value: integer): integer;855 begin 856 result := 0;850 Result := Result or fObserved; 851 end; 852 end; 853 854 function TIsoMap.Connection4(Loc, Mask, Value: Integer): Integer; 855 begin 856 Result := 0; 857 857 if dLoc(Loc, 1, -1) >= 0 then 858 858 begin 859 859 if MyMap[dLoc(Loc, 1, -1)] and Mask = Cardinal(Value) then 860 inc(result, 1);860 Inc(Result, 1); 861 861 if MyMap[dLoc(Loc, -1, -1)] and Mask = Cardinal(Value) then 862 inc(result, 8);862 Inc(Result, 8); 863 863 end; 864 864 if dLoc(Loc, 1, 1) < G.lx * G.ly then 865 865 begin 866 866 if MyMap[dLoc(Loc, 1, 1)] and Mask = Cardinal(Value) then 867 inc(result, 2);867 Inc(Result, 2); 868 868 if MyMap[dLoc(Loc, -1, 1)] and Mask = Cardinal(Value) then 869 inc(result, 4);870 end; 871 end; 872 873 function TIsoMap.Connection8(Loc, Mask: integer): integer;869 Inc(Result, 4); 870 end; 871 end; 872 873 function TIsoMap.Connection8(Loc, Mask: Integer): Integer; 874 874 var 875 875 Dir: Integer; 876 876 ConnLoc: Integer; 877 877 begin 878 result := 0;878 Result := 0; 879 879 for Dir := 0 to 7 do 880 880 begin … … 882 882 if (ConnLoc >= 0) and (ConnLoc < G.lx * G.ly) and 883 883 (MyMap[ConnLoc] and Mask <> 0) then 884 inc(result, 1 shl Dir);885 end; 886 end; 887 888 function TIsoMap.OceanConnection(Loc: integer): integer;884 Inc(Result, 1 shl Dir); 885 end; 886 end; 887 888 function TIsoMap.OceanConnection(Loc: Integer): Integer; 889 889 var 890 890 Dir: Integer; 891 891 ConnLoc: Integer; 892 892 begin 893 result := 0;893 Result := 0; 894 894 for Dir := 0 to 7 do 895 895 begin … … 897 897 if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or 898 898 ((MyMap[ConnLoc] - 2) and fTerrain < 13) then 899 inc(result, 1 shl Dir);900 end; 901 end; 902 903 procedure TIsoMap.PaintShore( x, y, Loc: integer);899 Inc(Result, 1 shl Dir); 900 end; 901 end; 902 903 procedure TIsoMap.PaintShore(X, Y, Loc: Integer); 904 904 var 905 905 Conn: Integer; 906 906 Tile: Integer; 907 907 begin 908 if ( y <= FTop - yyt * 2) or (y > FBottom) or (x<= FLeft - xxt * 2) or909 ( x> FRight) then910 exit;908 if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or 909 (X > FRight) then 910 Exit; 911 911 if (Loc < 0) or (Loc >= G.lx * G.ly) then 912 exit;912 Exit; 913 913 Tile := MyMap[Loc]; 914 914 if Tile and fTerrain >= fGrass then 915 exit;915 Exit; 916 916 Conn := OceanConnection(Loc); 917 917 if Conn = 0 then 918 exit;919 920 BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y, xxt, yyt,918 Exit; 919 920 BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y, xxt, yyt, 921 921 1 + (Conn shr 6 + Conn and 1 shl 2) * (xxt * 2 + 1), 922 922 1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT); 923 BitBltBitmap(HGrTerrain.Data, x + xxt, y+ yyt div 2, xxt, yyt,923 BitBltBitmap(HGrTerrain.Data, X + xxt, Y + yyt div 2, xxt, yyt, 924 924 1 + (Conn and 7) * (xxt * 2 + 1) + xxt, 925 925 1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT); 926 BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y+ yyt, xxt, yyt,926 BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y + yyt, xxt, yyt, 927 927 1 + (Conn shr 2 and 7) * (xxt * 2 + 1) + xxt, 928 928 1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT); 929 BitBltBitmap(HGrTerrain.Data, x, y+ yyt div 2, xxt, yyt,929 BitBltBitmap(HGrTerrain.Data, X, Y + yyt div 2, xxt, yyt, 930 930 1 + (Conn shr 4 and 7) * (xxt * 2 + 1), 931 931 1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT); 932 932 Conn := Connection4(Loc, fTerrain, fUNKNOWN); { dither to black } 933 933 if Conn and 1 <> 0 then 934 BitBltBitmap(HGrTerrain.Mask, x + xxt, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) +934 BitBltBitmap(HGrTerrain.Mask, X + xxt, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) + 935 935 xxt, 1 + yyt + 15 * (yyt * 3 + 1), SRCAND); 936 936 if Conn and 2 <> 0 then 937 BitBltBitmap(HGrTerrain.Mask, x + xxt, y+ yyt, xxt, yyt,937 BitBltBitmap(HGrTerrain.Mask, X + xxt, Y + yyt, xxt, yyt, 938 938 1 + 7 * (xxt * 2 + 1) + xxt, 1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND); 939 939 if Conn and 4 <> 0 then 940 BitBltBitmap(HGrTerrain.Mask, x, y+ yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1),940 BitBltBitmap(HGrTerrain.Mask, X, Y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1), 941 941 1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND); 942 942 if Conn and 8 <> 0 then 943 BitBltBitmap(HGrTerrain.Mask, x, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1),943 BitBltBitmap(HGrTerrain.Mask, X, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1), 944 944 1 + yyt + 15 * (yyt * 3 + 1), SRCAND); 945 945 end; 946 946 947 procedure TIsoMap.PaintTileExtraTerrain( x, y, Loc: integer);948 var 949 Dir, Conn, RRConn, yGr, Tile, yLoc: integer;950 begin 951 if (Loc < 0) or (Loc >= G.lx * G.ly) or ( y<= -yyt * 2) or952 ( y > FOutput.Height) or (x <= -xxt * 2) or (x> FOutput.Width) then953 exit;947 procedure TIsoMap.PaintTileExtraTerrain(X, Y, Loc: Integer); 948 var 949 Dir, Conn, RRConn, yGr, Tile, yLoc: Integer; 950 begin 951 if (Loc < 0) or (Loc >= G.lx * G.ly) or (Y <= -yyt * 2) or 952 (Y > FOutput.Height) or (X <= -xxt * 2) or (X > FOutput.Width) then 953 Exit; 954 954 Tile := MyMap[Loc]; 955 955 if Tile and fTerrain = fForest then … … 966 966 then 967 967 Conn := Conn and not 9; // no connection to north 968 TSprite( x, y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols);968 TSprite(X, Y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols); 969 969 end 970 970 else if Tile and fTerrain in [fHills, fMountains, fForest] then … … 972 972 yGr := 3 + 2 * (Tile and fTerrain - fForest); 973 973 Conn := Connection4(Loc, fTerrain, Tile and fTerrain); 974 TSprite( x, y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols);974 TSprite(X, Y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols); 975 975 end 976 976 else if Tile and fDeadLands <> 0 then 977 TSprite( x, y, spRow2);977 TSprite(X, Y, spRow2); 978 978 979 979 if ShowObjects then 980 980 begin 981 981 if Tile and fTerImp = tiFarm then 982 TSprite( x, y, spFarmLand)982 TSprite(X, Y, spFarmLand) 983 983 else if Tile and fTerImp = tiIrrigation then 984 TSprite( x, y, spIrrigation);984 TSprite(X, Y, spIrrigation); 985 985 end; 986 986 if Tile and fRiver <> 0 then … … 989 989 Connection4(Loc, fTerrain, fShore) or Connection4(Loc, fTerrain, 990 990 fUNKNOWN); 991 TSprite( x, y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols);991 TSprite(X, Y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols); 992 992 end; 993 993 … … 997 997 for Dir := 0 to 3 do 998 998 if Conn and (1 shl Dir) <> 0 then { river mouths } 999 TSprite( x, y, spRiverMouths + Dir);999 TSprite(X, Y, spRiverMouths + Dir); 1000 1000 if ShowObjects then 1001 1001 begin … … 1003 1003 for Dir := 0 to 7 do 1004 1004 if Conn and (1 shl Dir) <> 0 then { canal mouths } 1005 TSprite( x, y, spCanalMouths + 1 + Dir);1005 TSprite(X, Y, spCanalMouths + 1 + Dir); 1006 1006 end; 1007 1007 end; … … 1015 1015 if Conn = 0 then begin 1016 1016 if Tile and fCanal <> 0 then 1017 TSprite( x, y, spCanal);1017 TSprite(X, Y, spCanal); 1018 1018 end 1019 1019 else 1020 1020 for Dir := 0 to 7 do 1021 1021 if (1 shl Dir) and Conn <> 0 then 1022 TSprite( x, y, spCanal + 1 + Dir);1022 TSprite(X, Y, spCanal + 1 + Dir); 1023 1023 end; 1024 1024 … … 1032 1032 Conn := Connection8(Loc, fRoad or fRR or fCity) and not RRConn; 1033 1033 if (Conn = 0) and (Tile and (fRR or fCity) = 0) then 1034 TSprite( x, y, spRoad)1034 TSprite(X, Y, spRoad) 1035 1035 else if Conn > 0 then 1036 1036 for Dir := 0 to 7 do 1037 1037 if (1 shl Dir) and Conn <> 0 then 1038 TSprite( x, y, spRoad + 1 + Dir);1038 TSprite(X, Y, spRoad + 1 + Dir); 1039 1039 end; 1040 1040 1041 1041 // Paint railroad connections 1042 1042 if (Tile and fRR <> 0) and (RRConn = 0) then 1043 TSprite( x, y, spRailRoad)1043 TSprite(X, Y, spRailRoad) 1044 1044 else if RRConn > 0 then begin 1045 1045 for Dir := 0 to 7 do 1046 1046 if (1 shl Dir) and RRConn <> 0 then 1047 TSprite( x, y, spRailRoad + 1 + Dir);1047 TSprite(X, Y, spRailRoad + 1 + Dir); 1048 1048 end; 1049 1049 end; … … 1051 1051 1052 1052 // (x,y) is top left pixel of (2*xxt,3*yyt) rectangle 1053 procedure TIsoMap.PaintTileObjects( x, y, Loc, CityLoc, CityOwner: integer;1054 UseBlink: boolean);1055 var 1056 p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: integer;1053 procedure TIsoMap.PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer; 1054 UseBlink: Boolean); 1055 var 1056 p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: Integer; 1057 1057 CityInfo: TCityInfo; 1058 1058 UnitInfo: TUnitInfo; 1059 fog: boolean;1059 fog: Boolean; 1060 1060 SpecialRow: Integer; 1061 1061 SpecialCol: Integer; … … 1063 1063 procedure NameCity; 1064 1064 var 1065 cix, xs, w: integer;1065 cix, xs, W: Integer; 1066 1066 BehindCityInfo: TCityInfo; 1067 s: string;1068 IsCapital: boolean;1067 S: string; 1068 IsCapital: Boolean; 1069 1069 begin 1070 1070 BehindCityInfo.Loc := Loc - 2 * G.lx; … … 1076 1076 IsCapital := BehindCityInfo.Flags and ciCapital <> 0; 1077 1077 { if Showuix and (cix>=0) then s:=IntToStr(cix) 1078 else } s:= CityName(BehindCityInfo.ID);1079 w := FOutput.Canvas.TextWidth(s);1080 xs := x + xxt - (w+ 1) div 2;1078 else } S := CityName(BehindCityInfo.ID); 1079 W := FOutput.Canvas.TextWidth(S); 1080 xs := X + xxt - (W + 1) div 2; 1081 1081 if IsCapital then 1082 1082 FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style + [fsUnderline]; 1083 Textout(xs + 1, y - 9, $000000, s);1084 Textout(xs, y - 10, $FFFFFF, s);1083 Textout(xs + 1, Y - 9, $000000, S); 1084 Textout(xs, Y - 10, $FFFFFF, S); 1085 1085 if IsCapital then 1086 1086 FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style - [fsUnderline]; … … 1092 1092 if ShowObjects and not (moEditMode in MapOptions) and 1093 1093 (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then 1094 TSprite( x + xxt, y- 6, spSpacePort);1094 TSprite(X + xxt, Y - 6, spSpacePort); 1095 1095 end; 1096 1096 1097 1097 procedure PaintBorder; 1098 1098 var 1099 dx, dy: integer;1099 dx, dy: Integer; 1100 1100 begin 1101 1101 if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and 1102 1102 (Tile and fTerrain <> fUNKNOWN) then begin 1103 1103 p1 := MyRO.Territory[Loc]; 1104 if (p1 >= 0) and (ShowMyBorder or (p1 <> me)) then begin1104 if (p1 >= 0) and (ShowMyBorder or (p1 <> Me)) then begin 1105 1105 if BordersOK^ and (1 shl p1) = 0 then begin 1106 1106 UnshareBitmap(Borders); … … 1123 1123 if p2 <> p1 then 1124 1124 begin 1125 BitBltBitmap(HGrTerrain.Mask, x + dx * xxt, y+ dy * yyt, xxt,1125 BitBltBitmap(HGrTerrain.Mask, X + dx * xxt, Y + dy * yyt, xxt, 1126 1126 yyt, 1 + 8 * (xxt * 2 + 1) + dx * xxt, 1127 1127 1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, SRCAND); 1128 BitBltBitmap(Borders, x + dx * xxt, y+ dy * yyt, xxt, yyt, dx * xxt,1128 BitBltBitmap(Borders, X + dx * xxt, Y + dy * yyt, xxt, yyt, dx * xxt, 1129 1129 p1 * (yyt * 2) + dy * yyt, SRCPAINT); 1130 1130 end; … … 1143 1143 (Tile and fCity <> 0) then 1144 1144 GetCityInfo(Loc, cix, CityInfo); 1145 if ( y <= FTop - yyt * 2) or (y > FBottom) or (x<= FLeft - xxt * 2) or1146 ( x> FRight) then1145 if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or 1146 (X > FRight) then 1147 1147 begin 1148 1148 NameCity; 1149 1149 ShowSpacePort; 1150 exit;1150 Exit; 1151 1151 end; 1152 1152 if Tile and fTerrain = fUNKNOWN then … … 1154 1154 NameCity; 1155 1155 ShowSpacePort; 1156 exit;1156 Exit; 1157 1157 end; { square not discovered } 1158 1158 … … 1161 1161 1162 1162 if (Loc >= 0) and (Loc < G.lx * G.ly) and (Loc = FAdviceLoc) then 1163 TSprite( x, y, spPlain);1163 TSprite(X, Y, spPlain); 1164 1164 1165 1165 if (Loc >= 0) and (Loc < G.lx * G.ly) and (Tile and fSpecial <> 0) … … 1170 1170 SpecialRow := Tile and fSpecial shr 5; 1171 1171 if SpecialCol < fForest then 1172 TSprite( x, y, SpecialCol + SpecialRow * TerrainIconCols)1172 TSprite(X, Y, SpecialCol + SpecialRow * TerrainIconCols) 1173 1173 else if (SpecialCol = fForest) and IsJungle(dy) then 1174 TSprite( x, y, spJungle - 1 + SpecialRow * TerrainIconCols)1174 TSprite(X, Y, spJungle - 1 + SpecialRow * TerrainIconCols) 1175 1175 else 1176 TSprite( x, y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols);1176 TSprite(X, Y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols); 1177 1177 end; 1178 1178 … … 1180 1180 begin 1181 1181 if Tile and fTerImp = tiMine then 1182 TSprite( x, y, spMine);1182 TSprite(X, Y, spMine); 1183 1183 if Tile and fTerImp = tiBase then 1184 TSprite( x, y, spBase);1184 TSprite(X, Y, spBase); 1185 1185 if Tile and fPoll <> 0 then 1186 TSprite( x, y, spPollution);1186 TSprite(X, Y, spPollution); 1187 1187 if Tile and fTerImp = tiFort then 1188 1188 begin 1189 TSprite( x, y, spFortBack);1189 TSprite(X, Y, spFortBack); 1190 1190 if Tile and fObserved = 0 then 1191 TSprite( x, y, spFortFront);1191 TSprite(X, Y, spFortFront); 1192 1192 end; 1193 1193 end; 1194 1194 if (Tile and fDeadLands) <> 0 then 1195 TSprite( x, y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);1195 TSprite(X, Y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols); 1196 1196 1197 1197 if moEditMode in MapOptions then … … 1205 1205 if fog and ShowObjects then 1206 1206 if Loc < -G.lx then 1207 Sprite(HGrTerrain, x, y+ yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),1207 Sprite(HGrTerrain, X, Y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1), 1208 1208 1 + yyt * 2 + 15 * (yyt * 3 + 1)) 1209 1209 else if Loc >= G.lx * (G.ly + 1) then 1210 Sprite(HGrTerrain, x, y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),1210 Sprite(HGrTerrain, X, Y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1), 1211 1211 1 + yyt + 15 * (yyt * 3 + 1)) 1212 1212 else 1213 TSprite( x, y, spGrid, xxt <> 33);1213 TSprite(X, Y, spGrid, xxt <> 33); 1214 1214 1215 1215 if FoW and (Tile and fObserved = 0) then … … 1224 1224 if (Destination = Loc) and (Destination <> MyUn[UnFocus].Loc) then 1225 1225 if not UseBlink or BlinkOn then 1226 TSprite( x, y, spBlink1)1226 TSprite(X, Y, spBlink1) 1227 1227 else 1228 TSprite( x, y, spBlink2)1228 TSprite(X, Y, spBlink2) 1229 1229 end; 1230 1230 {$ENDIF} … … 1232 1232 begin 1233 1233 if Tile and fPrefStartPos <> 0 then 1234 TSprite( x, y, spPrefStartPos)1234 TSprite(X, Y, spPrefStartPos) 1235 1235 else if Tile and fStartPos <> 0 then 1236 TSprite( x, y, spStartPos);1236 TSprite(X, Y, spStartPos); 1237 1237 end 1238 1238 else if ShowObjects then 1239 1239 begin 1240 1240 { if (CityLoc<0) and (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc) then 1241 if BlinkOn then TSprite( x,y,8+9*0)1242 else TSprite( x,y,8+9*1); }1241 if BlinkOn then TSprite(X,Y,8+9*0) 1242 else TSprite(X,Y,8+9*1); } 1243 1243 1244 1244 NameCity; 1245 1245 ShowSpacePort; 1246 1246 if Tile and fCity <> 0 then 1247 PaintCity( x + xxt, y+ yyt, CityInfo, CityOwner < 0);1247 PaintCity(X + xxt, Y + yyt, CityInfo, CityOwner < 0); 1248 1248 1249 1249 if (Tile and fUnit <> 0) and (Loc <> AttLoc) and … … 1259 1259 UnitInfo.Health := DefHealth; 1260 1260 if (UnitInfo.Owner <> CityOwner) and 1261 not((CityOwner = me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance))1261 not((CityOwner = Me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance)) 1262 1262 then 1263 1263 {$IFNDEF SCR} if (UnFocus >= 0) and (Loc = MyUn[UnFocus].Loc) then { active unit } 1264 1264 begin 1265 1265 Multi := UnitInfo.Flags and unMulti; 1266 MakeUnitInfo( me, MyUn[UnFocus], UnitInfo);1266 MakeUnitInfo(Me, MyUn[UnFocus], UnitInfo); 1267 1267 UnitInfo.Flags := UnitInfo.Flags or Multi; 1268 PaintUnit( x + (xxt - xxu), y+ (yyt - yyu_anchor), UnitInfo,1268 PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 1269 1269 MyUn[UnFocus].Status); 1270 1270 end 1271 else if UnitInfo.Owner = me then1271 else if UnitInfo.Owner = Me then 1272 1272 begin 1273 1273 if ClientMode = cMovieTurn then 1274 PaintUnit( x + (xxt - xxu), y+ (yyt - yyu_anchor), UnitInfo, 0)1274 PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0) 1275 1275 // status is not set with precise timing during loading 1276 1276 else 1277 PaintUnit( x + (xxt - xxu), y+ (yyt - yyu_anchor), UnitInfo,1277 PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 1278 1278 MyUn[uix].Status); 1279 1279 // if Showuix then Textout(x+16,y+5,$80FF00,IntToStr(uix)); 1280 1280 end 1281 else {$ENDIF} PaintUnit( x + (xxt - xxu), y+ (yyt - yyu_anchor), UnitInfo, 0);1281 else {$ENDIF} PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0); 1282 1282 end 1283 1283 else if Tile and fHiddenUnit <> 0 then 1284 Sprite(HGrStdUnits, x + (xxt - xxu), y+ (yyt - yyu_anchor), xxu * 2,1284 Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2, 1285 1285 yyu * 2, 1 + 5 * (xxu * 2 + 1), 1) 1286 1286 else if Tile and fStealthUnit <> 0 then 1287 Sprite(HGrStdUnits, x + (xxt - xxu), y+ (yyt - yyu_anchor), xxu * 2,1287 Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2, 1288 1288 yyu * 2, 1 + 5 * (xxu * 2 + 1), 1 + 1 * (yyu * 2 + 1)) 1289 1289 end; … … 1291 1291 if ShowObjects and (Tile and fTerImp = tiFort) and (Tile and fObserved <> 0) 1292 1292 then 1293 TSprite( x, y, spFortFront);1293 TSprite(X, Y, spFortFront); 1294 1294 1295 1295 if (Loc >= 0) and (Loc < G.lx * G.ly) then 1296 1296 if ShowLoc then 1297 Textout( x + xxt - 16, y+ yyt - 9, $FFFF00, IntToStr(Loc))1297 Textout(X + xxt - 16, Y + yyt - 9, $FFFF00, IntToStr(Loc)) 1298 1298 else if ShowDebug and (DebugMap <> nil) and (Loc >= 0) and 1299 1299 (Loc < G.lx * G.ly) and (DebugMap[Loc] <> 0) then 1300 Textout( x + xxt - 16, y+ yyt - 9, $00E0FF,1301 IntToStr( integer(DebugMap[Loc])))1302 end; 1303 1304 procedure TIsoMap.PaintGrid( x, y, nx, ny: integer);1305 1306 procedure ClippedLine(dx0, dy0: integer; mirror: boolean);1300 Textout(X + xxt - 16, Y + yyt - 9, $00E0FF, 1301 IntToStr(Integer(DebugMap[Loc]))) 1302 end; 1303 1304 procedure TIsoMap.PaintGrid(X, Y, nx, ny: Integer); 1305 1306 procedure ClippedLine(dx0, dy0: Integer; mirror: Boolean); 1307 1307 var 1308 x0, x1, dxmin, dymin, dxmax, dymax, n: integer;1308 x0, x1, dxmin, dymin, dxmax, dymax, N: Integer; 1309 1309 begin 1310 1310 with FOutput.Canvas do 1311 1311 begin 1312 dxmin := (FLeft - x) div xxt;1313 dymin := (RealTop - y) div yyt;1314 dxmax := (FRight - x- 1) div xxt + 1;1315 dymax := (RealBottom - y- 1) div yyt + 1;1316 n:= dymax - dy0;1312 dxmin := (FLeft - X) div xxt; 1313 dymin := (RealTop - Y) div yyt; 1314 dxmax := (FRight - X - 1) div xxt + 1; 1315 dymax := (RealBottom - Y - 1) div yyt + 1; 1316 N := dymax - dy0; 1317 1317 if mirror then 1318 1318 begin 1319 if dx0 - dxmin < nthen1320 n:= dx0 - dxmin;1319 if dx0 - dxmin < N then 1320 N := dx0 - dxmin; 1321 1321 if dx0 > dxmax then 1322 1322 begin 1323 n := n- (dx0 - dxmax);1323 N := N - (dx0 - dxmax); 1324 1324 dy0 := dy0 + (dx0 - dxmax); 1325 1325 dx0 := dxmax … … 1327 1327 if dy0 < dymin then 1328 1328 begin 1329 n := n- (dymin - dy0);1329 N := N - (dymin - dy0); 1330 1330 dx0 := dx0 - (dymin - dy0); 1331 1331 dy0 := dymin … … 1334 1334 else 1335 1335 begin 1336 if dxmax - dx0 < nthen1337 n:= dxmax - dx0;1336 if dxmax - dx0 < N then 1337 N := dxmax - dx0; 1338 1338 if dx0 < dxmin then 1339 1339 begin 1340 n := n- (dxmin - dx0);1340 N := N - (dxmin - dx0); 1341 1341 dy0 := dy0 + (dxmin - dx0); 1342 1342 dx0 := dxmin … … 1344 1344 if dy0 < dymin then 1345 1345 begin 1346 n := n- (dymin - dy0);1346 N := N - (dymin - dy0); 1347 1347 dx0 := dx0 + (dymin - dy0); 1348 1348 dy0 := dymin 1349 1349 end; 1350 1350 end; 1351 if n<= 0 then1352 exit;1351 if N <= 0 then 1352 Exit; 1353 1353 if mirror then 1354 1354 begin 1355 x0 := x+ dx0 * xxt - 1;1356 x1 := x + (dx0 - n) * xxt - 1;1355 x0 := X + dx0 * xxt - 1; 1356 x1 := X + (dx0 - N) * xxt - 1; 1357 1357 end 1358 1358 else 1359 1359 begin 1360 x0 := x+ dx0 * xxt;1361 x1 := x + (dx0 + n) * xxt;1360 x0 := X + dx0 * xxt; 1361 x1 := X + (dx0 + N) * xxt; 1362 1362 end; 1363 moveto(x0, y+ dy0 * yyt);1364 lineto(x1, y + (dy0 + n) * yyt);1363 moveto(x0, Y + dy0 * yyt); 1364 lineto(x1, Y + (dy0 + N) * yyt); 1365 1365 end; 1366 1366 end; 1367 1367 1368 1368 var 1369 i: integer;1369 I: Integer; 1370 1370 begin 1371 1371 FOutput.Canvas.pen.Color := $000000; // $FF shl (8*random(3)); 1372 for i:= 0 to nx div 2 do1373 ClippedLine( i * 2, 0, false);1374 for i:= 1 to (nx + 1) div 2 do1375 ClippedLine( i * 2, 0, true);1376 for i:= 0 to ny div 2 do1377 begin 1378 ClippedLine(0, 2 * i + 2, false);1379 ClippedLine(nx + 1, 2 * i + 1 + nx and 1, true);1380 end; 1381 end; 1382 1383 function TIsoMap.IsShoreTile(Loc: integer): boolean;1372 for I := 0 to nx div 2 do 1373 ClippedLine(I * 2, 0, False); 1374 for I := 1 to (nx + 1) div 2 do 1375 ClippedLine(I * 2, 0, True); 1376 for I := 0 to ny div 2 do 1377 begin 1378 ClippedLine(0, 2 * I + 2, False); 1379 ClippedLine(nx + 1, 2 * I + 1 + nx and 1, True); 1380 end; 1381 end; 1382 1383 function TIsoMap.IsShoreTile(Loc: Integer): Boolean; 1384 1384 var 1385 1385 Dir: Integer; 1386 ConnLoc: integer;1387 begin 1388 result := false;1386 ConnLoc: Integer; 1387 begin 1388 Result := False; 1389 1389 for Dir := 0 to 7 do 1390 1390 begin … … 1392 1392 if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or 1393 1393 ((MyMap[ConnLoc] - 2) and fTerrain < 13) then 1394 result := true;1394 Result := True; 1395 1395 end; 1396 1396 end; … … 1401 1401 begin 1402 1402 for I := 0 to Length - 1 do begin 1403 Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7 f;1404 Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7 f;1405 Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7 f;1403 Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7F; 1404 Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7F; 1405 Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7F; 1406 1406 Line^.NextPixel; 1407 1407 end; … … 1415 1415 end; 1416 1416 1417 procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: integer);1417 procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: Integer); 1418 1418 const 1419 1419 rShade = 3.75; 1420 1420 var 1421 y, wBright: integer;1422 y_n, w_n: single;1421 Y, wBright: Integer; 1422 y_n, w_n: Single; 1423 1423 Line: TPixelPointer; 1424 1424 begin 1425 1425 FOutput.BeginUpdate; 1426 1426 Line := PixelPointer(FOutput, ScaleToNative(x0), ScaleToNative(y0)); 1427 for y:= 0 to ScaleToNative(Height) - 1 do begin1428 y_n := (ScaleFromNative( y) + y0 - ym) / yyt;1427 for Y := 0 to ScaleToNative(Height) - 1 do begin 1428 y_n := (ScaleFromNative(Y) + y0 - ym) / yyt; 1429 1429 if abs(y_n) < rShade then begin 1430 1430 // Darken left and right parts of elipsis … … 1445 1445 end; 1446 1446 1447 procedure TIsoMap.CityGrid(xm, ym: integer; CityAllowClick: Boolean);1448 var 1449 i: integer;1447 procedure TIsoMap.CityGrid(xm, ym: Integer; CityAllowClick: Boolean); 1448 var 1449 I: Integer; 1450 1450 begin 1451 1451 with FOutput.Canvas do … … 1456 1456 pen.Color := $000000; 1457 1457 pen.Width := 1; 1458 for i:= 0 to 3 do1458 for I := 0 to 3 do 1459 1459 begin 1460 moveto(xm - xxt * (4 - i), ym + yyt * (1 + i));1461 lineto(xm + xxt * (1 + i), ym - yyt * (4 - i));1462 moveto(xm - xxt * (4 - i), ym - yyt * (1 + i));1463 lineto(xm + xxt * (1 + i), ym + yyt * (4 - i));1460 moveto(xm - xxt * (4 - I), ym + yyt * (1 + I)); 1461 lineto(xm + xxt * (1 + I), ym - yyt * (4 - I)); 1462 moveto(xm - xxt * (4 - I), ym - yyt * (1 + I)); 1463 lineto(xm + xxt * (1 + I), ym + yyt * (4 - I)); 1464 1464 end; 1465 1465 moveto(xm - xxt * 4, ym + yyt * 1); … … 1475 1475 end; 1476 1476 1477 procedure TIsoMap.Paint( x, y, Loc, nx, ny, CityLoc, CityOwner: integer;1478 UseBlink: boolean; CityAllowClick: boolean);1479 var 1480 dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: integer;1481 begin 1482 FoW := true;1477 procedure TIsoMap.Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer; 1478 UseBlink: Boolean; CityAllowClick: Boolean); 1479 var 1480 dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: Integer; 1481 begin 1482 FoW := True; 1483 1483 ShowLoc := moLocCodes in MapOptions; 1484 1484 ShowDebug := pDebugMap >= 0; … … 1486 1486 ShowCityNames := ShowObjects and (CityOwner < 0) and 1487 1487 (moCityNames in MapOptions); 1488 ShowBorder := true;1488 ShowBorder := True; 1489 1489 ShowMyBorder := CityOwner < 0; 1490 1490 ShowGrWall := (CityOwner < 0) and (moGreatWall in MapOptions); 1491 1491 if ShowDebug then 1492 Server(sGetDebugMap, me, pDebugMap, DebugMap)1492 Server(sGetDebugMap, Me, pDebugMap, DebugMap) 1493 1493 else 1494 1494 DebugMap := nil; 1495 1495 with FOutput.Canvas do 1496 1496 begin 1497 RealTop := y- ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt;1498 RealBottom := y+ (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) +1497 RealTop := Y - ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt; 1498 RealBottom := Y + (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) + 1499 1499 3) * yyt; 1500 1500 Brush.Color := EmptySpaceColor; … … 1573 1573 bix := 0; 1574 1574 end; 1575 BitBltBitmap(OceanPatch, x + dx * xxt, y+ dy * yyt, xxt, yyt,1575 BitBltBitmap(OceanPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt, 1576 1576 Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY) 1577 1577 end … … 1621 1621 bix := Aix; 1622 1622 if Aix = -1 then 1623 BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y+ dy * yyt, xxt,1623 BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt, 1624 1624 yyt, 1 + 6 * (xxt * 2 + 1) + (dx + dy + 1) and 1 * xxt, 1 + yyt, 1625 1625 SRCCOPY) // arctic <-> ocean 1626 1626 else if bix = -1 then 1627 BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y+ dy * yyt, xxt,1627 BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt, 1628 1628 yyt, 1 + 6 * (xxt * 2 + 1) + xxt - (dx + dy + 1) and 1 * xxt, 1629 1629 1 + yyt * 2, SRCCOPY) // arctic <-> ocean 1630 1630 else 1631 BitBltBitmap(LandPatch, x + dx * xxt, y+ dy * yyt, xxt, yyt,1631 BitBltBitmap(LandPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt, 1632 1632 Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY) 1633 1633 end; … … 1639 1639 for dx := -1 to nx do 1640 1640 if (dx + dy) and 1 = 0 then 1641 PaintShore( x + xxt * dx, y+ yyt + yyt * dy, dLoc(Loc, dx, dy));1641 PaintShore(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy)); 1642 1642 for dy := -2 to ny + 1 do 1643 1643 for dx := -1 to nx do 1644 1644 if (dx + dy) and 1 = 0 then 1645 PaintTileExtraTerrain( x + xxt * dx, y+ yyt + yyt * dy,1645 PaintTileExtraTerrain(X + xxt * dx, Y + yyt + yyt * dy, 1646 1646 dLoc(Loc, dx, dy)); 1647 1647 if CityOwner >= 0 then … … 1653 1653 ALoc := dLoc(Loc, dx, dy); 1654 1654 if Distance(ALoc, CityLoc) > 5 then 1655 PaintTileObjects( x + xxt * dx, y+ yyt + yyt * dy, ALoc, CityLoc,1655 PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc, 1656 1656 CityOwner, UseBlink); 1657 1657 end; … … 1660 1660 * G.lx) mod (2 * G.lx) - G.lx; 1661 1661 dy := CityLoc div G.lx - (Loc + 666 * G.lx) div G.lx + 666; 1662 xm := x+ (dx + 1) * xxt;1663 ym := y+ (dy + 1) * yyt + yyt;1662 xm := X + (dx + 1) * xxt; 1663 ym := Y + (dy + 1) * yyt + yyt; 1664 1664 ShadeOutside(FLeft, FTop, FRight - FLeft, FBottom - FTop, xm, ym); 1665 1665 CityGrid(xm, ym, CityAllowClick); … … 1670 1670 ALoc := dLoc(Loc, dx, dy); 1671 1671 if Distance(ALoc, CityLoc) <= 5 then 1672 PaintTileObjects( x + xxt * dx, y+ yyt + yyt * dy, ALoc, CityLoc,1672 PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc, 1673 1673 CityOwner, UseBlink); 1674 1674 end; … … 1678 1678 if ShowLoc or (moEditMode in MapOptions) or 1679 1679 (moGrid in MapOptions) then 1680 PaintGrid( x, y, nx, ny);1680 PaintGrid(X, Y, nx, ny); 1681 1681 for dy := -2 to ny + 1 do 1682 1682 for dx := -2 to nx + 1 do 1683 1683 if (dx + dy) and 1 = 0 then 1684 PaintTileObjects( x + xxt * dx, y+ yyt + yyt * dy, dLoc(Loc, dx, dy),1684 PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy), 1685 1685 CityLoc, CityOwner, UseBlink); 1686 1686 end; -
trunk/LocalPlayer/LocalPlayer.pas
r364 r447 4 4 interface 5 5 6 procedure Client(Command, Player: integer; var Data); stdcall;7 procedure SetAIName( p: integer; Name: string);6 procedure Client(Command, Player: Integer; var Data); stdcall; 7 procedure SetAIName(P: Integer; Name: string); 8 8 9 9 implementation … … 14 14 15 15 var 16 FormsCreated: boolean;16 FormsCreated: Boolean; 17 17 18 procedure Client(Command, Player: integer; var Data);18 procedure Client(Command, Player: Integer; var Data); 19 19 begin 20 20 if not FormsCreated then 21 21 begin 22 FormsCreated := true;22 FormsCreated := True; 23 23 // TODO: Changing application name in runtime will cause change of Linux XML registry file path 24 24 // Application.MainForm := MainScreen; … … 45 45 end; 46 46 47 procedure SetAIName( p: integer; Name: string);47 procedure SetAIName(P: Integer; Name: string); 48 48 begin 49 MainScreen.SetAIName( p, Name);49 MainScreen.SetAIName(P, Name); 50 50 end; 51 51 52 52 initialization 53 53 54 FormsCreated := false;54 FormsCreated := False; 55 55 56 56 end. -
trunk/LocalPlayer/MessgEx.pas
r442 r447 39 39 IconKind: TMessageIconKind; 40 40 OpenSound: string; 41 function ShowModal: integer; override;41 function ShowModal: Integer; override; 42 42 procedure CancelMovie; 43 43 private 44 MovieCancelled: boolean;45 procedure PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);44 MovieCancelled: Boolean; 45 procedure PaintBook(ca: TCanvas; X, Y, clPage, clCover: Integer); 46 46 procedure PaintMyArmy; 47 47 procedure PaintEnemyArmy; … … 53 53 54 54 procedure SoundMessageEx(SimpleText, SoundItem: string); 55 procedure TribeMessage( p: integer; SimpleText, SoundItem: string);55 procedure TribeMessage(P: Integer; SimpleText, SoundItem: string); 56 56 function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string) 57 : integer;57 : Integer; 58 58 procedure ContextMessage(SimpleText, SoundItem: string; 59 ContextKind, ContextNo: integer);59 ContextKind, ContextNo: Integer); 60 60 61 61 … … 81 81 procedure TMessgExDlg.FormShow(Sender: TObject); 82 82 var 83 i: integer;83 I: Integer; 84 84 begin 85 85 if IconKind = mikEnemyArmy then … … 150 150 end; 151 151 152 SplitText( true);152 SplitText(True); 153 153 ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing; 154 154 if GameMode = cMovie then … … 181 181 end; 182 182 end; 183 for i:= 0 to ControlCount - 1 do184 Controls[ i].Top := ClientHeight - (34 + Border);183 for I := 0 to ControlCount - 1 do 184 Controls[I].Top := ClientHeight - (34 + Border); 185 185 if Kind = mkModel then 186 186 EInput.Top := ClientHeight - (76 + Border); 187 187 end; 188 188 189 function TMessgExDlg.ShowModal: integer;189 function TMessgExDlg.ShowModal: Integer; 190 190 var 191 191 Ticks0: TDateTime; … … 197 197 if not((GameMode = cMovie) and (MovieSpeed = 4)) then 198 198 begin 199 MovieCancelled := false;199 MovieCancelled := False; 200 200 Show; 201 201 Ticks0 := NowPrecise; … … 207 207 Hide; 208 208 end; 209 result := mrOk;209 Result := mrOk; 210 210 end 211 211 else 212 result := inherited;212 Result := inherited; 213 213 Gtk2Fix; 214 214 end; … … 216 216 procedure TMessgExDlg.CancelMovie; 217 217 begin 218 MovieCancelled := true;219 end; 220 221 procedure TMessgExDlg.PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);218 MovieCancelled := True; 219 end; 220 221 procedure TMessgExDlg.PaintBook(ca: TCanvas; X, Y, clPage, clCover: Integer); 222 222 const 223 223 xScrewed = 77; … … 228 228 TScrewed = array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of Single; 229 229 var 230 ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: integer;230 ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: Integer; 231 231 BookRect: TRect; 232 x1, xR, yR, share: single;232 x1, xR, yR, share: Single; 233 233 Screwed: TScrewed; 234 234 SrcPtr: TPixelPointer; … … 284 284 BookRect := SmallBook.BoundsRect; 285 285 end; 286 x := x- BookRect.Width div 2;286 X := X - BookRect.Width div 2; 287 287 288 288 // paint 289 289 UnshareBitmap(LogoBuffer); 290 BitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, x, y);290 BitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, X, Y); 291 291 292 292 if IconIndex >= 0 then … … 301 301 ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), BookRect, clCover, clPage); 302 302 303 BitBltCanvas(ca, x, y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);303 BitBltCanvas(ca, X, Y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0); 304 304 end; 305 305 … … 310 310 procedure TMessgExDlg.PaintEnemyArmy; 311 311 var 312 emix, ix, iy, x, y, count, UnitsInLine: integer;312 emix, ix, iy, X, Y, count, UnitsInLine: Integer; 313 313 begin 314 314 ix := 0; … … 321 321 for count := 0 to LostArmy[emix] - 1 do 322 322 begin 323 x:= ClientWidth div 2 + ix * 64 - UnitsInLine * 32;324 y:= 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;323 X := ClientWidth div 2 + ix * 64 - UnitsInLine * 32; 324 Y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48; 325 325 with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do 326 326 begin 327 BitBltCanvas(Canvas, x, y, 64, 48, HGr.Mask.Canvas,327 BitBltCanvas(Canvas, X, Y, 64, 48, HGr.Mask.Canvas, 328 328 pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND); 329 BitBltCanvas(Canvas, x, y, 64, 48, HGr.Data.Canvas,329 BitBltCanvas(Canvas, X, Y, 64, 48, HGr.Data.Canvas, 330 330 pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT); 331 331 end; 332 332 333 333 // next position 334 inc(ix);334 Inc(ix); 335 335 if ix = LostUnitsPerLine then 336 336 begin // next line 337 337 ix := 0; 338 inc(iy);338 Inc(iy); 339 339 if iy = 6 then 340 exit;340 Exit; 341 341 UnitsInLine := nLostArmy - LostUnitsPerLine * iy; 342 342 if UnitsInLine > LostUnitsPerLine then … … 348 348 procedure TMessgExDlg.FormPaint(Sender: TObject); 349 349 var 350 p1, clSaveTextLight, clSaveTextShade: integer;350 p1, clSaveTextLight, clSaveTextShade: Integer; 351 351 begin 352 352 if (IconKind = mikImp) and (IconIndex = 27) then … … 394 394 end; 395 395 mikModel: 396 with Tribe[ me].ModelPicture[IconIndex] do396 with Tribe[Me].ModelPicture[IconIndex] do 397 397 begin 398 398 FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig, … … 498 498 end; 499 499 500 procedure TribeMessage( p: integer; SimpleText, SoundItem: string);500 procedure TribeMessage(P: Integer; SimpleText, SoundItem: string); 501 501 begin 502 502 with MessgExDlg do … … 506 506 Kind := mkOk; 507 507 IconKind := mikTribe; 508 IconIndex := p;508 IconIndex := P; 509 509 ShowModal; 510 510 end; … … 512 512 513 513 function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string) 514 : integer;514 : Integer; 515 515 begin 516 516 with MessgExDlg do … … 520 520 Kind := QueryKind; 521 521 ShowModal; 522 result := ModalResult;522 Result := ModalResult; 523 523 end; 524 524 end; 525 525 526 526 procedure ContextMessage(SimpleText, SoundItem: string; 527 ContextKind, ContextNo: integer);527 ContextKind, ContextNo: Integer); 528 528 begin 529 529 with MessgExDlg do -
trunk/LocalPlayer/NatStat.pas
r442 r447 25 25 procedure ToggleBtnClick(Sender: TObject); 26 26 procedure PlayerClick(Sender: TObject); 27 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);27 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 28 28 procedure FormDestroy(Sender: TObject); 29 29 procedure ScrollUpBtnClick(Sender: TObject); … … 32 32 public 33 33 procedure CheckAge; 34 procedure ShowNewContent(NewMode: TWindowMode; p: integer = -1);34 procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1); 35 35 procedure EcoChange; 36 36 protected 37 37 procedure OffscreenPaint; override; 38 38 private 39 pView, AgePrepared, LinesDown: integer;39 pView, AgePrepared, LinesDown: Integer; 40 40 SelfReport, CurrentReport: PEnemyReport; 41 ShowContact, ContactEnabled: boolean;41 ShowContact, ContactEnabled: Boolean; 42 42 Back, Template: TBitmap; 43 43 ReportText: TStringList; … … 114 114 procedure TNatStatDlg.FormShow(Sender: TObject); 115 115 begin 116 if pView = me then116 if pView = Me then 117 117 begin 118 118 SelfReport.TurnOfCivilReport := MyRO.Turn; 119 119 SelfReport.TurnOfMilReport := MyRO.Turn; 120 move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));120 Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty)); 121 121 SelfReport.Government := MyRO.Government; 122 122 SelfReport.Money := MyRO.Money; 123 CurrentReport := pointer(SelfReport);123 CurrentReport := Pointer(SelfReport); 124 124 end 125 125 else 126 CurrentReport := pointer(MyRO.EnemyReport[pView]);126 CurrentReport := Pointer(MyRO.EnemyReport[pView]); 127 127 if CurrentReport.TurnOfCivilReport >= 0 then 128 128 GenerateReportText; 129 ShowContact := (pView <> me) and (not supervising or (me <> 0));130 ContactEnabled := ShowContact and not supervising and129 ShowContact := (pView <> Me) and (not Supervising or (Me <> 0)); 130 ContactEnabled := ShowContact and not Supervising and 131 131 (1 shl pView and MyRO.Alive <> 0); 132 132 ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and … … 146 146 end; 147 147 148 procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; p: integer);149 begin 150 if p< 0 then148 procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer); 149 begin 150 if P < 0 then 151 151 if ClientMode >= scContact then 152 pView := DipMem[ me].pContact152 pView := DipMem[Me].pContact 153 153 else 154 154 begin … … 156 156 while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or 157 157 (1 shl pView and MyRO.Alive = 0)) do 158 inc(pView);158 Inc(pView); 159 159 if pView >= nPl then 160 pView := me;160 pView := Me; 161 161 end 162 162 else 163 pView := p;163 pView := P; 164 164 inherited ShowNewContent(NewMode); 165 165 end; … … 174 174 List: ^TChart; 175 175 176 function StatText(no: integer): string;176 function StatText(no: Integer): string; 177 177 var 178 i: integer;178 I: Integer; 179 179 begin 180 180 if (CurrentReport.TurnOfCivilReport >= 0) and 181 (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then181 (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then 182 182 begin 183 i:= List[CurrentReport.TurnOfCivilReport];183 I := List[CurrentReport.TurnOfCivilReport]; 184 184 case no of 185 185 stPop: 186 result := Format(Phrases.Lookup('FRSTATPOP'), [i]);186 Result := Format(Phrases.Lookup('FRSTATPOP'), [I]); 187 187 stTerritory: 188 result := Format(Phrases.Lookup('FRSTATTER'), [i]);188 Result := Format(Phrases.Lookup('FRSTATTER'), [I]); 189 189 stScience: 190 result := Format(Phrases.Lookup('FRSTATTECH'), [idiv nAdv]);190 Result := Format(Phrases.Lookup('FRSTATTECH'), [I div nAdv]); 191 191 stExplore: 192 result := Format(Phrases.Lookup('FRSTATEXP'),193 [ i* 100 div (G.lx * G.ly)]);192 Result := Format(Phrases.Lookup('FRSTATEXP'), 193 [I * 100 div (G.lx * G.ly)]); 194 194 end; 195 195 end … … 197 197 198 198 var 199 p1, Treaty: integer;200 s: string;201 HasContact, ExtinctPart: boolean;199 p1, Treaty: Integer; 200 S: string; 201 HasContact, ExtinctPart: Boolean; 202 202 begin 203 203 GetMem(List, 4 * (MyRO.Turn + 2)); … … 208 208 (1 shl pView and MyRO.Alive <> 0) then 209 209 begin 210 s:= Format(Phrases.Lookup('FROLDCIVILREP'),210 S := Format(Phrases.Lookup('FROLDCIVILREP'), 211 211 [TurnToString(CurrentReport.TurnOfCivilReport)]); 212 ReportText.Add('C' + s);212 ReportText.Add('C' + S); 213 213 ReportText.Add(''); 214 214 end; … … 223 223 ReportText.Add('S' + StatText(stScience)); 224 224 ReportText.Add('E' + StatText(stExplore)); 225 HasContact := false;225 HasContact := False; 226 226 for p1 := 0 to nPl - 1 do 227 if (p1 <> me) and (CurrentReport.Treaty[p1] > trNoContact) then228 HasContact := true;227 if (p1 <> Me) and (CurrentReport.Treaty[p1] > trNoContact) then 228 HasContact := True; 229 229 if HasContact then 230 230 begin 231 231 ReportText.Add(''); 232 232 ReportText.Add(' ' + Phrases.Lookup('FRRELATIONS')); 233 for ExtinctPart := false to true do233 for ExtinctPart := False to True do 234 234 for Treaty := trAlliance downto trNone do 235 235 for p1 := 0 to nPl - 1 do 236 if (p1 <> me) and (CurrentReport.Treaty[p1] = Treaty) and236 if (p1 <> Me) and (CurrentReport.Treaty[p1] = Treaty) and 237 237 ((1 shl p1 and MyRO.Alive = 0) = ExtinctPart) then 238 238 begin 239 s:= Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));239 S := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty)); 240 240 if ExtinctPart then 241 s := '(' + s+ ')';242 ReportText.Add(char(48 + Treaty) + s);241 S := '(' + S + ')'; 242 ReportText.Add(char(48 + Treaty) + S); 243 243 end; 244 244 end; … … 250 250 procedure TNatStatDlg.OffscreenPaint; 251 251 var 252 i, y: integer;253 s: string;254 ps: pchar;255 Extinct: boolean;252 I, Y: Integer; 253 S: string; 254 ps: PChar; 255 Extinct: Boolean; 256 256 257 257 begin … … 260 260 Extinct := 1 shl pView and MyRO.Alive = 0; 261 261 262 BitBltCanvas( offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,262 BitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight, 263 263 Back.Canvas, 0, 0); 264 264 265 offscreen.Canvas.Font.Assign(UniFont[ftCaption]);266 RisedTextout( offscreen.Canvas,265 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 266 RisedTextout(Offscreen.Canvas, 267 267 40 { (ClientWidth-BiColorTextWidth(offscreen.canvas,caption)) div 2 } , 268 268 7, Caption); 269 269 270 offscreen.Canvas.Font.Assign(UniFont[ftNormal]);271 272 with offscreen do270 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 271 272 with Offscreen do 273 273 begin 274 274 // show leader picture … … 276 276 if Assigned(Tribe[pView].faceHGr) then 277 277 begin 278 Dump( offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,278 Dump(Offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48, 279 279 1 + Tribe[pView].facepix mod 10 * 65, 280 280 1 + Tribe[pView].facepix div 10 * 49); 281 frame( offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,281 frame(Offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48, 282 282 $000000, $000000); 283 283 end; 284 284 285 if (pView = me) or not Extinct then285 if (pView = Me) or not Extinct then 286 286 LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib, 287 287 Phrases.Lookup('GOVERNMENT', CurrentReport.Government) + 288 288 Phrases.Lookup('FRAND')); 289 if pView = me then289 if pView = Me then 290 290 begin 291 291 LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19, … … 314 314 if MyRO.Treaty[pView] = trNoContact then 315 315 begin 316 s:= Phrases.Lookup('FRNOCONTACT');316 S := Phrases.Lookup('FRNOCONTACT'); 317 317 LoweredTextOut(Canvas, -1, MainTexture, 318 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, yRelation + 9, s);318 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, yRelation + 9, S); 319 319 end 320 320 else if ShowContact then … … 340 340 FrameImage(Canvas, BigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200) 341 341 { else if CurrentReport.Government=gAnarchy then 342 FrameImage( canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,342 FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400, 343 343 ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) 344 344 else 345 FrameImage( canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,345 FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig, 346 346 56*(CurrentReport.Government-1),40, 347 347 ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) }; … … 361 361 end; 362 362 363 y:= 0;364 for i:= 0 to ReportText.Count - 1 do365 begin 366 if ( i >= LinesDown) and (i< LinesDown + ReportLines) then363 Y := 0; 364 for I := 0 to ReportText.Count - 1 do 365 begin 366 if (I >= LinesDown) and (I < LinesDown + ReportLines) then 367 367 begin 368 s := ReportText[i];369 if s<> '' then368 S := ReportText[I]; 369 if S <> '' then 370 370 begin 371 371 // LineType:=s[1]; 372 delete(s, 1, 1);372 Delete(S, 1, 1); 373 373 BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkMisc, cliPaperText], 374 $7F007F, xReport + 8, yReport + LineSpacing * y, s);374 $7F007F, xReport + 8, yReport + LineSpacing * Y, S); 375 375 end; 376 inc(y);376 Inc(Y); 377 377 end; 378 378 end; … … 380 380 else 381 381 begin 382 s:= Phrases.Lookup('FRNOCIVILREP');383 RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,384 yReport + hReport div 2 - 10, s);382 S := Phrases.Lookup('FRNOCIVILREP'); 383 RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 384 yReport + hReport div 2 - 10, S); 385 385 end; 386 386 387 387 if soTellAI in OptionChecked then begin 388 Server(sGetAIInfo, me, pView, ps);388 Server(sGetAIInfo, Me, pView, ps); 389 389 LoweredTextOut(Canvas, -1, MainTexture, 42, 445, ps); 390 390 end else … … 392 392 Phrases2.Lookup('MENU_TELLAI')); 393 393 end; 394 ContactBtn.SetBack( offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);394 ContactBtn.SetBack(Offscreen.Canvas, ContactBtn.Left, ContactBtn.Top); 395 395 396 396 MarkUsedOffscreen(ClientWidth, ClientHeight); … … 404 404 procedure TNatStatDlg.DialogBtnClick(Sender: TObject); 405 405 var 406 ContactResult: integer;406 ContactResult: Integer; 407 407 begin 408 408 ContactResult := MainScreen.DipCall(scContact + pView shl 4); … … 412 412 SoundMessage(Phrases.Lookup('FRCOLDWAR'), 'MSG_DEFAULT') 413 413 else if MyRO.Government = gAnarchy then 414 SoundMessage(Tribe[ me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')414 SoundMessage(Tribe[Me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT') 415 415 else if ContactResult = eAnarchy then 416 416 if MyRO.Treaty[pView] >= trPeace then … … 428 428 procedure TNatStatDlg.ToggleBtnClick(Sender: TObject); 429 429 var 430 p1, StartCount: integer;431 m: TMenuItem;432 ExtinctPart: boolean;430 p1, StartCount: Integer; 431 M: TMenuItem; 432 ExtinctPart: Boolean; 433 433 begin 434 434 EmptyMenu(Popup.Items); 435 435 436 436 // own nation 437 if G.Difficulty[ me] <> 0 then438 begin 439 m:= TMenuItem.Create(Popup);440 m.RadioItem := true;441 m.Caption := Tribe[me].TPhrase('TITLE_NATION');442 m.Tag := me;443 m.OnClick := PlayerClick;444 if me = pView then445 m.Checked := true;446 Popup.Items.Add( m);437 if G.Difficulty[Me] <> 0 then 438 begin 439 M := TMenuItem.Create(Popup); 440 M.RadioItem := True; 441 M.Caption := Tribe[Me].TPhrase('TITLE_NATION'); 442 M.Tag := Me; 443 M.OnClick := PlayerClick; 444 if Me = pView then 445 M.Checked := True; 446 Popup.Items.Add(M); 447 447 end; 448 448 449 449 // foreign nations 450 for ExtinctPart := false to true do450 for ExtinctPart := False to True do 451 451 begin 452 452 StartCount := Popup.Items.Count; … … 456 456 (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] >= trNone) then 457 457 begin 458 m:= TMenuItem.Create(Popup);459 m.RadioItem := true;460 m.Caption := Tribe[p1].TPhrase('TITLE_NATION');458 M := TMenuItem.Create(Popup); 459 M.RadioItem := True; 460 M.Caption := Tribe[p1].TPhrase('TITLE_NATION'); 461 461 if ExtinctPart then 462 m.Caption := '(' + m.Caption + ')';463 m.Tag := p1;464 m.OnClick := PlayerClick;462 M.Caption := '(' + M.Caption + ')'; 463 M.Tag := p1; 464 M.OnClick := PlayerClick; 465 465 if p1 = pView then 466 m.Checked := true;467 Popup.Items.Add( m);466 M.Checked := True; 467 Popup.Items.Add(M); 468 468 end; 469 469 if (StartCount > 0) and (Popup.Items.Count > StartCount) then 470 470 begin // seperator 471 m:= TMenuItem.Create(Popup);472 m.Caption := '-';473 Popup.Items.Insert(StartCount, m);471 M := TMenuItem.Create(Popup); 472 M.Caption := '-'; 473 Popup.Items.Insert(StartCount, M); 474 474 end; 475 475 end; … … 478 478 end; 479 479 480 procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: word;480 procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: Word; 481 481 Shift: TShiftState); 482 482 var 483 i: integer;483 I: Integer; 484 484 begin 485 485 if Key = VK_F9 then // my key 486 486 begin // toggle nation 487 i:= 0;487 I := 0; 488 488 repeat 489 489 pView := (pView + 1) mod nPl; 490 inc(i);491 until ( i>= nPl) or (1 shl pView and MyRO.Alive <> 0) and490 Inc(I); 491 until (I >= nPl) or (1 shl pView and MyRO.Alive <> 0) and 492 492 (MyRO.Treaty[pView] >= trNone); 493 if i>= nPl then494 pView := me;493 if I >= nPl then 494 pView := Me; 495 495 Tag := pView; 496 496 PlayerClick(self); // no, this is not nice … … 502 502 procedure TNatStatDlg.EcoChange; 503 503 begin 504 if Visible and (pView = me) then504 if Visible and (pView = Me) then 505 505 begin 506 506 SelfReport.Government := MyRO.Government; … … 514 514 if LinesDown > 0 then 515 515 begin 516 dec(LinesDown);516 Dec(LinesDown); 517 517 SmartUpdateContent; 518 518 end; … … 523 523 if LinesDown + ReportLines < ReportText.Count then 524 524 begin 525 inc(LinesDown);525 Inc(LinesDown); 526 526 SmartUpdateContent; 527 527 end; -
trunk/LocalPlayer/Nego.pas
r442 r447 15 15 type 16 16 THistory = record 17 n: Integer;17 N: Integer; 18 18 Text: array[0 .. MaxHistory - 1] of ansistring; 19 19 end; … … 59 59 procedure FormDestroy(Sender: TObject); 60 60 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 61 Shift: TShiftState; X, Y: integer);61 Shift: TShiftState; X, Y: Integer); 62 62 procedure OkBtnClick(Sender: TObject); 63 63 procedure BwdBtnClick(Sender: TObject); … … 78 78 79 79 private 80 Page, DipCommand: integer;80 Page, DipCommand: Integer; 81 81 CurrentOffer: TOffer; 82 82 MyAllowed, OppoAllowed: TPriceSet; … … 84 84 History: array [0 .. nPl - 1] of THistory; 85 85 RomanFont: TFont; 86 Costs, Delivers: array [0 .. 11] of cardinal;86 Costs, Delivers: array [0 .. 11] of Cardinal; 87 87 procedure ResetCurrentOffer; 88 88 procedure BuildCurrentOffer; 89 89 procedure FindAllowed; 90 90 procedure SplitText(Text: string; Bounds: TRect); 91 procedure PaintNationPicture(X, Y, p: integer);91 procedure PaintNationPicture(X, Y, P: Integer); 92 92 procedure SetButtonStates; 93 93 end; … … 183 183 procedure TNegoDlg.ResetCurrentOffer; 184 184 var 185 i: integer;185 I: Integer; 186 186 begin 187 187 CurrentOffer.nDeliver := 0; 188 188 CurrentOffer.nCost := 0; 189 for i:= 0 to 11 do190 Costs[ i] := $FFFFFFFF;191 for i:= 0 to 11 do192 Delivers[ i] := $FFFFFFFF;189 for I := 0 to 11 do 190 Costs[I] := $FFFFFFFF; 191 for I := 0 to 11 do 192 Delivers[I] := $FFFFFFFF; 193 193 end; 194 194 … … 201 201 else 202 202 PassBtn.SmartHint := Phrases.Lookup('BTN_PASS'); 203 case MyRO.Treaty[DipMem[ me].pContact] of203 case MyRO.Treaty[DipMem[Me].pContact] of 204 204 trNone: 205 205 begin … … 237 237 begin 238 238 if ClientMode <> scDipStart then 239 with History[ me] do240 begin 241 if n= MaxHistory then242 begin 243 move(Text[2], Text[0], (MaxHistory - 2) * sizeof(integer));244 dec(n, 2);239 with History[Me] do 240 begin 241 if N = MaxHistory then 242 begin 243 Move(Text[2], Text[0], (MaxHistory - 2) * SizeOf(Integer)); 244 Dec(N, 2); 245 245 end; 246 Text[ n] := copy(DipCommandToString(DipMem[me].pContact, me,247 DipMem[ me].FormerTreaty, DipMem[me].SentCommand, ClientMode,248 DipMem[ me].SentOffer, ReceivedOffer), 1, 255);249 inc(n);246 Text[N] := Copy(DipCommandToString(DipMem[Me].pContact, Me, 247 DipMem[Me].FormerTreaty, DipMem[Me].SentCommand, ClientMode, 248 DipMem[Me].SentOffer, ReceivedOffer), 1, 255); 249 Inc(N); 250 250 end; 251 assert(History[me].nmod 2 = 1);252 253 Page := History[ me].n;251 Assert(History[Me].N mod 2 = 1); 252 253 Page := History[Me].N; 254 254 FindAllowed; 255 255 ResetCurrentOffer; … … 283 283 procedure TNegoDlg.SplitText(Text: string; Bounds: TRect); 284 284 var 285 nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: integer;286 s: string;287 preview, Dot: boolean;285 nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: Integer; 286 S: string; 287 preview, Dot: Boolean; 288 288 begin 289 289 nLines := 0; 290 for preview := true downto false do290 for preview := True downto False do 291 291 begin 292 292 Start := 1; … … 295 295 while Start < Length(Text) do 296 296 begin 297 Dot := false;297 Dot := False; 298 298 if (Start = 1) or (Text[Start - 1] = '\') then 299 299 if Text[Start] = '-' then 300 300 begin 301 301 Indent := ListIndent; 302 inc(Start);302 Inc(Start); 303 303 if Start = Length(Text) then 304 break;305 Dot := true;304 Break; 305 Dot := True; 306 306 end 307 307 else … … 310 310 while (Stop < Length(Text)) and (Text[Stop] <> '\') do 311 311 begin 312 inc(Stop);312 Inc(Stop); 313 313 if BiColorTextWidth(Offscreen.Canvas, 314 copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -314 Copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left - 315 315 PaperBorder_Left - PaperBorder_Right - Indent then 316 316 begin 317 dec(Stop);318 break317 Dec(Stop); 318 Break 319 319 end; 320 320 end; … … 324 324 while (Text[OrdinaryStop + 1] <> ' ') and 325 325 (Text[OrdinaryStop + 1] <> '\') do 326 dec(OrdinaryStop);326 Dec(OrdinaryStop); 327 327 if (OrdinaryStop + 1 - Start) * 2 >= Stop - Start then 328 328 Stop := OrdinaryStop … … 334 334 Sprite(Offscreen, HGrSystem, Bounds.Left + PaperBorder_Left + 335 335 (ListIndent - 14), Y + 7, 8, 8, 90, 16); 336 s := copy(Text, Start, Stop - Start + 1);336 S := Copy(Text, Start, Stop - Start + 1); 337 337 BiColorTextOut(Offscreen.Canvas, Colors.Canvas.Pixels[clkMisc, 338 338 cliPaperText], $7F007F, Bounds.Left + PaperBorder_Left + 339 Indent, Y, s);339 Indent, Y, S); 340 340 end; 341 inc(Line);341 Inc(Line); 342 342 Start := Stop + 2; 343 343 end; … … 348 348 procedure TNegoDlg.FindAllowed; 349 349 var 350 i: integer;350 I: Integer; 351 351 begin 352 352 CommandAllowed := [scDipOffer - scDipStart]; 353 353 if ClientMode <> scDipBreak then 354 include(CommandAllowed, scDipBreak - scDipStart);355 if MyRO.Treaty[DipMem[ me].pContact] >= trPeace then356 include(CommandAllowed, scDipCancelTreaty - scDipStart);357 if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, me, 0, nil^)354 Include(CommandAllowed, scDipBreak - scDipStart); 355 if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then 356 Include(CommandAllowed, scDipCancelTreaty - scDipStart); 357 if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, Me, 0, nil^) 358 358 >= rExecuted) then 359 include(CommandAllowed, scDipAccept - scDipStart);359 Include(CommandAllowed, scDipAccept - scDipStart); 360 360 361 361 MyAllowed := [opChoose shr 24, opMoney shr 24]; 362 362 OppoAllowed := [opChoose shr 24, opMoney shr 24]; 363 if not IsCivilReportNew(DipMem[ me].pContact) then363 if not IsCivilReportNew(DipMem[Me].pContact) then 364 364 begin // no up-to-date civil report 365 365 MyAllowed := MyAllowed + [opCivilReport shr 24]; 366 for i:= 0 to nAdv - 1 do367 if MyRO.Tech[ i] >= tsApplicable then366 for I := 0 to nAdv - 1 do 367 if MyRO.Tech[I] >= tsApplicable then 368 368 begin 369 369 MyAllowed := MyAllowed + [opAllTech shr 24]; 370 break370 Break 371 371 end; 372 372 OppoAllowed := OppoAllowed + [opCivilReport shr 24, opAllTech shr 24]; … … 374 374 else 375 375 begin // check techs 376 for i:= 0 to nAdv - 1 do377 if not( iin FutureTech) then378 if (MyRO.Tech[ i] < tsSeen) and379 (MyRO.EnemyReport[DipMem[ me].pContact].Tech[i] >= tsApplicable) then376 for I := 0 to nAdv - 1 do 377 if not(I in FutureTech) then 378 if (MyRO.Tech[I] < tsSeen) and 379 (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then 380 380 OppoAllowed := OppoAllowed + [opAllTech shr 24] 381 else if (MyRO.EnemyReport[DipMem[ me].pContact].Tech[i] < tsSeen) and382 (MyRO.Tech[ i] >= tsApplicable) then381 else if (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) and 382 (MyRO.Tech[I] >= tsApplicable) then 383 383 MyAllowed := MyAllowed + [opAllTech shr 24]; 384 384 end; 385 if not IsMilReportNew(DipMem[ me].pContact) then385 if not IsMilReportNew(DipMem[Me].pContact) then 386 386 begin // no up-to-date military report 387 387 MyAllowed := MyAllowed + [opMilReport shr 24]; … … 397 397 OppoAllowed := OppoAllowed + [opAllModel shr 24]; 398 398 end; 399 if MyRO.Treaty[DipMem[ me].pContact] < trAlliance then399 if MyRO.Treaty[DipMem[Me].pContact] < trAlliance then 400 400 begin 401 401 MyAllowed := MyAllowed + [opTreaty shr 24, opMap shr 24]; … … 407 407 OppoAllowed:=OppoAllowed+[opLowTreaty shr 24]; 408 408 end; } 409 for i:= 0 to nShipPart - 1 do410 begin 411 if MyRO.Ship[ me].Parts[i] > 0 then412 include(MyAllowed, opShipParts shr 24);413 if MyRO.Ship[DipMem[ me].pContact].Parts[i] > 0 then414 include(OppoAllowed, opShipParts shr 24);415 end; 416 MyAllowed := MyAllowed - DipMem[ me].DeliveredPrices *409 for I := 0 to nShipPart - 1 do 410 begin 411 if MyRO.Ship[Me].Parts[I] > 0 then 412 Include(MyAllowed, opShipParts shr 24); 413 if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then 414 Include(OppoAllowed, opShipParts shr 24); 415 end; 416 MyAllowed := MyAllowed - DipMem[Me].DeliveredPrices * 417 417 [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24, 418 418 opMilReport shr 24, opMap shr 24]; 419 OppoAllowed := OppoAllowed - DipMem[ me].ReceivedPrices *419 OppoAllowed := OppoAllowed - DipMem[Me].ReceivedPrices * 420 420 [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24, 421 421 opMilReport shr 24, opMap shr 24]; 422 422 end; 423 423 424 procedure TNegoDlg.PaintNationPicture(X, Y, p: integer);424 procedure TNegoDlg.PaintNationPicture(X, Y, P: Integer); 425 425 begin 426 426 with Offscreen.Canvas do 427 427 begin 428 428 Pen.Color := $000000; 429 Brush.Color := Tribe[ p].Color;429 Brush.Color := Tribe[P].Color; 430 430 Rectangle(X - 6, Y - 1, X + 70, Y + 49); 431 431 Brush.Color := $000000; 432 Tribe[ p].InitAge(GetAge(p));433 if Assigned(Tribe[ p].faceHGr) then434 Dump(Offscreen, Tribe[ p].faceHGr, X, Y, 64, 48,435 1 + Tribe[ p].facepix mod 10 * 65, 1 + Tribe[p].facepix div 10 * 49)432 Tribe[P].InitAge(GetAge(P)); 433 if Assigned(Tribe[P].faceHGr) then 434 Dump(Offscreen, Tribe[P].faceHGr, X, Y, 64, 48, 435 1 + Tribe[P].facepix mod 10 * 65, 1 + Tribe[P].facepix div 10 * 49) 436 436 else 437 437 FillRect(Rect(X, Y, X + 64, Y + 48)); … … 443 443 procedure TNegoDlg.SetButtonStates; 444 444 var 445 cix: integer;446 IsActionPage: boolean;447 begin 448 IsActionPage := Page = History[ me].n;445 cix: Integer; 446 IsActionPage: Boolean; 447 begin 448 IsActionPage := Page = History[Me].N; 449 449 450 450 AcceptBtn.Possible := IsActionPage and … … 483 483 procedure TNegoDlg.OffscreenPaint; 484 484 var 485 i, cred: integer;486 s: string;487 OkEnabled: boolean;485 I, cred: Integer; 486 S: string; 487 OkEnabled: Boolean; 488 488 begin 489 489 if (OffscreenUser <> nil) and (OffscreenUser <> self) then … … 492 492 OffscreenUser := self; 493 493 494 if (DipCommand >= 0) and (Page = History[ me].n) then495 History[ me].Text[History[me].n] :=496 copy(DipCommandToString(me, DipMem[me].pContact,497 MyRO.Treaty[DipMem[ me].pContact], ClientMode, DipCommand, ReceivedOffer,494 if (DipCommand >= 0) and (Page = History[Me].N) then 495 History[Me].Text[History[Me].N] := 496 Copy(DipCommandToString(Me, DipMem[Me].pContact, 497 MyRO.Treaty[DipMem[Me].pContact], ClientMode, DipCommand, ReceivedOffer, 498 498 CurrentOffer), 1, 255); 499 499 500 FwdBtn.Visible := Page < History[ me].n;500 FwdBtn.Visible := Page < History[Me].N; 501 501 BwdBtn.Visible := Page >= 2; 502 if Page < History[ me].nthen503 OkEnabled := false502 if Page < History[Me].N then 503 OkEnabled := False 504 504 else if DipCommand = scDipOffer then 505 OkEnabled := Server(scDipOffer - sExecute, me, 0, CurrentOffer) >= rExecuted505 OkEnabled := Server(scDipOffer - sExecute, Me, 0, CurrentOffer) >= rExecuted 506 506 else 507 507 OkEnabled := DipCommand >= 0; … … 532 532 yPad1 + 41 + 42 * 2, $FFFFFF, $B0B0B0); 533 533 534 PaintNationPicture(xNationPicture0, yNationPicture, DipMem[ me].pContact);535 PaintNationPicture(xNationPicture1, yNationPicture, me);536 537 if History[ me].Text[Page - 1] <> '' then534 PaintNationPicture(xNationPicture0, yNationPicture, DipMem[Me].pContact); 535 PaintNationPicture(xNationPicture1, yNationPicture, Me); 536 537 if History[Me].Text[Page - 1] <> '' then 538 538 begin 539 539 FillSeamless(Offscreen.Canvas, xText0, yText0, wText, hText, 0, 0, Paper); 540 i:= Page - 1;541 if History[ me].Text[0] = '' then542 dec(i);543 if i< 16 then540 I := Page - 1; 541 if History[Me].Text[0] = '' then 542 Dec(I); 543 if I < 16 then 544 544 begin 545 545 Offscreen.Canvas.Font.Assign(RomanFont); 546 546 Offscreen.Canvas.TextOut 547 (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[ i])) div 2,548 yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[ i])) div 2,549 RomanNo[ i]);547 (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2, 548 yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2, 549 RomanNo[I]); 550 550 end 551 551 end; 552 552 FillSeamless(Offscreen.Canvas, xText1, yText1, wText, hText, 0, 0, Paper); 553 i:= Page;554 if History[ me].Text[0] = '' then555 dec(i);556 if i< 16 then553 I := Page; 554 if History[Me].Text[0] = '' then 555 Dec(I); 556 if I < 16 then 557 557 begin 558 558 Offscreen.Canvas.Font.Assign(RomanFont); 559 559 Offscreen.Canvas.TextOut 560 (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[ i])) div 2,561 yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[ i])) div 2,562 RomanNo[ i]);560 (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2, 561 yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2, 562 RomanNo[I]); 563 563 end; 564 564 with Offscreen.Canvas do 565 565 begin 566 566 Brush.Color := MainTexture.ColorBevelShade; 567 if History[ me].Text[Page - 1] <> '' then567 if History[Me].Text[Page - 1] <> '' then 568 568 begin 569 569 FillRect(Rect(xText0 + wText, yText0 + PaperShade, … … 583 583 { if Page=History[me].n then 584 584 begin // show attitude 585 s:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[me].pContact].Attitude);585 S:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[Me].pContact].Attitude); 586 586 //LoweredTextOut(Offscreen.Canvas,-1,MainTexture, 587 587 RisedTextOut(Offscreen.Canvas,xText0+wText div 2- 588 BiColorTextWidth(Offscreen.Canvas, s) div 2,yAttitude,s);589 s:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[me].pContact]);588 BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S); 589 S:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[Me].pContact]); 590 590 //LoweredTextOut(Offscreen.Canvas,-1,MainTexture, 591 591 RisedTextOut(Offscreen.Canvas,xText1+wText div 2- 592 BiColorTextWidth(Offscreen.Canvas, s) div 2,yAttitude,s);592 BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S); 593 593 end; } 594 594 595 if History[ me].Text[Page - 1] <> '' then596 SplitText(History[ me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,595 if History[Me].Text[Page - 1] <> '' then 596 SplitText(History[Me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText, 597 597 yText0 + hText)); 598 if (Page < History[ me].n) or OkEnabled then599 SplitText(History[ me].Text[Page], Rect(xText1, yText1, xText1 + wText,598 if (Page < History[Me].N) or OkEnabled then 599 SplitText(History[Me].Text[Page], Rect(xText1, yText1, xText1 + wText, 600 600 yText1 + hText)); 601 601 602 602 // show credibility 603 603 Offscreen.Canvas.Font.Assign(UniFont[ftTiny]); 604 cred := MyRO.EnemyReport[DipMem[ me].pContact].Credibility;604 cred := MyRO.EnemyReport[DipMem[Me].pContact].Credibility; 605 605 case cred of 606 606 0 .. 49: 607 i:= 3;607 I := 3; 608 608 50 .. 90: 609 i:= 0;609 I := 0; 610 610 91 .. 100: 611 i:= 1;612 end; 613 PaintProgressBar(Offscreen.Canvas, i, xCred0, yCred0 + 17, (cred + 2) div 5,611 I := 1; 612 end; 613 PaintProgressBar(Offscreen.Canvas, I, xCred0, yCred0 + 17, (cred + 2) div 5, 614 614 0, 20, MainTexture); 615 s:= IntToStr(cred);615 S := IntToStr(cred); 616 616 RisedTextOut(Offscreen.Canvas, xCred0 + 10 - 617 (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred0, s);617 (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred0, S); 618 618 case MyRO.Credibility of 619 619 0 .. 49: 620 i:= 3;620 I := 3; 621 621 50 .. 90: 622 i:= 0;622 I := 0; 623 623 91 .. 100: 624 i:= 1;625 end; 626 PaintProgressBar(Offscreen.Canvas, i, xCred1, yCred1 + 17,624 I := 1; 625 end; 626 PaintProgressBar(Offscreen.Canvas, I, xCred1, yCred1 + 17, 627 627 (MyRO.Credibility + 2) div 5, 0, 20, MainTexture); 628 s:= IntToStr(MyRO.Credibility);628 S := IntToStr(MyRO.Credibility); 629 629 RisedTextOut(Offscreen.Canvas, xCred1 + 10 - 630 (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred1, s);630 (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred1, S); 631 631 632 632 MarkUsedOffscreen(ClientWidth, ClientHeight); … … 635 635 procedure TNegoDlg.Initiate; 636 636 begin 637 History[ me].n:= 1;638 History[ me].Text[0] := '';637 History[Me].N := 1; 638 History[Me].Text[0] := ''; 639 639 end; 640 640 641 641 procedure TNegoDlg.Respond; 642 642 begin 643 History[ me].n:= 0;643 History[Me].N := 0; 644 644 end; 645 645 646 646 procedure TNegoDlg.FormMouseDown(Sender: TObject; Button: TMouseButton; 647 Shift: TShiftState; X, Y: integer);647 Shift: TShiftState; X, Y: Integer); 648 648 begin 649 649 if (X >= xNationPicture0) and (X < xNationPicture0 + 64) and 650 650 (Y >= yNationPicture) and (Y < yNationPicture + 48) then 651 NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[ me].pContact)651 NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[Me].pContact) 652 652 else if (X >= xNationPicture1) and (X < xNationPicture1 + 64) and 653 653 (Y >= yNationPicture) and (Y < yNationPicture + 48) then 654 NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), me)654 NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), Me) 655 655 end; 656 656 657 657 procedure TNegoDlg.BwdBtnClick(Sender: TObject); 658 658 begin 659 dec(Page, 2);659 Dec(Page, 2); 660 660 SetButtonStates; 661 661 SmartUpdateContent; … … 664 664 procedure TNegoDlg.FwdBtnClick(Sender: TObject); 665 665 begin 666 inc(Page, 2);666 Inc(Page, 2); 667 667 SetButtonStates; 668 668 SmartUpdateContent; … … 671 671 procedure TNegoDlg.OkBtnClick(Sender: TObject); 672 672 begin 673 inc(History[me].n);673 Inc(History[Me].N); 674 674 if DipCommand = scDipOffer then 675 675 MainScreen.OfferCall(CurrentOffer) … … 697 697 procedure TNegoDlg.BuildCurrentOffer; 698 698 var 699 i: integer;699 I: Integer; 700 700 begin 701 701 CurrentOffer.nDeliver := 0; 702 702 CurrentOffer.nCost := 0; 703 for i:= 0 to 11 do704 if Delivers[ i] <> $FFFFFFFF then705 begin 706 CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[ i];707 inc(CurrentOffer.nDeliver);703 for I := 0 to 11 do 704 if Delivers[I] <> $FFFFFFFF then 705 begin 706 CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[I]; 707 Inc(CurrentOffer.nDeliver); 708 708 end; 709 for i:= 0 to 11 do710 if Costs[ i] <> $FFFFFFFF then709 for I := 0 to 11 do 710 if Costs[I] <> $FFFFFFFF then 711 711 begin 712 712 CurrentOffer.Price[CurrentOffer.nDeliver + CurrentOffer.nCost] := 713 Costs[ i];714 inc(CurrentOffer.nCost);713 Costs[I]; 714 Inc(CurrentOffer.nCost); 715 715 end; 716 716 end; … … 718 718 procedure TNegoDlg.WantClick(Sender: TObject); 719 719 var 720 a, i, max: integer;721 Price: cardinal;722 begin 723 if (Page <> History[ me].n) or (ClientMode = scDipCancelTreaty) or720 A, I, Max: Integer; 721 Price: Cardinal; 722 begin 723 if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or 724 724 (ClientMode = scDipBreak) then 725 exit;725 Exit; 726 726 if Costs[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then 727 727 Price := $FFFFFFFF // toggle off … … 731 731 begin 732 732 SimpleMessage(Phrases.Lookup('MAX2WANTS')); 733 exit733 Exit 734 734 end; 735 735 Price := ButtonPrice[TButtonN(Sender).Tag and $FF]; 736 736 if not(Price shr 24 in OppoAllowed) then 737 exit;737 Exit; 738 738 case Price of 739 739 opCivilReport, opMilReport: 740 inc(Price, DipMem[me].pContact shl 16 + MyRO.Turn);740 Inc(Price, DipMem[Me].pContact shl 16 + MyRO.Turn); 741 741 // !!! choose player and year! 742 742 opMoney: … … 747 747 InputDlg.ShowModal; 748 748 if InputDlg.ModalResult <> mrOK then 749 exit;750 val(InputDlg.EInput.Text, a, i);751 if ( i <> 0) or (a <= 0) or (a>= MaxMoneyPrice) then752 exit;753 inc(Price, a);749 Exit; 750 val(InputDlg.EInput.Text, A, I); 751 if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then 752 Exit; 753 Inc(Price, A); 754 754 end; 755 755 opShipParts: … … 765 765 ShowModal; 766 766 if ModalResult <> mrOK then 767 exit767 Exit 768 768 end; 769 769 ModalSelectDlg.ShowNewContent(wmModal, kEShipPart); 770 if ModalSelectDlg. result < 0 then771 exit;772 inc(Price, ModalSelectDlg.result shl 16);773 max := MyRO.Ship[DipMem[me].pContact].Parts[ModalSelectDlg.result];770 if ModalSelectDlg.Result < 0 then 771 Exit; 772 Inc(Price, ModalSelectDlg.Result shl 16); 773 Max := MyRO.Ship[DipMem[Me].pContact].Parts[ModalSelectDlg.Result]; 774 774 InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER'); 775 775 InputDlg.EInput.Text := ''; … … 777 777 InputDlg.ShowModal; 778 778 if InputDlg.ModalResult <> mrOK then 779 exit;780 val(InputDlg.EInput.Text, a, i);781 if ( i <> 0) or (a<= 0) then782 exit;783 if a > max then784 a := max;785 if a> MaxShipPartPrice then786 a:= MaxShipPartPrice;787 inc(Price, a);779 Exit; 780 val(InputDlg.EInput.Text, A, I); 781 if (I <> 0) or (A <= 0) then 782 Exit; 783 if A > Max then 784 A := Max; 785 if A > MaxShipPartPrice then 786 A := MaxShipPartPrice; 787 Inc(Price, A); 788 788 end; 789 789 opAllTech: 790 790 begin // choose technology 791 791 ModalSelectDlg.ShowNewContent(wmModal, kChooseETech); 792 if ModalSelectDlg. result < 0 then793 exit;794 if ModalSelectDlg. result = adAll then792 if ModalSelectDlg.Result < 0 then 793 Exit; 794 if ModalSelectDlg.Result = adAll then 795 795 Price := opAllTech 796 796 else 797 Price := OpTech + ModalSelectDlg. result;797 Price := OpTech + ModalSelectDlg.Result; 798 798 end; 799 799 opAllModel: 800 800 begin // choose model 801 801 ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel); 802 if ModalSelectDlg. result < 0 then803 exit;804 if ModalSelectDlg. result = mixAll then802 if ModalSelectDlg.Result < 0 then 803 Exit; 804 if ModalSelectDlg.Result = mixAll then 805 805 Price := opAllModel 806 806 else 807 Price := OpModel + MyRO.EnemyModel[ModalSelectDlg. result].mix;807 Price := OpModel + MyRO.EnemyModel[ModalSelectDlg.Result].mix; 808 808 end; 809 809 opTreaty: 810 810 begin 811 if MyRO.Treaty[DipMem[ me].pContact] < trPeace then811 if MyRO.Treaty[DipMem[Me].pContact] < trPeace then 812 812 Price := opTreaty + trPeace 813 813 else 814 Price := opTreaty + MyRO.Treaty[DipMem[ me].pContact] + 1;814 Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1; 815 815 end; 816 816 { opLowTreaty: 817 817 begin 818 if MyRO.Treaty[DipMem[ me].pContact]=trNone then Price:=opTreaty+trCeaseFire819 else Price:=opTreaty+MyRO.Treaty[DipMem[ me].pContact]-1;818 if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire 819 else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1; 820 820 end } 821 821 end; … … 831 831 procedure TNegoDlg.OfferClick(Sender: TObject); 832 832 var 833 a, i, max: integer;834 Price: cardinal;835 begin 836 if (Page <> History[ me].n) or (ClientMode = scDipCancelTreaty) or833 A, I, Max: Integer; 834 Price: Cardinal; 835 begin 836 if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or 837 837 (ClientMode = scDipBreak) then 838 exit;838 Exit; 839 839 if Delivers[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then 840 840 Price := $FFFFFFFF // toggle off … … 844 844 begin 845 845 SimpleMessage(Phrases.Lookup('MAX2OFFERS')); 846 exit;846 Exit; 847 847 end; 848 848 Price := ButtonPrice[TButtonN(Sender).Tag and $FF]; 849 849 if not(Price shr 24 in MyAllowed) then 850 exit;850 Exit; 851 851 case Price of 852 852 opCivilReport, opMilReport: 853 inc(Price, me shl 16 + MyRO.Turn); // !!! choose player and year!853 Inc(Price, Me shl 16 + MyRO.Turn); // !!! choose player and year! 854 854 opMoney: 855 855 begin // choose amount … … 859 859 InputDlg.ShowModal; 860 860 if InputDlg.ModalResult <> mrOK then 861 exit;862 val(InputDlg.EInput.Text, a, i);863 if ( i <> 0) or (a <= 0) or (a>= MaxMoneyPrice) then864 exit;865 if (Price = opMoney) and ( a> MyRO.Money) then866 a:= MyRO.Money;867 inc(Price, a);861 Exit; 862 val(InputDlg.EInput.Text, A, I); 863 if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then 864 Exit; 865 if (Price = opMoney) and (A > MyRO.Money) then 866 A := MyRO.Money; 867 Inc(Price, A); 868 868 end; 869 869 opShipParts: 870 870 begin // choose type and number 871 871 ModalSelectDlg.ShowNewContent(wmModal, kShipPart); 872 if ModalSelectDlg. result < 0 then873 exit;874 inc(Price, ModalSelectDlg.result shl 16);875 max := MyRO.Ship[me].Parts[ModalSelectDlg.result];872 if ModalSelectDlg.Result < 0 then 873 Exit; 874 Inc(Price, ModalSelectDlg.Result shl 16); 875 Max := MyRO.Ship[Me].Parts[ModalSelectDlg.Result]; 876 876 InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER'); 877 877 InputDlg.EInput.Text := ''; … … 879 879 InputDlg.ShowModal; 880 880 if InputDlg.ModalResult <> mrOK then 881 exit;882 val(InputDlg.EInput.Text, a, i);883 if ( i <> 0) or (a<= 0) then884 exit;885 if a > max then886 a := max;887 if a> MaxShipPartPrice then888 a:= MaxShipPartPrice;889 inc(Price, a);881 Exit; 882 val(InputDlg.EInput.Text, A, I); 883 if (I <> 0) or (A <= 0) then 884 Exit; 885 if A > Max then 886 A := Max; 887 if A > MaxShipPartPrice then 888 A := MaxShipPartPrice; 889 Inc(Price, A); 890 890 end; 891 891 opAllTech: 892 892 begin // choose technology 893 893 ModalSelectDlg.ShowNewContent(wmModal, kChooseTech); 894 if ModalSelectDlg. result < 0 then895 exit;896 if ModalSelectDlg. result = adAll then894 if ModalSelectDlg.Result < 0 then 895 Exit; 896 if ModalSelectDlg.Result = adAll then 897 897 Price := opAllTech 898 898 else 899 Price := OpTech + ModalSelectDlg. result;899 Price := OpTech + ModalSelectDlg.Result; 900 900 end; 901 901 opAllModel: 902 902 begin // choose model 903 903 ModalSelectDlg.ShowNewContent(wmModal, kChooseModel); 904 if ModalSelectDlg. result < 0 then905 exit;906 if ModalSelectDlg. result = mixAll then904 if ModalSelectDlg.Result < 0 then 905 Exit; 906 if ModalSelectDlg.Result = mixAll then 907 907 Price := opAllModel 908 908 else 909 Price := OpModel + ModalSelectDlg. result;909 Price := OpModel + ModalSelectDlg.Result; 910 910 end; 911 911 opTreaty: 912 912 begin 913 if MyRO.Treaty[DipMem[ me].pContact] < trPeace then913 if MyRO.Treaty[DipMem[Me].pContact] < trPeace then 914 914 Price := opTreaty + trPeace 915 915 else 916 Price := opTreaty + MyRO.Treaty[DipMem[ me].pContact] + 1;916 Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1; 917 917 end; 918 918 { opLowTreaty: 919 919 begin 920 if MyRO.Treaty[DipMem[ me].pContact]=trNone then Price:=opTreaty+trCeaseFire921 else Price:=opTreaty+MyRO.Treaty[DipMem[ me].pContact]-1;920 if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire 921 else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1; 922 922 end } 923 923 end; … … 933 933 procedure TNegoDlg.FastBtnClick(Sender: TObject); 934 934 var 935 NewCommand: cardinal;936 begin 937 if Page <> History[ me].nthen938 exit;935 NewCommand: Cardinal; 936 begin 937 if Page <> History[Me].N then 938 Exit; 939 939 NewCommand := TButtonN(Sender).Tag and $FF + scDipStart; 940 940 if not(NewCommand - scDipStart in CommandAllowed) then 941 exit;941 Exit; 942 942 if (NewCommand = scDipCancelTreaty) and 943 (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[ me].pContact] + CancelTreatyTurns)943 (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[Me].pContact] + CancelTreatyTurns) 944 944 then 945 945 begin 946 946 SimpleMessage(Phrases.Lookup('CANCELTREATYRUSH')); 947 exit;947 Exit; 948 948 end; 949 949 if (NewCommand = scDipOffer) and ((ClientMode = scDipCancelTreaty) or -
trunk/LocalPlayer/PVSB.pas
r442 r447 30 30 procedure Init(Max, PageSize: Integer); 31 31 procedure SetPos(Pos: Integer); 32 function Process(const Msg: TMessage): boolean;32 function Process(const Msg: TMessage): Boolean; 33 33 function ProcessMouseWheel(Delta: Integer): Boolean; 34 procedure Show(Visible: boolean);34 procedure Show(Visible: Boolean); 35 35 procedure EndSB; 36 36 procedure SetBorderSpacing(Top, Right, Bottom: Integer); … … 63 63 end; 64 64 65 function TPVScrollBar.Process(const Msg: TMessage): boolean;65 function TPVScrollBar.Process(const Msg: TMessage): Boolean; 66 66 var 67 NewPos: integer;67 NewPos: Integer; 68 68 begin 69 69 if Max < ScrollBar.PageSize then 70 result := false70 Result := False 71 71 else 72 72 begin 73 73 if (Msg.wParam and $ffff) in [SB_THUMBPOSITION, SB_THUMBTRACK] then 74 74 begin 75 result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position;75 Result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position; 76 76 ScrollBar.Position := (Msg.wParam shr 16) and $ffff; 77 77 end else begin … … 92 92 if NewPos > Max - ScrollBar.PageSize + 1 then 93 93 NewPos := Max - ScrollBar.PageSize + 1; 94 result := NewPos <> ScrollBar.Position;94 Result := NewPos <> ScrollBar.Position; 95 95 if (NewPos <> ScrollBar.Position) or ((Msg.wParam and $ffff) = SB_ENDSCROLL) then 96 96 begin … … 103 103 function TPVScrollBar.ProcessMouseWheel(Delta: Integer): Boolean; 104 104 var 105 NewPos: integer;105 NewPos: Integer; 106 106 begin 107 107 if Max < ScrollBar.PageSize then Result := False … … 118 118 end; 119 119 120 procedure TPVScrollBar.Show(Visible: boolean);120 procedure TPVScrollBar.Show(Visible: Boolean); 121 121 begin 122 122 if not Visible or (Max < ScrollBar.PageSize) then -
trunk/LocalPlayer/Rates.pas
r442 r447 46 46 procedure TRatesDlg.OffscreenPaint; 47 47 var 48 p, x, y, current, max, i: integer;49 s, s1: string;48 P, X, Y, current, Max, I: Integer; 49 S, s1: string; 50 50 begin 51 51 if (OffscreenUser <> nil) and (OffscreenUser <> self) then … … 64 64 BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture); 65 65 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 66 s:= Phrases.Lookup('TITLE_RATES');66 S := Phrases.Lookup('TITLE_RATES'); 67 67 RisedTextOut(Offscreen.Canvas, 68 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s)) div 2 - 1, 7, s);69 70 if MyRO.Wonder[woLiberty].EffectiveOwner = me then71 s:= Phrases.Lookup('NORATES')72 else 73 s:= Phrases.Lookup('RATES');68 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S); 69 70 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then 71 S := Phrases.Lookup('NORATES') 72 else 73 S := Phrases.Lookup('RATES'); 74 74 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 75 p := pos('\', s);76 if p= 0 then77 RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))78 div 2, 114, s)79 else 80 begin 81 s1 := copy(s, 1, p- 1);75 P := Pos('\', S); 76 if P = 0 then 77 RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) 78 div 2, 114, S) 79 else 80 begin 81 s1 := Copy(S, 1, P - 1); 82 82 RisedTextOut(Offscreen.Canvas, 83 83 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2, 84 84 114 - MessageLineSpacing div 2, s1); 85 s1 := copy(s, p+ 1, 255);85 s1 := Copy(S, P + 1, 255); 86 86 RisedTextOut(Offscreen.Canvas, 87 87 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2, … … 90 90 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 91 91 92 if MyRO.Wonder[woLiberty].EffectiveOwner = me then92 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then 93 93 begin 94 94 GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2, 52, xSizeBig, 95 ySizeBig, Tribe[ me].Color);95 ySizeBig, Tribe[Me].Color); 96 96 BitBltCanvas(Offscreen.Canvas, ClientWidth div 2 - xSizeBig div 2, 52, 97 97 xSizeBig, ySizeBig, BigImp.Canvas, (woLiberty mod 7) * xSizeBig, … … 102 102 // ImageOp_CBC(Offscreen,Templates,260,40,145,112,36,36,$404000,$8B8BEB); 103 103 104 s:= Phrases.Lookup('SCIENCE');105 RisedTextOut(Offscreen.Canvas, 106 16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 44, s);107 s:= Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);108 RisedTextOut(Offscreen.Canvas, 109 16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 60, s);104 S := Phrases.Lookup('SCIENCE'); 105 RisedTextOut(Offscreen.Canvas, 106 16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 44, S); 107 S := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]); 108 RisedTextOut(Offscreen.Canvas, 109 16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 60, S); 110 110 // PaintProgressBar(Offscreen.Canvas,2,16,81,(100-MyRO.LuxRate-MyRO.TaxRate)*120 div 100,0,120,MainTexture); 111 111 112 112 // reverse progress bar for science 113 x:= 16;114 y:= 81;113 X := 16; 114 Y := 81; 115 115 current := (100 - MyRO.LuxRate - MyRO.TaxRate) * 120 div 100; 116 max := 120;117 Frame(Offscreen.Canvas, x - 1, y - 1, x + max, y+ 7, $000000, $000000);118 RFrame(Offscreen.Canvas, x - 2, y - 2, x + max + 1, y+ 8,116 Max := 120; 117 Frame(Offscreen.Canvas, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000); 118 RFrame(Offscreen.Canvas, X - 2, Y - 2, X + Max + 1, Y + 8, 119 119 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 120 120 with Offscreen.Canvas do 121 121 begin 122 for i:= 0 to current div 8 - 1 do123 BitBltCanvas(Offscreen.Canvas, x + max - 8 - i * 8, y, 8, 7,122 for I := 0 to current div 8 - 1 do 123 BitBltCanvas(Offscreen.Canvas, X + Max - 8 - I * 8, Y, 8, 7, 124 124 HGrSystem.Data.Canvas, 104, 9 + 8 * 2); 125 BitBltCanvas(Offscreen.Canvas, x + max - current, y, current - 8 * (current div 8), 7,125 BitBltCanvas(Offscreen.Canvas, X + Max - current, Y, current - 8 * (current div 8), 7, 126 126 HGrSystem.Data.Canvas, 104, 9 + 8 * 2); 127 127 Brush.Color := $000000; 128 FillRect(Rect( x, y, x + max - current, y+ 7));128 FillRect(Rect(X, Y, X + Max - current, Y + 7)); 129 129 Brush.Style := bsClear; 130 130 end; 131 131 132 132 RisedTextOut(Offscreen.Canvas, 16 + 160, 44, Phrases.Lookup('LUX')); 133 s:= Format('%d%%', [MyRO.LuxRate]);134 RisedTextOut(Offscreen.Canvas, 135 16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, s);133 S := Format('%d%%', [MyRO.LuxRate]); 134 RisedTextOut(Offscreen.Canvas, 135 16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, S); 136 136 PaintProgressBar(Offscreen.Canvas, 5, 16 + 160, 81, 137 137 MyRO.LuxRate * 120 div 100, 0, 120, MainTexture); … … 144 144 MainTexture.ColorBevelLight); 145 145 RisedTextOut(Offscreen.Canvas, 16 + 80, 164, Phrases.Lookup('TAXRATE')); 146 s:= Format('%d%%', [MyRO.TaxRate]);146 S := Format('%d%%', [MyRO.TaxRate]); 147 147 RisedTextOut(Offscreen.Canvas, 148 16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, s);148 16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, S); 149 149 PaintProgressBar(Offscreen.Canvas, 0, 16 + 80, 201, 150 150 MyRO.TaxRate * 120 div 100, 0, 120, MainTexture); … … 164 164 begin 165 165 Caption := Phrases.Lookup('TITLE_RATES'); 166 if MyRO.Wonder[woLiberty].EffectiveOwner = me then167 begin 168 ScienceBtn.Visible := false;169 LuxBtn.Visible := false;166 if MyRO.Wonder[woLiberty].EffectiveOwner = Me then 167 begin 168 ScienceBtn.Visible := False; 169 LuxBtn.Visible := False; 170 170 end 171 171 else 172 172 begin 173 ScienceBtn.Visible := true;174 LuxBtn.Visible := true;173 ScienceBtn.Visible := True; 174 LuxBtn.Visible := True; 175 175 end; 176 176 OffscreenPaint; … … 184 184 procedure TRatesDlg.TaxLuxBtnClick(Sender: TObject); 185 185 var 186 NewTax, NewLux: integer;186 NewTax, NewLux: Integer; 187 187 begin 188 188 NewTax := MyRO.TaxRate div 10; … … 191 191 begin 192 192 if NewTax < 10 then 193 inc(NewTax);193 Inc(NewTax); 194 194 if NewTax + NewLux > 10 then 195 dec(NewLux);195 Dec(NewLux); 196 196 end 197 197 else if (Sender = TaxDownBtn) and (NewTax > 0) then 198 dec(NewTax)198 Dec(NewTax) 199 199 else if (Sender = ScienceBtn) and (NewLux > 0) then 200 dec(NewLux)200 Dec(NewLux) 201 201 else if (Sender = LuxBtn) and (NewLux + NewTax < 100) then 202 inc(NewLux);203 if Server(sSetRates, me, NewTax + NewLux shl 4, nil^) <> eNotChanged then202 Inc(NewLux); 203 if Server(sSetRates, Me, NewTax + NewLux shl 4, nil^) <> eNotChanged then 204 204 begin 205 205 CityOptimizer_BeginOfTurn; 206 206 SmartUpdateContent; 207 MainScreen.UpdateViews( true);207 MainScreen.UpdateViews(True); 208 208 end; 209 209 end; -
trunk/LocalPlayer/Select.pas
r442 r447 31 31 WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); 32 32 procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 33 x, y: integer);33 X, Y: Integer); 34 34 procedure FormCreate(Sender: TObject); 35 35 procedure FormDestroy(Sender: TObject); 36 36 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 37 Shift: TShiftState; x, y: integer);37 Shift: TShiftState; X, Y: Integer); 38 38 procedure FormPaint(Sender: TObject); 39 39 procedure CloseBtnClick(Sender: TObject); 40 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);40 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 41 41 procedure FormShow(Sender: TObject); 42 42 procedure ModeBtnClick(Sender: TObject); 43 43 procedure ToggleBtnClick(Sender: TObject); 44 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);44 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 45 45 procedure PlayerClick(Sender: TObject); 46 46 private … … 59 59 Lines: array [0 .. MaxLayer - 1] of Integer; 60 60 FirstShrinkedLine: array [0 .. MaxLayer - 1] of Integer; 61 code: array [0 .. MaxLayer - 1, 0 .. 4095] of Integer;61 Code: array [0 .. MaxLayer - 1, 0 .. 4095] of Integer; 62 62 Column: array [0 .. nPl - 1] of Integer; 63 63 Closable: Boolean; … … 66 66 procedure ScrollBarUpdate(Sender: TObject); 67 67 procedure InitLines; 68 procedure line(ca: TCanvas; l: integer; NonText, lit: boolean);69 function RenameCity(cix: integer): boolean;70 function RenameModel(mix: integer): boolean;68 procedure Line(ca: TCanvas; L: Integer; NonText, lit: Boolean); 69 function RenameCity(cix: Integer): Boolean; 70 function RenameModel(mix: Integer): Boolean; 71 71 procedure OnScroll(var Msg: TMessage); message WM_VSCROLL; 72 72 procedure OnMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE; 73 73 public 74 result: integer;75 function OnlyChoice(TestKind: TListKind): integer;74 Result: Integer; 75 function OnlyChoice(TestKind: TListKind): Integer; 76 76 // -2=empty, -1=ambiguous, other=only choice 77 77 procedure OffscreenPaint; override; 78 78 procedure ShowNewContent(NewMode: TWindowMode; ListKind: TListKind); 79 procedure ShowNewContent_CityProject(NewMode: TWindowMode; cix: integer);80 procedure ShowNewContent_MilReport(NewMode: TWindowMode; p: integer);79 procedure ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer); 80 procedure ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer); 81 81 procedure EcoChange; 82 82 procedure TechChange; … … 135 135 procedure TListDlg.CloseBtnClick(Sender: TObject); 136 136 begin 137 Closable := true;137 Closable := True; 138 138 Close; 139 139 end; 140 140 141 procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: boolean);141 procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 142 142 begin 143 143 CanClose := Closable or not(Kind in MustChooseKind); … … 149 149 if ScrollBar.Process(Msg) then begin 150 150 Selected := -2; 151 SmartUpdateContent( true);151 SmartUpdateContent(True); 152 152 end; 153 153 } … … 158 158 if not Closable and (Selected <> -2) then 159 159 begin 160 line(Canvas, Selected, false, false);160 Line(Canvas, Selected, False, False); 161 161 Selected := -2; 162 162 end; … … 165 165 procedure TListDlg.FormPaint(Sender: TObject); 166 166 var 167 s: string;167 S: string; 168 168 begin 169 169 inherited; 170 170 Canvas.Font.Assign(UniFont[ftNormal]); 171 171 if Selected <> -2 then 172 line(Canvas, Selected, false, true);173 s:= '';172 Line(Canvas, Selected, False, True); 173 S := ''; 174 174 if (Kind = kAdvance) and (MyData.FarTech <> adNone) then 175 s:= Format(Phrases.Lookup('TECHFOCUS'),175 S := Format(Phrases.Lookup('TECHFOCUS'), 176 176 [Phrases.Lookup('ADVANCES', MyData.FarTech)]) 177 177 else if Kind = kModels then 178 s := Tribe[me].TPhrase('SHORTNAME')178 S := Tribe[Me].TPhrase('SHORTNAME') 179 179 else if Kind = kEModels then 180 s:= Tribe[pView].TPhrase('SHORTNAME') + ' (' +180 S := Tribe[pView].TPhrase('SHORTNAME') + ' (' + 181 181 TurnToString(MyRO.EnemyReport[pView].TurnOfMilReport) + ')'; 182 if s<> '' then182 if S <> '' then 183 183 LoweredTextOut(Canvas, -1, MainTexture, 184 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, 31, s);184 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S); 185 185 if not MultiPage and (Kind in [kProject, kAdvance, kFarAdvance]) and not Phrases2FallenBackToEnglish 186 186 then 187 187 begin 188 s:= Phrases2.Lookup('SHIFTCLICK');188 S := Phrases2.Lookup('SHIFTCLICK'); 189 189 LoweredTextOut(Canvas, -2, MainTexture, 190 (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, ClientHeight - 29, s);191 end; 192 end; 193 194 procedure TListDlg. line(ca: TCanvas; l: integer; NonText, lit: boolean);190 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, ClientHeight - 29, S); 191 end; 192 end; 193 194 procedure TListDlg.Line(ca: TCanvas; L: Integer; NonText, lit: Boolean); 195 195 // paint a line 196 196 197 procedure DisplayProject( x, y, pix: integer);197 procedure DisplayProject(X, Y, pix: Integer); 198 198 begin 199 199 if pix and (cpType or cpImp) = 0 then 200 with Tribe[ me].ModelPicture[pix and cpIndex] do201 Sprite( offscreen, HGr, x, y, 64, 48, pix mod 10 * 65 + 1,200 with Tribe[Me].ModelPicture[pix and cpIndex] do 201 Sprite(Offscreen, HGr, X, Y, 64, 48, pix mod 10 * 65 + 1, 202 202 pix div 10 * 49 + 1) 203 203 else 204 204 begin 205 Frame( offscreen.Canvas, x + (16 - 1), y + (16 - 2), x+ (16 + xSizeSmall),206 y+ (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight,205 Frame(Offscreen.Canvas, X + (16 - 1), Y + (16 - 2), X + (16 + xSizeSmall), 206 Y + (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight, 207 207 MainTexture.ColorBevelShade); 208 208 if pix and cpType = 0 then 209 209 if (pix and cpIndex = imPalace) and (MyRO.Government <> gAnarchy) then 210 BitBltCanvas( offscreen.Canvas, x + 16, y+ (16 - 1), xSizeSmall,210 BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall, 211 211 ySizeSmall, SmallImp.Canvas, (MyRO.Government - 1) * 212 212 xSizeSmall, ySizeSmall) 213 213 else 214 BitBltCanvas( offscreen.Canvas, x + 16, y+ (16 - 1), xSizeSmall,214 BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall, 215 215 ySizeSmall, SmallImp.Canvas, pix and cpIndex mod 7 * 216 216 xSizeSmall, (pix and cpIndex + SystemIconLines * 7) div 7 * 217 217 ySizeSmall) 218 218 else 219 BitBltCanvas( offscreen.Canvas, x + 16, y+ (16 - 1), xSizeSmall,219 BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall, 220 220 ySizeSmall, SmallImp.Canvas, (3 + pix and cpIndex) * 221 221 xSizeSmall, 0); … … 223 223 end; 224 224 225 procedure ReplaceText( x, y, Color: integer; s: string);225 procedure ReplaceText(X, Y, Color: Integer; S: string); 226 226 var 227 227 TextSize: TSize; … … 229 229 if ca = Canvas then 230 230 begin 231 TextSize.cx := BiColorTextWidth(ca, s);232 TextSize.cy := ca.TextHeight( s);233 if y+ TextSize.cy >= TitleHeight + InnerHeight then234 TextSize.cy := TitleHeight + InnerHeight - y;235 Fill(ca, x, y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth)231 TextSize.cx := BiColorTextWidth(ca, S); 232 TextSize.cy := ca.TextHeight(S); 233 if Y + TextSize.cy >= TitleHeight + InnerHeight then 234 TextSize.cy := TitleHeight + InnerHeight - Y; 235 Fill(ca, X, Y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth) 236 236 div 2, (Maintexture.Height - ClientHeight) div 2); 237 237 end; 238 LoweredTextOut(ca, Color, MainTexture, x, y, s);238 LoweredTextOut(ca, Color, MainTexture, X, Y, S); 239 239 end; 240 240 241 241 var 242 icon, ofs, x, y, y0, lix, i, j, TextColor, Available, first, test,243 FutureCount, growth, TrueFood, TrueProd: integer;242 icon, ofs, X, Y, y0, lix, I, J, TextColor, Available, first, Test, 243 FutureCount, growth, TrueFood, TrueProd: Integer; 244 244 CityReport: TCityReportNew; 245 245 mox: ^TModelInfo; 246 s, number: string;247 CanGrow: boolean;248 begin 249 lix := code[Layer, ScrollBar.Position + l];250 y0 := 2 + ( l+ 1) * LineDistance;251 if ScrollBar.Position + l>= FirstShrinkedLine[Layer] then252 ofs := (ScrollBar.Position + l- FirstShrinkedLine[Layer]) and 1 * 33246 S, number: string; 247 CanGrow: Boolean; 248 begin 249 lix := Code[Layer, ScrollBar.Position + L]; 250 y0 := 2 + (L + 1) * LineDistance; 251 if ScrollBar.Position + L >= FirstShrinkedLine[Layer] then 252 ofs := (ScrollBar.Position + L - FirstShrinkedLine[Layer]) and 1 * 33 253 253 else { if FirstShrinkedLine[Layer]<Lines[Layer] then } 254 254 ofs := 33; … … 257 257 with MyCity[lix] do 258 258 begin 259 x:= 104 - 76;260 y:= y0;259 X := 104 - 76; 260 Y := y0; 261 261 if ca = Canvas then 262 262 begin 263 x := x+ SideFrame;264 y := y+ TitleHeight;263 X := X + SideFrame; 264 Y := Y + TitleHeight; 265 265 end; 266 266 if lit then … … 268 268 else 269 269 TextColor := -1; 270 s:= CityName(ID);271 while BiColorTextWidth(ca, s) > CityNameSpace do272 delete(s, length(s), 1);273 ReplaceText( x + 15, y, TextColor, s);270 S := CityName(ID); 271 while BiColorTextWidth(ca, S) > CityNameSpace do 272 Delete(S, Length(S), 1); 273 ReplaceText(X + 15, Y, TextColor, S); 274 274 275 275 if NonText then 276 with offscreen.Canvas do276 with Offscreen.Canvas do 277 277 begin // city size 278 brush.Color := $000000;279 fillrect(rect(x - 4 - 11, y + 1, x - 4 + 13, y+ 21));280 brush.Color := $FFFFFF;281 fillrect(rect(x - 4 - 12, y, x - 4 + 12, y+ 20));282 brush.style := bsClear;278 Brush.Color := $000000; 279 FillRect(rect(X - 4 - 11, Y + 1, X - 4 + 13, Y + 21)); 280 Brush.Color := $FFFFFF; 281 FillRect(rect(X - 4 - 12, Y, X - 4 + 12, Y + 20)); 282 Brush.style := bsClear; 283 283 Font.Color := $000000; 284 s := inttostr(MyCity[lix].Size);285 TextOut( x - 4 - textwidth(s) div 2, y, s);284 S := IntToStr(MyCity[lix].Size); 285 TextOut(X - 4 - textwidth(S) div 2, Y, S); 286 286 end; 287 287 … … 289 289 begin 290 290 first := -1; 291 for j:= 0 to nCityEventPriority - 1 do292 if (Flags and CityRepMask and CityEventPriority[ j] <> 0) then293 begin 294 first := j;291 for J := 0 to nCityEventPriority - 1 do 292 if (Flags and CityRepMask and CityEventPriority[J] <> 0) then 293 begin 294 first := J; 295 295 Break; 296 296 end; 297 297 if first >= 0 then 298 298 begin 299 i:= 0;300 test := 1;301 while test < CityEventPriority[first] do302 begin 303 inc(i);304 inc(test, test);305 end; 306 s := CityEventName(i);299 I := 0; 300 Test := 1; 301 while Test < CityEventPriority[first] do 302 begin 303 Inc(I); 304 Inc(Test, Test); 305 end; 306 S := CityEventName(I); 307 307 { if CityEventPriority[first]=chNoGrowthWarning then 308 308 if Built[imAqueduct]=0 then 309 s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])310 else begin s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); i:=17 end; }311 ReplaceText( x + (CityNameSpace + 4 + 40 + 18 + 8), y, TextColor, s);309 S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)]) 310 else begin S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); I:=17 end; } 311 ReplaceText(X + (CityNameSpace + 4 + 40 + 18 + 8), Y, TextColor, S); 312 312 if NonText then 313 313 begin 314 Sprite( offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40,315 y0 + 1, 18, 18, 1 + i mod 3 * 19, 1 + idiv 3 * 19);316 x:= InnerWidth - 26;317 for j:= nCityEventPriority - 1 downto first + 1 do318 if (Flags and CityRepMask and CityEventPriority[ j] <> 0) then314 Sprite(Offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40, 315 y0 + 1, 18, 18, 1 + I mod 3 * 19, 1 + I div 3 * 19); 316 X := InnerWidth - 26; 317 for J := nCityEventPriority - 1 downto first + 1 do 318 if (Flags and CityRepMask and CityEventPriority[J] <> 0) then 319 319 begin 320 i:= 0;321 test := 1;322 while test < CityEventPriority[j] do320 I := 0; 321 Test := 1; 322 while Test < CityEventPriority[J] do 323 323 begin 324 inc(i);325 inc(test, test);324 Inc(I); 325 Inc(Test, Test); 326 326 end; 327 if (CityEventPriority[ j] = chNoGrowthWarning) and327 if (CityEventPriority[J] = chNoGrowthWarning) and 328 328 (Built[imAqueduct] > 0) then 329 i:= 17;330 Sprite( offscreen, HGrSystem, x, y0 + 1, 18, 18,331 1 + i mod 3 * 19, 1 + idiv 3 * 19);332 dec(x, 20);329 I := 17; 330 Sprite(Offscreen, HGrSystem, X, y0 + 1, 18, 18, 331 1 + I mod 3 * 19, 1 + I div 3 * 19); 332 Dec(X, 20); 333 333 end; 334 334 end; … … 340 340 CityReport.HypoTaxRate := -1; 341 341 CityReport.HypoLuxuryRate := -1; 342 Server(sGetCityReportNew, me, lix, CityReport);342 Server(sGetCityReportNew, Me, lix, CityReport); 343 343 TrueFood := Food; 344 344 TrueProd := Prod; 345 if supervising then345 if Supervising then 346 346 begin // normalize city from after-turn state 347 dec(TrueFood, CityReport.FoodSurplus);347 Dec(TrueFood, CityReport.FoodSurplus); 348 348 if TrueFood < 0 then 349 349 TrueFood := 0; // shouldn't happen 350 dec(TrueProd, CityReport.Production);350 Dec(TrueProd, CityReport.Production); 351 351 if TrueProd < 0 then 352 352 TrueProd := 0; // shouldn't happen 353 353 end; 354 354 355 s:= ''; // disorder info355 S := ''; // disorder info 356 356 if Flags and chCaptured <> 0 then 357 s:= Phrases.Lookup('CITYEVENTS', 14)357 S := Phrases.Lookup('CITYEVENTS', 14) 358 358 else if CityReport.HappinessBalance < 0 then 359 s:= Phrases.Lookup('CITYEVENTS', 0);360 if s<> '' then359 S := Phrases.Lookup('CITYEVENTS', 0); 360 if S <> '' then 361 361 begin { disorder } 362 362 if NonText then 363 363 begin 364 DarkGradient( offscreen.Canvas, 99 + 31 + CityNameSpace + 4,364 DarkGradient(Offscreen.Canvas, 99 + 31 + CityNameSpace + 4, 365 365 y0 + 2, 131, 3); 366 366 ca.Font.Assign(UniFont[ftSmall]); 367 RisedTextout( offscreen.Canvas, 103 + CityNameSpace + 4 + 31,368 y0 + 1, s);367 RisedTextout(Offscreen.Canvas, 103 + CityNameSpace + 4 + 31, 368 y0 + 1, S); 369 369 ca.Font.Assign(UniFont[ftNormal]); 370 370 end; … … 373 373 begin 374 374 { s:=IntToStr(CityReport.FoodSurplus); 375 ReplaceText( x+(CityNameSpace+4+48)-BiColorTextWidth(ca,s),y,TextColor,s); }376 s := inttostr(CityReport.Science);377 ReplaceText( x+ CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca,378 s), y, TextColor, s);379 s := inttostr(CityReport.Production);380 ReplaceText( x + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, s), y,381 TextColor, s);375 ReplaceText(X+(CityNameSpace+4+48)-BiColorTextWidth(ca,S),Y,TextColor,S); } 376 S := IntToStr(CityReport.Science); 377 ReplaceText(X + CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca, 378 S), Y, TextColor, S); 379 S := IntToStr(CityReport.Production); 380 ReplaceText(X + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, S), Y, 381 TextColor, S); 382 382 if NonText then 383 383 begin 384 384 // Sprite(offscreen,HGrSystem,x+CityNameSpace+4+333+1,y+6,10,10,66,115); 385 Sprite( offscreen, HGrSystem, x+ CityNameSpace + 4 + 370 + 48 + 1,386 y+ 6, 10, 10, 77, 126);387 Sprite( offscreen, HGrSystem, x + CityNameSpace + 4 + 132 + 1, y+ 6,385 Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 48 + 1, 386 Y + 6, 10, 10, 77, 126); 387 Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 132 + 1, Y + 6, 388 388 10, 10, 88, 115); 389 389 end; 390 390 end; 391 s := inttostr(CityTaxBalance(lix, CityReport));392 ReplaceText( x + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, s), y,393 TextColor, s);391 S := IntToStr(CityTaxBalance(lix, CityReport)); 392 ReplaceText(X + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, S), Y, 393 TextColor, S); 394 394 // if Project and (cpImp+cpIndex)<>cpImp+imTrGoods then 395 395 // ReplaceText(x+CityNameSpace+4+333+1,y,TextColor,Format('%d/%d',[TrueProd,CityReport.ProjectCost])); 396 396 if NonText then 397 397 begin 398 Sprite( offscreen, HGrSystem, x + CityNameSpace + 4 + 370 + 1, y+ 6,398 Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 1, Y + 6, 399 399 10, 10, 132, 115); 400 400 … … 404 404 ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and 405 405 (Size < NeedSewerSize) or (Built[imSewer] = 1)); 406 PaintRelativeProgressBar( offscreen.Canvas, 1, x+ 15 + CityNameSpace +407 4, y+ 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus,406 PaintRelativeProgressBar(Offscreen.Canvas, 1, X + 15 + CityNameSpace + 407 4, Y + 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus, 408 408 (MyRO.Government <> gAnarchy) and (Flags and chCaptured = 0), 409 409 MyRO.Government, Size), CityReport.Storage, CanGrow, MainTexture); … … 411 411 if Project <> cpImp + imTrGoods then 412 412 begin 413 DisplayProject(ofs + 104 - 76 + x- 28 + CityNameSpace + 4 + 206 -413 DisplayProject(ofs + 104 - 76 + X - 28 + CityNameSpace + 4 + 206 - 414 414 60, y0 - 15, Project); 415 415 … … 419 419 (Flags and chCaptured <> 0) then 420 420 growth := 0; 421 PaintRelativeProgressBar( offscreen.Canvas, 4,422 x + CityNameSpace + 4 + 304 - 60 + 9, y+ 7, 68, TrueProd, growth,423 CityReport.ProjectCost, true, MainTexture);421 PaintRelativeProgressBar(Offscreen.Canvas, 4, 422 X + CityNameSpace + 4 + 304 - 60 + 9, Y + 7, 68, TrueProd, growth, 423 CityReport.ProjectCost, True, MainTexture); 424 424 end; 425 425 end; … … 428 428 else if Kind in [kModels, kEModels] then 429 429 begin 430 x:= 104;431 y:= y0;430 X := 104; 431 Y := y0; 432 432 if ca = Canvas then 433 433 begin 434 x := x+ SideFrame;435 y := y+ TitleHeight;434 X := X + SideFrame; 435 Y := Y + TitleHeight; 436 436 end; 437 437 if lit then … … 442 442 begin 443 443 Available := 0; 444 for j:= 0 to MyRO.nUn - 1 do445 if (MyUn[ j].Loc >= 0) and (MyUn[j].mix = lix) then446 inc(Available);444 for J := 0 to MyRO.nUn - 1 do 445 if (MyUn[J].Loc >= 0) and (MyUn[J].mix = lix) then 446 Inc(Available); 447 447 if MainScreen.mNames.Checked then 448 s := Tribe[me].ModelName[lix]448 S := Tribe[Me].ModelName[lix] 449 449 else 450 s := Format(Tribe[me].TPhrase('GENMODEL'), [lix]);450 S := Format(Tribe[Me].TPhrase('GENMODEL'), [lix]); 451 451 if NonText then 452 452 DisplayProject(8 + ofs, y0 - 15, lix); … … 456 456 Available := MyRO.EnemyReport[pView].UnCount[lix]; 457 457 if MainScreen.mNames.Checked then 458 s:= Tribe[pView].ModelName[lix]458 S := Tribe[pView].ModelName[lix] 459 459 else 460 s:= Format(Tribe[pView].TPhrase('GENMODEL'), [lix]);460 S := Format(Tribe[pView].TPhrase('GENMODEL'), [lix]); 461 461 if NonText then 462 462 with Tribe[pView].ModelPicture[lix] do 463 Sprite( offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1,463 Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1, 464 464 pix div 10 * 49 + 1); 465 465 end; 466 466 if Available > 0 then 467 ReplaceText( x + 32 - BiColorTextWidth(ca, inttostr(Available)), y,468 TextColor, inttostr(Available));469 ReplaceText( x + 40, y, TextColor, s);467 ReplaceText(X + 32 - BiColorTextWidth(ca, IntToStr(Available)), Y, 468 TextColor, IntToStr(Available)); 469 ReplaceText(X + 40, Y, TextColor, S); 470 470 end 471 471 else … … 474 474 kAllEModels, kChooseEModel: 475 475 if lix = mixAll then 476 s:= Phrases.Lookup('PRICECAT_ALLMODEL')476 S := Phrases.Lookup('PRICECAT_ALLMODEL') 477 477 else 478 478 begin … … 480 480 if MainScreen.mNames.Checked then 481 481 begin 482 s:= Tribe[mox.Owner].ModelName[mox.mix];483 if (Kind = kAllEModels) and ( code[1, ScrollBar.Position + l] = 0) then484 s := Format(Tribe[mox.Owner].TPhrase('OWNED'), [s]);482 S := Tribe[mox.Owner].ModelName[mox.mix]; 483 if (Kind = kAllEModels) and (Code[1, ScrollBar.Position + L] = 0) then 484 S := Format(Tribe[mox.Owner].TPhrase('OWNED'), [S]); 485 485 end 486 486 else 487 s:= Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]);487 S := Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]); 488 488 if NonText then 489 489 with Tribe[mox.Owner].ModelPicture[mox.mix] do 490 Sprite( offscreen, HGr, 8 + ofs, y0 - 15, 64, 48,490 Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, 491 491 pix mod 10 * 65 + 1, pix div 10 * 49 + 1); 492 492 end; 493 493 kChooseModel: 494 494 if lix = mixAll then 495 s:= Phrases.Lookup('PRICECAT_ALLMODEL')495 S := Phrases.Lookup('PRICECAT_ALLMODEL') 496 496 else 497 497 begin 498 s := Tribe[me].ModelName[lix];498 S := Tribe[Me].ModelName[lix]; 499 499 if NonText then 500 500 DisplayProject(8 + ofs, y0 - 15, lix); … … 503 503 begin 504 504 if lix and cpType <> 0 then 505 s:= Phrases.Lookup('CITYTYPE', lix and cpIndex)505 S := Phrases.Lookup('CITYTYPE', lix and cpIndex) 506 506 else if lix and cpImp = 0 then 507 507 with MyModel[lix and cpIndex] do 508 508 begin 509 s := Tribe[me].ModelName[lix and cpIndex];509 S := Tribe[Me].ModelName[lix and cpIndex]; 510 510 if lix and cpConscripts <> 0 then 511 s := Format(Phrases.Lookup('CONSCRIPTS'), [s]);511 S := Format(Phrases.Lookup('CONSCRIPTS'), [S]); 512 512 end 513 513 else 514 514 begin 515 s:= Phrases.Lookup('IMPROVEMENTS', lix and cpIndex);515 S := Phrases.Lookup('IMPROVEMENTS', lix and cpIndex); 516 516 if (Imp[lix and cpIndex].Kind in [ikNatLocal, ikNatGlobal]) and 517 517 (MyRO.NatBuilt[lix and cpIndex] > 0) or … … 519 519 (MyCity[cixProject].Built[imPower] + MyCity[cixProject].Built 520 520 [imHydro] + MyCity[cixProject].Built[imNuclear] > 0) then 521 s := Format(Phrases.Lookup('NATEXISTS'), [s]);521 S := Format(Phrases.Lookup('NATEXISTS'), [S]); 522 522 end; 523 523 if NonText then … … 527 527 begin 528 528 if lix = adAll then 529 s:= Phrases.Lookup('PRICECAT_ALLTECH')529 S := Phrases.Lookup('PRICECAT_ALLTECH') 530 530 else 531 531 begin 532 532 if lix = adNexus then 533 s:= Phrases.Lookup('NEXUS')533 S := Phrases.Lookup('NEXUS') 534 534 else if lix = adNone then 535 s:= Phrases.Lookup('NOFARTECH')535 S := Phrases.Lookup('NOFARTECH') 536 536 else if lix = adMilitary then 537 s:= Phrases.Lookup('INITUNIT')537 S := Phrases.Lookup('INITUNIT') 538 538 else 539 539 begin 540 s:= Phrases.Lookup('ADVANCES', lix);540 S := Phrases.Lookup('ADVANCES', lix); 541 541 if (Kind = kAdvance) and (lix in FutureTech) then 542 542 if MyRO.Tech[lix] < tsApplicable then 543 s := s+ ' 1'543 S := S + ' 1' 544 544 else 545 s := s + ' ' + inttostr(MyRO.Tech[lix] + 1);545 S := S + ' ' + IntToStr(MyRO.Tech[lix] + 1); 546 546 end; 547 if BiColorTextWidth(ca, s) > TechNameSpace + 8 then547 if BiColorTextWidth(ca, S) > TechNameSpace + 8 then 548 548 begin 549 549 repeat 550 delete(s, length(s), 1);551 until BiColorTextWidth(ca, s) <= TechNameSpace + 5;552 s := s+ '.';550 Delete(S, Length(S), 1); 551 until BiColorTextWidth(ca, S) <= TechNameSpace + 5; 552 S := S + '.'; 553 553 end; 554 554 … … 557 557 if lix = adNexus then 558 558 begin 559 Frame( offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),559 Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36), 560 560 y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 561 Dump( offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295)561 Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295) 562 562 end 563 563 else if lix = adNone then 564 564 begin 565 Frame( offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),565 Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36), 566 566 y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 567 Dump( offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295)567 Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295) 568 568 end 569 569 else if lix = adMilitary then 570 570 begin 571 Frame( offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),571 Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36), 572 572 y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 573 Dump( offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295)573 Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295) 574 574 end 575 575 else 576 576 begin 577 Frame( offscreen.Canvas, (8 + 16 - 1), y0 - 1,577 Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, 578 578 (8 + 16 + xSizeSmall), y0 + ySizeSmall, 579 579 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 580 580 if AdvIcon[lix] < 84 then 581 BitBltCanvas( offscreen.Canvas, (8 + 16), y0, xSizeSmall,581 BitBltCanvas(Offscreen.Canvas, (8 + 16), y0, xSizeSmall, 582 582 ySizeSmall, SmallImp.Canvas, 583 583 (AdvIcon[lix] + SystemIconLines * 7) mod 7 * xSizeSmall, … … 585 585 ySizeSmall) 586 586 else 587 Dump( offscreen, HGrSystem, (8 + 16), y0, 36, 20,587 Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 588 588 1 + (AdvIcon[lix] - 84) mod 8 * 37, 589 589 295 + (AdvIcon[lix] - 84) div 8 * 21); 590 j:= AdvValue[lix] div 1000;591 BitBltCanvas( offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14,592 HGrSystem.Mask.Canvas, 127 + j* 15,590 J := AdvValue[lix] div 1000; 591 BitBltCanvas(Offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14, 592 HGrSystem.Mask.Canvas, 127 + J * 15, 593 593 85, SRCAND); 594 Sprite( offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14,595 127 + j* 15, 85);594 Sprite(Offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14, 595 127 + J * 15, 85); 596 596 end; 597 597 end; … … 600 600 if NonText and (Kind in [kAdvance, kScience]) then 601 601 begin // show research state 602 for j:= 0 to nColumn - 1 do602 for J := 0 to nColumn - 1 do 603 603 begin 604 604 FutureCount := 0; 605 if j= 0 then // own science605 if J = 0 then // own science 606 606 if lix = MyRO.ResearchTech then 607 607 begin 608 Server(sGetTechCost, me, 0, icon);608 Server(sGetTechCost, Me, 0, icon); 609 609 icon := 4 + MyRO.Research * 4 div icon; 610 610 if icon > 4 + 3 then … … 625 625 icon := -1 626 626 else 627 with MyRO.EnemyReport[Column[ j]]^ do // enemy science628 if (MyRO.Alive and (1 shl Column[ j]) <> 0) and627 with MyRO.EnemyReport[Column[J]]^ do // enemy science 628 if (MyRO.Alive and (1 shl Column[J]) <> 0) and 629 629 (TurnOfCivilReport >= 0) and (lix = ResearchTech) and 630 630 ((lix = adMilitary) or (lix in FutureTech) or … … 649 649 icon := -1; 650 650 if icon >= 0 then 651 Sprite( offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace +652 24 * j, y0 + 3, 14, 14, 67 + icon * 15, 85)651 Sprite(Offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace + 652 24 * J, y0 + 3, 14, 14, 67 + icon * 15, 85) 653 653 else if (Kind = kScience) and (FutureCount > 0) then 654 654 begin 655 number := inttostr(FutureCount);656 RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * j-655 number := IntToStr(FutureCount); 656 RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * J - 657 657 BiColorTextWidth(ca, number) div 2, y0, number); 658 658 end; … … 661 661 end; // kAdvance, kScience 662 662 kTribe: 663 s:= TribeNames[lix];663 S := TribeNames[lix]; 664 664 kShipPart: 665 665 begin 666 s:= Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +667 inttostr(MyRO.Ship[me].Parts[lix]) + ')';666 S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' + 667 IntToStr(MyRO.Ship[Me].Parts[lix]) + ')'; 668 668 if NonText then 669 669 DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix); … … 671 671 kEShipPart: 672 672 begin 673 s:= Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +674 inttostr(MyRO.Ship[DipMem[me].pContact].Parts[lix]) + ')';673 S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' + 674 IntToStr(MyRO.Ship[DipMem[Me].pContact].Parts[lix]) + ')'; 675 675 if NonText then 676 676 DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix); … … 678 678 kGov: 679 679 begin 680 s:= Phrases.Lookup('GOVERNMENT', lix);680 S := Phrases.Lookup('GOVERNMENT', lix); 681 681 if NonText then 682 682 begin 683 Frame( offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2),683 Frame(Offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2), 684 684 8 + 16 + xSizeSmall, y0 - 15 + (16 - 1 + ySizeSmall), 685 685 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 686 BitBltCanvas( offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1),686 BitBltCanvas(Offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1), 687 687 xSizeSmall, ySizeSmall, SmallImp.Canvas, 688 688 (lix - 1) * xSizeSmall, ySizeSmall); … … 690 690 end; 691 691 kMission: 692 s:= Phrases.Lookup('SPYMISSION', lix);692 S := Phrases.Lookup('SPYMISSION', lix); 693 693 end; 694 694 case Kind of 695 695 kTribe, kMission: // center text 696 696 if Lines[0] > MaxLines then 697 x:= (InnerWidth - GetSystemMetrics(SM_CXVSCROLL)) div 2 -698 BiColorTextWidth(ca, s) div 2697 X := (InnerWidth - GetSystemMetrics(SM_CXVSCROLL)) div 2 - 698 BiColorTextWidth(ca, S) div 2 699 699 else 700 x := InnerWidth div 2 - BiColorTextWidth(ca, s) div 2;700 X := InnerWidth div 2 - BiColorTextWidth(ca, S) div 2; 701 701 kAdvance, kFarAdvance, kScience, kChooseTech, kChooseETech, 702 702 kStealTech, kGov: 703 x:= 104 - 33;703 X := 104 - 33; 704 704 kAllEModels: 705 x:= 104;705 X := 104; 706 706 else 707 x:= 104 + 15;707 X := 104 + 15; 708 708 end; 709 y:= y0;709 Y := y0; 710 710 if ca = Canvas then 711 711 begin 712 x := x+ SideFrame;713 y := y+ TitleHeight;712 X := X + SideFrame; 713 Y := Y + TitleHeight; 714 714 end; 715 715 if lit then … … 718 718 TextColor := -1; 719 719 { if Kind=kTribe then ReplaceText_Tribe(x,y,TextColor, 720 integer(TribeNames.Objects[lix]),s)721 else } ReplaceText( x, y, TextColor, s);720 Integer(TribeNames.Objects[lix]),S) 721 else } ReplaceText(X, Y, TextColor, S); 722 722 end; 723 723 end; … … 725 725 procedure TListDlg.OffscreenPaint; 726 726 var 727 i, j: integer;727 I, J: Integer; 728 728 begin 729 729 case Kind of 730 730 kCities: 731 Caption := Tribe[ me].TPhrase('TITLE_CITIES');731 Caption := Tribe[Me].TPhrase('TITLE_CITIES'); 732 732 kCityEvents: 733 733 Caption := Format(Phrases.Lookup('TITLE_EVENTS'), … … 736 736 737 737 inherited; 738 offscreen.Canvas.Font.Assign(UniFont[ftNormal]);738 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 739 739 FillOffscreen(0, 0, InnerWidth, InnerHeight); 740 with offscreen.Canvas do740 with Offscreen.Canvas do 741 741 begin 742 742 if Kind = kScience then 743 for i:= 1 to nColumn - 1 do743 for I := 1 to nColumn - 1 do 744 744 begin 745 745 Pen.Color := $000000; 746 MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i, 0);747 LineTo(104 - 33 + 15 + TechNameSpace + 24 * i, InnerHeight);748 MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, 0);749 LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, InnerHeight);750 if MyRO.EnemyReport[Column[ i]].TurnOfCivilReport >= MyRO.Turn - 1 then751 begin 752 brush.Color := Tribe[Column[i]].Color;753 fillrect(rect(104 - 33 + 14 + TechNameSpace + 24 * i+ 1 * 2, 0,754 104 - 33 + 17 + TechNameSpace + 24 * i+ 8 * 2, InnerHeight));755 brush.style := bsClear;746 MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I, 0); 747 LineTo(104 - 33 + 15 + TechNameSpace + 24 * I, InnerHeight); 748 MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, 0); 749 LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, InnerHeight); 750 if MyRO.EnemyReport[Column[I]].TurnOfCivilReport >= MyRO.Turn - 1 then 751 begin 752 Brush.Color := Tribe[Column[I]].Color; 753 FillRect(rect(104 - 33 + 14 + TechNameSpace + 24 * I + 1 * 2, 0, 754 104 - 33 + 17 + TechNameSpace + 24 * I + 8 * 2, InnerHeight)); 755 Brush.style := bsClear; 756 756 end 757 757 else 758 758 begin // colored player columns 759 Pen.Color := Tribe[Column[ i]].Color;760 for j:= 1 to 8 do761 begin 762 MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i + j* 2, 0);763 LineTo(104 - 33 + 15 + TechNameSpace + 24 * i + j* 2, InnerHeight);764 end; 765 end; 766 end; 767 768 for i:= -1 to DispLines do769 if ( i + ScrollBar.Position >= 0) and (i+ ScrollBar.Position < Lines[Layer]) then770 Self. line(offscreen.Canvas, i, true, false);759 Pen.Color := Tribe[Column[I]].Color; 760 for J := 1 to 8 do 761 begin 762 MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, 0); 763 LineTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, InnerHeight); 764 end; 765 end; 766 end; 767 768 for I := -1 to DispLines do 769 if (I + ScrollBar.Position >= 0) and (I + ScrollBar.Position < Lines[Layer]) then 770 Self.Line(Offscreen.Canvas, I, True, False); 771 771 end; 772 772 MarkUsedOffscreen(InnerWidth, 8 + 48 + DispLines * LineDistance); … … 774 774 775 775 procedure TListDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 776 x, y: integer);776 X, Y: Integer); 777 777 var 778 i0, Sel0, iColumn, OldScienceNation, xScreen: integer;779 s: string;780 begin 781 y := y- TitleHeight;778 i0, Sel0, iColumn, OldScienceNation, xScreen: Integer; 779 S: string; 780 begin 781 Y := Y - TitleHeight; 782 782 i0 := ScrollBar.Position; 783 783 Sel0 := Selected; 784 if ( x >= SideFrame) and (x < SideFrame + InnerWidth) and (y>= 0) and785 ( y < InnerHeight) and (y mod LineDistance >= 4) and (ymod LineDistance < 20)784 if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and 785 (Y < InnerHeight) and (Y mod LineDistance >= 4) and (Y mod LineDistance < 20) 786 786 then 787 Selected := ydiv LineDistance - 1787 Selected := Y div LineDistance - 1 788 788 else 789 789 Selected := -2; … … 794 794 begin 795 795 if Sel0 <> -2 then 796 line(Canvas, Sel0, false, false);796 Line(Canvas, Sel0, False, False); 797 797 if Selected <> -2 then 798 line(Canvas, Selected, false, true);798 Line(Canvas, Selected, False, True); 799 799 end; 800 800 … … 803 803 OldScienceNation := ScienceNation; 804 804 ScienceNation := -1; 805 if ( x>= SideFrame + (104 - 33 + 15 + TechNameSpace)) and806 (( x- SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and807 ( y >= 0) and (y< InnerHeight) then805 if (X >= SideFrame + (104 - 33 + 15 + TechNameSpace)) and 806 ((X - SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and 807 (Y >= 0) and (Y < InnerHeight) then 808 808 begin 809 iColumn := ( x- SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24;809 iColumn := (X - SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24; 810 810 if (iColumn >= 1) and (iColumn < nColumn) then 811 811 ScienceNation := Column[iColumn]; … … 818 818 if ScienceNation >= 0 then 819 819 begin 820 s:= Tribe[ScienceNation].TPhrase('SHORTNAME');820 S := Tribe[ScienceNation].TPhrase('SHORTNAME'); 821 821 if MyRO.Alive and (1 shl ScienceNation) = 0 then 822 s := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [s]) // extinct822 S := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [S]) // extinct 823 823 else if MyRO.EnemyReport[ScienceNation].TurnOfCivilReport < MyRO.Turn - 1 824 824 then 825 s := s+ ' (' + TurnToString(MyRO.EnemyReport[ScienceNation]825 S := S + ' (' + TurnToString(MyRO.EnemyReport[ScienceNation] 826 826 .TurnOfCivilReport) + ')'; // old report 827 xScreen := (ClientWidth - BiColorTextWidth(Canvas, s)) div 2;827 xScreen := (ClientWidth - BiColorTextWidth(Canvas, S)) div 2; 828 828 LoweredTextOut(Canvas, -1, MainTexture, xScreen + 10, 829 ClientHeight - 29, s);829 ClientHeight - 29, S); 830 830 BitBltCanvas(ScienceNationDotBuffer.Canvas, 0, 0, ScienceNationDot.Width, 831 831 ScienceNationDot.Height, Canvas, xScreen - 10, ClientHeight - 27); … … 853 853 end; 854 854 855 function TListDlg.RenameCity(cix: integer): boolean;855 function TListDlg.RenameCity(cix: Integer): Boolean; 856 856 var 857 857 CityNameInfo: TCityNameInfo; … … 870 870 (CityNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt); 871 871 Server(CommandWithData(cSetCityName, CityNameInfo.GetCommandDataSize), 872 me, 0, CityNameInfo);872 Me, 0, CityNameInfo); 873 873 if CityDlg.Visible then 874 874 begin … … 882 882 end; 883 883 884 function TListDlg.RenameModel(mix: integer): boolean;884 function TListDlg.RenameModel(mix: Integer): Boolean; 885 885 var 886 886 ModelNameInfo: TModelNameInfo; 887 887 begin 888 888 InputDlg.Caption := Phrases.Lookup('TITLE_MODELNAME'); 889 InputDlg.EInput.Text := Tribe[ me].ModelName[mix];889 InputDlg.EInput.Text := Tribe[Me].ModelName[mix]; 890 890 InputDlg.CenterToRect(BoundsRect); 891 891 InputDlg.ShowModal; 892 892 if (InputDlg.ModalResult = mrOK) and (InputDlg.EInput.Text <> '') and 893 (InputDlg.EInput.Text <> Tribe[ me].ModelName[mix]) then893 (InputDlg.EInput.Text <> Tribe[Me].ModelName[mix]) then 894 894 begin 895 895 ModelNameInfo.mix := mix; … … 899 899 (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt); 900 900 Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize), 901 me, 0, ModelNameInfo);901 Me, 0, ModelNameInfo); 902 902 if UnitStatDlg.Visible then 903 903 begin … … 905 905 UnitStatDlg.Invalidate; 906 906 end; 907 result := true;907 Result := True; 908 908 end 909 909 else 910 result := false;910 Result := False; 911 911 end; 912 912 913 913 procedure TListDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 914 Shift: TShiftState; x, y: integer);914 Shift: TShiftState; X, Y: Integer); 915 915 var 916 lix: integer;916 lix: Integer; 917 917 begin 918 918 if ScrollBar.Position + Selected >= 0 then 919 lix := code[Layer, ScrollBar.Position + Selected];919 lix := Code[Layer, ScrollBar.Position + Selected]; 920 920 if Kind in [kScience, kCities, kCityEvents, kModels, kEModels, kAllEModels] 921 921 then 922 include(Shift, ssShift); // don't close list window922 Include(Shift, ssShift); // don't close list window 923 923 if (ssLeft in Shift) and not(ssShift in Shift) then 924 924 begin 925 925 if Selected <> -2 then 926 926 begin 927 result := lix;928 Closable := true;927 Result := lix; 928 Closable := True; 929 929 Close; 930 930 end; … … 937 937 MainScreen.ZoomToCity(MyCity[lix].Loc); 938 938 kCityEvents: 939 MainScreen.ZoomToCity(MyCity[lix].Loc, false, MyCity[lix].Flags and939 MainScreen.ZoomToCity(MyCity[lix].Loc, False, MyCity[lix].Flags and 940 940 CityRepMask); 941 941 kModels, kChooseModel: … … 944 944 kEModels: 945 945 UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent, 946 code[1, ScrollBar.Position + Selected]);946 Code[1, ScrollBar.Position + Selected]); 947 947 kAllEModels, kChooseEModel: 948 948 if lix <> mixAll then … … 987 987 procedure TListDlg.InitLines; 988 988 var 989 required: array [0 .. nAdv - 1] of integer;990 991 procedure TryAddImpLine(Layer, Project: integer);992 begin 993 if Server(sSetCityProject - sExecute, me, cixProject, Project) >= rExecuted989 required: array [0 .. nAdv - 1] of Integer; 990 991 procedure TryAddImpLine(Layer, Project: Integer); 992 begin 993 if Server(sSetCityProject - sExecute, Me, cixProject, Project) >= rExecuted 994 994 then 995 995 begin 996 code[Layer, Lines[Layer]] := Project;997 inc(Lines[Layer]);996 Code[Layer, Lines[Layer]] := Project; 997 Inc(Lines[Layer]); 998 998 end; 999 999 end; … … 1001 1001 procedure SortTechs; 1002 1002 var 1003 i, j, swap: integer;1003 I, J, swap: Integer; 1004 1004 begin // sort by advancedness 1005 for i:= 0 to Lines[0] - 2 do1006 if code[0, i] < adMilitary then1007 for j := i+ 1 to Lines[0] - 1 do1008 if AdvValue[ code[0, i]] * nAdv + code[0, i] < AdvValue[code[0, j]] *1009 nAdv + code[0, j] then1010 begin 1011 swap := code[0, i];1012 code[0, i] := code[0, j];1013 code[0, j] := swap;1005 for I := 0 to Lines[0] - 2 do 1006 if Code[0, I] < adMilitary then 1007 for J := I + 1 to Lines[0] - 1 do 1008 if AdvValue[Code[0, I]] * nAdv + Code[0, I] < AdvValue[Code[0, J]] * 1009 nAdv + Code[0, J] then 1010 begin 1011 swap := Code[0, I]; 1012 Code[0, I] := Code[0, J]; 1013 Code[0, J] := swap; 1014 1014 end; 1015 1015 end; … … 1017 1017 procedure SortCities; 1018 1018 var 1019 i, j, swap: integer;1020 begin 1021 for i:= 0 to Lines[0] - 2 do1022 for j := i+ 1 to Lines[0] - 1 do1023 if CityName(MyCity[ code[0, i]].ID) > CityName(MyCity[code[0, j]].ID)1019 I, J, swap: Integer; 1020 begin 1021 for I := 0 to Lines[0] - 2 do 1022 for J := I + 1 to Lines[0] - 1 do 1023 if CityName(MyCity[Code[0, I]].ID) > CityName(MyCity[Code[0, J]].ID) 1024 1024 then 1025 1025 begin 1026 swap := code[0, i];1027 code[0, i] := code[0, j];1028 code[0, j] := swap;1026 swap := Code[0, I]; 1027 Code[0, I] := Code[0, J]; 1028 Code[0, J] := swap; 1029 1029 end; 1030 1030 end; 1031 1031 1032 1032 function ModelSortValue(const mi: TModelInfo; 1033 MixPlayers: boolean = false): integer;1034 begin 1035 result := (mi.Domain + 1) shl 28 - mi.mix;1033 MixPlayers: Boolean = False): Integer; 1034 begin 1035 Result := (mi.Domain + 1) shl 28 - mi.mix; 1036 1036 if MixPlayers then 1037 dec(result, ModelCode(mi) shl 16);1037 Dec(Result, ModelCode(mi) shl 16); 1038 1038 end; 1039 1039 1040 1040 procedure SortModels; 1041 1041 var 1042 i, j, swap: integer;1042 I, J, swap: Integer; 1043 1043 begin // sort by code[2] 1044 for i:= 0 to Lines[0] - 2 do1045 for j := i+ 1 to Lines[0] - 1 do1046 if code[2, i] > code[2, j] then1047 begin 1048 swap := code[0, i];1049 code[0, i] := code[0, j];1050 code[0, j] := swap;1051 swap := code[1, i];1052 code[1, i] := code[1, j];1053 code[1, j] := swap;1054 swap := code[2, i];1055 code[2, i] := code[2, j];1056 code[2, j] := swap;1057 end; 1058 end; 1059 1060 procedure MarkPreqs( i: integer);1061 begin 1062 required[ i] := 1;1063 if MyRO.Tech[ i] < tsSeen then1044 for I := 0 to Lines[0] - 2 do 1045 for J := I + 1 to Lines[0] - 1 do 1046 if Code[2, I] > Code[2, J] then 1047 begin 1048 swap := Code[0, I]; 1049 Code[0, I] := Code[0, J]; 1050 Code[0, J] := swap; 1051 swap := Code[1, I]; 1052 Code[1, I] := Code[1, J]; 1053 Code[1, J] := swap; 1054 swap := Code[2, I]; 1055 Code[2, I] := Code[2, J]; 1056 Code[2, J] := swap; 1057 end; 1058 end; 1059 1060 procedure MarkPreqs(I: Integer); 1061 begin 1062 required[I] := 1; 1063 if MyRO.Tech[I] < tsSeen then 1064 1064 begin 1065 if (AdvPreq[ i, 0] >= 0) then1066 MarkPreqs(AdvPreq[ i, 0]);1067 if (AdvPreq[ i, 1] >= 0) then1068 MarkPreqs(AdvPreq[ i, 1]);1065 if (AdvPreq[I, 0] >= 0) then 1066 MarkPreqs(AdvPreq[I, 0]); 1067 if (AdvPreq[I, 1] >= 0) then 1068 MarkPreqs(AdvPreq[I, 1]); 1069 1069 end; 1070 1070 end; 1071 1071 1072 1072 var 1073 Loc1, i, j, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: integer;1073 Loc1, I, J, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: Integer; 1074 1074 mi: TModelInfo; 1075 1075 PPicture, PTestPicture: ^TModelPicture; 1076 ModelOk: array [0 .. 4095] of boolean;1077 ok: boolean;1078 begin 1079 for i:= 0 to MaxLayer - 1 do1080 begin 1081 Lines[ i] := 0;1082 FirstShrinkedLine[ i] := MaxInt;1076 ModelOk: array [0 .. 4095] of Boolean; 1077 ok: Boolean; 1078 begin 1079 for I := 0 to MaxLayer - 1 do 1080 begin 1081 Lines[I] := 0; 1082 FirstShrinkedLine[I] := MaxInt; 1083 1083 end; 1084 1084 case Kind of … … 1086 1086 begin 1087 1087 // improvements 1088 code[0, 0] := cpImp + imTrGoods;1088 Code[0, 0] := cpImp + imTrGoods; 1089 1089 Lines[0] := 1; 1090 for i:= nWonder to nImp - 1 do1091 if Imp[ i].Kind = ikCommon then1092 TryAddImpLine(0, i+ cpImp);1093 for i:= nWonder to nImp - 1 do1094 if not(Imp[ i].Kind in [ikCommon, ikTrGoods]) and1095 ((MyRO.NatBuilt[ i] = 0) or (Imp[i].Kind = ikNatLocal)) then1096 TryAddImpLine(0, i+ cpImp);1097 for i:= 0 to nCityType - 1 do1098 if MyData.ImpOrder[ i, 0] >= 0 then1099 begin 1100 code[0, Lines[0]] := cpType + i;1101 inc(Lines[0]);1090 for I := nWonder to nImp - 1 do 1091 if Imp[I].Kind = ikCommon then 1092 TryAddImpLine(0, I + cpImp); 1093 for I := nWonder to nImp - 1 do 1094 if not(Imp[I].Kind in [ikCommon, ikTrGoods]) and 1095 ((MyRO.NatBuilt[I] = 0) or (Imp[I].Kind = ikNatLocal)) then 1096 TryAddImpLine(0, I + cpImp); 1097 for I := 0 to nCityType - 1 do 1098 if MyData.ImpOrder[I, 0] >= 0 then 1099 begin 1100 Code[0, Lines[0]] := cpType + I; 1101 Inc(Lines[0]); 1102 1102 end; 1103 1103 1104 1104 // wonders 1105 for i:= 0 to nWonder - 1 do1106 TryAddImpLine(1, i+ cpImp);1105 for I := 0 to nWonder - 1 do 1106 TryAddImpLine(1, I + cpImp); 1107 1107 1108 1108 // units 1109 for i:= 0 to MyRO.nModel - 1 do1109 for I := 0 to MyRO.nModel - 1 do 1110 1110 begin 1111 1111 { if MyModel[i].Kind=mkSlaves then 1112 ok:= MyRO.Wonder[woPyramids].EffectiveOwner= me1113 else } if MyModel[ i].Domain = dSea then1114 begin 1115 ok := false;1112 ok:= MyRO.Wonder[woPyramids].EffectiveOwner=Me 1113 else } if MyModel[I].Domain = dSea then 1114 begin 1115 ok := False; 1116 1116 for dx := -2 to 2 do 1117 1117 for dy := -2 to 2 do … … 1122 1122 ((MyMap[Loc1] and fTerrain = fShore) or 1123 1123 (MyMap[Loc1] and fCanal > 0)) then 1124 ok := true;1124 ok := True; 1125 1125 end; 1126 1126 end 1127 1127 else 1128 ok := true;1128 ok := True; 1129 1129 if ok then 1130 1130 begin 1131 if MyModel[ i].Status and msObsolete = 0 then1131 if MyModel[I].Status and msObsolete = 0 then 1132 1132 begin 1133 code[2, Lines[2]] := i;1134 inc(Lines[2]);1133 Code[2, Lines[2]] := I; 1134 Inc(Lines[2]); 1135 1135 end; 1136 if MyModel[ i].Status and msAllowConscripts <> 0 then1136 if MyModel[I].Status and msAllowConscripts <> 0 then 1137 1137 begin 1138 code[2, Lines[2]] := i+ cpConscripts;1139 inc(Lines[2]);1138 Code[2, Lines[2]] := I + cpConscripts; 1139 Inc(Lines[2]); 1140 1140 end; 1141 1141 end; … … 1151 1151 MarkPreqs(MyData.FarTech); 1152 1152 end; 1153 for i:= 0 to nAdv - 1 do1154 if (( i in FutureTech) or (MyRO.Tech[i] < tsApplicable)) and1155 (Server(sSetResearch - sExecute, me, i, nil^) >= rExecuted) and1156 ((MyData.FarTech = adNone) or (required[ i] > 0)) then1157 begin 1158 code[0, Lines[0]] := i;1159 inc(Lines[0]);1153 for I := 0 to nAdv - 1 do 1154 if ((I in FutureTech) or (MyRO.Tech[I] < tsApplicable)) and 1155 (Server(sSetResearch - sExecute, Me, I, nil^) >= rExecuted) and 1156 ((MyData.FarTech = adNone) or (required[I] > 0)) then 1157 begin 1158 Code[0, Lines[0]] := I; 1159 Inc(Lines[0]); 1160 1160 end; 1161 1161 SortTechs; 1162 1162 if Lines[0] = 0 then // no more techs -- offer nexus 1163 1163 begin 1164 code[0, Lines[0]] := adNexus;1165 inc(Lines[0]);1166 end; 1167 ok := false;1168 for i:= 0 to nDomains - 1 do1169 if (upgrade[ i, 0].Preq = preNone) or1170 (MyRO.Tech[upgrade[ i, 0].Preq] >= tsApplicable) then1171 ok := true;1164 Code[0, Lines[0]] := adNexus; 1165 Inc(Lines[0]); 1166 end; 1167 ok := False; 1168 for I := 0 to nDomains - 1 do 1169 if (upgrade[I, 0].Preq = preNone) or 1170 (MyRO.Tech[upgrade[I, 0].Preq] >= tsApplicable) then 1171 ok := True; 1172 1172 if ok then { new unit class } 1173 1173 begin 1174 code[0, Lines[0]] := adMilitary;1175 inc(Lines[0]);1174 Code[0, Lines[0]] := adMilitary; 1175 Inc(Lines[0]); 1176 1176 end; 1177 1177 end; 1178 1178 kFarAdvance: 1179 1179 begin 1180 code[0, Lines[0]] := adNone;1181 inc(Lines[0]);1182 for i:= 0 to nAdv - 1 do1183 if not( i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and1184 ((AdvValue[ i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and1185 ((AdvValue[ i] < 1000) or (MyRO.Tech[adScience] > tsNA)) then1186 begin 1187 code[0, Lines[0]] := i;1188 inc(Lines[0]);1180 Code[0, Lines[0]] := adNone; 1181 Inc(Lines[0]); 1182 for I := 0 to nAdv - 1 do 1183 if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and 1184 ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and 1185 ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) then 1186 begin 1187 Code[0, Lines[0]] := I; 1188 Inc(Lines[0]); 1189 1189 end; 1190 1190 SortTechs; … … 1192 1192 kChooseTech: 1193 1193 begin 1194 for i:= 0 to nAdv - 1 do1195 if not( i in FutureTech) and (MyRO.Tech[i] >= tsApplicable) and1196 (MyRO.EnemyReport[DipMem[ me].pContact].Tech[i] < tsSeen) then1197 begin 1198 code[0, Lines[0]] := i;1199 inc(Lines[0]);1194 for I := 0 to nAdv - 1 do 1195 if not(I in FutureTech) and (MyRO.Tech[I] >= tsApplicable) and 1196 (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) then 1197 begin 1198 Code[0, Lines[0]] := I; 1199 Inc(Lines[0]); 1200 1200 end; 1201 1201 SortTechs; 1202 1202 // if Lines[0]>1 then 1203 1203 begin 1204 code[0, Lines[0]] := adAll;1205 inc(Lines[0]);1204 Code[0, Lines[0]] := adAll; 1205 Inc(Lines[0]); 1206 1206 end; 1207 1207 end; 1208 1208 kChooseETech: 1209 1209 begin 1210 for i:= 0 to nAdv - 1 do1211 if not( i in FutureTech) and (MyRO.Tech[i] < tsSeen) and1212 (MyRO.EnemyReport[DipMem[ me].pContact].Tech[i] >= tsApplicable) then1213 begin 1214 code[0, Lines[0]] := i;1215 inc(Lines[0]);1210 for I := 0 to nAdv - 1 do 1211 if not(I in FutureTech) and (MyRO.Tech[I] < tsSeen) and 1212 (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then 1213 begin 1214 Code[0, Lines[0]] := I; 1215 Inc(Lines[0]); 1216 1216 end; 1217 1217 SortTechs; 1218 1218 // if Lines[0]>1 then 1219 1219 begin 1220 code[0, Lines[0]] := adAll;1221 inc(Lines[0]);1220 Code[0, Lines[0]] := adAll; 1221 Inc(Lines[0]); 1222 1222 end; 1223 1223 end; 1224 1224 kStealTech: 1225 1225 begin 1226 for i:= 0 to nAdv - 1 do1227 if Server(sStealTech - sExecute, me, i, nil^) >= rExecuted then1228 begin 1229 code[0, Lines[0]] := i;1230 inc(Lines[0]);1226 for I := 0 to nAdv - 1 do 1227 if Server(sStealTech - sExecute, Me, I, nil^) >= rExecuted then 1228 begin 1229 Code[0, Lines[0]] := I; 1230 Inc(Lines[0]); 1231 1231 end; 1232 1232 SortTechs; … … 1234 1234 kScience: 1235 1235 begin 1236 Column[0] := me;1236 Column[0] := Me; 1237 1237 nColumn := 1; 1238 1238 for EnemyType := 0 to 2 do … … 1252 1252 begin 1253 1253 Column[nColumn] := p1; 1254 inc(nColumn);1254 Inc(nColumn); 1255 1255 end; 1256 1256 end; 1257 for i:= 0 to nAdv - 1 do1258 begin 1259 ok := (MyRO.Tech[ i] <> tsNA) or (MyRO.ResearchTech = i);1260 for j:= 1 to nColumn - 1 do1261 with MyRO.EnemyReport[Column[ j]]^ do1262 if (Tech[ i] <> tsNA) or (TurnOfCivilReport >= 0) and1263 (ResearchTech = i) then1264 ok := true;1257 for I := 0 to nAdv - 1 do 1258 begin 1259 ok := (MyRO.Tech[I] <> tsNA) or (MyRO.ResearchTech = I); 1260 for J := 1 to nColumn - 1 do 1261 with MyRO.EnemyReport[Column[J]]^ do 1262 if (Tech[I] <> tsNA) or (TurnOfCivilReport >= 0) and 1263 (ResearchTech = I) then 1264 ok := True; 1265 1265 if ok then 1266 1266 begin 1267 code[0, Lines[0]] := i;1268 inc(Lines[0]);1267 Code[0, Lines[0]] := I; 1268 Inc(Lines[0]); 1269 1269 end; 1270 1270 end; … … 1272 1272 1273 1273 ok := MyRO.ResearchTech = adMilitary; 1274 for j:= 1 to nColumn - 1 do1275 with MyRO.EnemyReport[Column[ j]]^ do1276 if (MyRO.Alive and (1 shl Column[ j]) <> 0) and1274 for J := 1 to nColumn - 1 do 1275 with MyRO.EnemyReport[Column[J]]^ do 1276 if (MyRO.Alive and (1 shl Column[J]) <> 0) and 1277 1277 (TurnOfCivilReport >= 0) and (ResearchTech = adMilitary) then 1278 ok := true;1278 ok := True; 1279 1279 if ok then 1280 1280 begin 1281 code[0, Lines[0]] := adMilitary;1282 inc(Lines[0]);1281 Code[0, Lines[0]] := adMilitary; 1282 Inc(Lines[0]); 1283 1283 end 1284 1284 end; … … 1286 1286 begin 1287 1287 if ClientMode < scContact then 1288 for i:= 0 to MyRO.nCity - 1 do1289 if MyCity[ i].Loc >= 0 then1288 for I := 0 to MyRO.nCity - 1 do 1289 if MyCity[I].Loc >= 0 then 1290 1290 begin 1291 code[0, Lines[0]] := i;1292 inc(Lines[0]);1291 Code[0, Lines[0]] := I; 1292 Inc(Lines[0]); 1293 1293 end; 1294 1294 SortCities; … … 1297 1297 kCityEvents: 1298 1298 begin 1299 for i:= 0 to MyRO.nCity - 1 do1300 if (MyCity[ i].Loc >= 0) and (MyCity[i].Flags and CityRepMask <> 0)1299 for I := 0 to MyRO.nCity - 1 do 1300 if (MyCity[I].Loc >= 0) and (MyCity[I].Flags and CityRepMask <> 0) 1301 1301 then 1302 1302 begin 1303 code[0, Lines[0]] := i;1304 inc(Lines[0]);1303 Code[0, Lines[0]] := I; 1304 Inc(Lines[0]); 1305 1305 end; 1306 1306 SortCities; … … 1309 1309 { kChooseECity: 1310 1310 begin 1311 for i:=0 to MyRO.nEnemyCity-1 do1312 if (MyRO.EnemyCity[ i].Loc>=0)1313 and (MyRO.EnemyCity[ i].owner=DipMem[me].pContact) then1314 begin code[0,Lines[0]]:=i; inc(Lines[0]); end;1311 for I:=0 to MyRO.nEnemyCity-1 do 1312 if (MyRO.EnemyCity[I].Loc>=0) 1313 and (MyRO.EnemyCity[I].owner=DipMem[Me].pContact) then 1314 begin Code[0,Lines[0]]:=I; Inc(Lines[0]); end; 1315 1315 FirstShrinkedLine:=0 1316 1316 end; } … … 1319 1319 for mix := 0 to MyRO.nModel - 1 do 1320 1320 begin 1321 code[0, mix] := mix;1322 MakeModelInfo( me, mix, MyModel[mix], mi);1323 code[2, mix] := ModelSortValue(mi);1321 Code[0, mix] := mix; 1322 MakeModelInfo(Me, mix, MyModel[mix], mi); 1323 Code[2, mix] := ModelSortValue(mi); 1324 1324 end; 1325 1325 Lines[0] := MyRO.nModel; … … 1331 1331 for mix := 3 to MyRO.nModel - 1 do 1332 1332 begin // check if opponent already has this model 1333 MakeModelInfo( me, mix, MyModel[mix], mi);1334 ok := true;1333 MakeModelInfo(Me, mix, MyModel[mix], mi); 1334 ok := True; 1335 1335 for emix := 0 to MyRO.nEnemyModel - 1 do 1336 if (MyRO.EnemyModel[emix].Owner = DipMem[ me].pContact) and1336 if (MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact) and 1337 1337 IsSameModel(MyRO.EnemyModel[emix], mi) then 1338 ok := false;1338 ok := False; 1339 1339 if ok then 1340 1340 begin 1341 code[0, Lines[0]] := mix;1342 MakeModelInfo( me, mix, MyModel[mix], mi);1343 code[2, Lines[0]] := ModelSortValue(mi);1344 inc(Lines[0]);1341 Code[0, Lines[0]] := mix; 1342 MakeModelInfo(Me, mix, MyModel[mix], mi); 1343 Code[2, Lines[0]] := ModelSortValue(mi); 1344 Inc(Lines[0]); 1345 1345 end; 1346 1346 end; … … 1348 1348 // if Lines[0]>1 then 1349 1349 begin 1350 code[0, Lines[0]] := mixAll;1351 inc(Lines[0]);;1350 Code[0, Lines[0]] := mixAll; 1351 Inc(Lines[0]);; 1352 1352 end; 1353 1353 FirstShrinkedLine[0] := 0; … … 1356 1356 begin 1357 1357 if MyRO.TestFlags and tfUncover <> 0 then 1358 Server(sGetModels, me, 0, nil^);1358 Server(sGetModels, Me, 0, nil^); 1359 1359 for emix := 0 to MyRO.nEnemyModel - 1 do 1360 ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[ me].pContact;1360 ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact; 1361 1361 for mix := 0 to MyRO.nModel - 1 do 1362 1362 begin // don't list models I already have 1363 MakeModelInfo( me, mix, MyModel[mix], mi);1363 MakeModelInfo(Me, mix, MyModel[mix], mi); 1364 1364 for emix := 0 to MyRO.nEnemyModel - 1 do 1365 1365 ModelOk[emix] := ModelOk[emix] and … … 1369 1369 if ModelOk[emix] then 1370 1370 begin 1371 if not Assigned(Tribe[DipMem[ me].pContact].ModelPicture1371 if not Assigned(Tribe[DipMem[Me].pContact].ModelPicture 1372 1372 [MyRO.EnemyModel[emix].mix].HGr) then 1373 1373 InitEnemyModel(emix); 1374 code[0, Lines[0]] := emix;1375 code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]);1376 inc(Lines[0]);1374 Code[0, Lines[0]] := emix; 1375 Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]); 1376 Inc(Lines[0]); 1377 1377 end; 1378 1378 SortModels; 1379 1379 // if not IsMilReportNew(DipMem[me].pContact) or (Lines[0]>1) then 1380 1380 begin 1381 code[0, Lines[0]] := mixAll;1382 inc(Lines[0]);1381 Code[0, Lines[0]] := mixAll; 1382 Inc(Lines[0]); 1383 1383 end; 1384 1384 FirstShrinkedLine[0] := 0; … … 1386 1386 kEModels: 1387 1387 begin 1388 for i:= 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do1389 begin 1390 code[1, Lines[0]] := MyRO.nEnemyModel - 1;1391 while ( code[1, Lines[0]] >= 0) and1392 not((MyRO.EnemyModel[ code[1, Lines[0]]].Owner = pView) and1393 (MyRO.EnemyModel[ code[1, Lines[0]]].mix = i)) do1394 dec(code[1, Lines[0]]);1395 if not Assigned(Tribe[pView].ModelPicture[ i].HGr) then1396 InitEnemyModel( code[1, Lines[0]]);1397 code[0, Lines[0]] := i;1398 code[2, Lines[0]] :=1399 ModelSortValue(MyRO.EnemyModel[ code[1, Lines[0]]]);1400 inc(Lines[0]);1388 for I := 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do 1389 begin 1390 Code[1, Lines[0]] := MyRO.nEnemyModel - 1; 1391 while (Code[1, Lines[0]] >= 0) and 1392 not((MyRO.EnemyModel[Code[1, Lines[0]]].Owner = pView) and 1393 (MyRO.EnemyModel[Code[1, Lines[0]]].mix = I)) do 1394 Dec(Code[1, Lines[0]]); 1395 if not Assigned(Tribe[pView].ModelPicture[I].HGr) then 1396 InitEnemyModel(Code[1, Lines[0]]); 1397 Code[0, Lines[0]] := I; 1398 Code[2, Lines[0]] := 1399 ModelSortValue(MyRO.EnemyModel[Code[1, Lines[0]]]); 1400 Inc(Lines[0]); 1401 1401 end; 1402 1402 SortModels; … … 1405 1405 kAllEModels: 1406 1406 begin 1407 if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[ me] = 0) then1408 Server(sGetModels, me, 0, nil^);1407 if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[Me] = 0) then 1408 Server(sGetModels, Me, 0, nil^); 1409 1409 for emix := 0 to MyRO.nEnemyModel - 1 do 1410 1410 if (MyRO.EnemyModel[emix].mix >= 3) and … … 1416 1416 if not Assigned(PPicture.HGr) then 1417 1417 InitEnemyModel(emix); 1418 ok := true;1418 ok := True; 1419 1419 if MainScreen.mNames.Checked then 1420 for j:= 0 to Lines[0] - 1 do1420 for J := 0 to Lines[0] - 1 do 1421 1421 begin