Changeset 447
- Timestamp:
- May 19, 2022, 10:39:34 PM (2 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 1422 PTestPicture := @Tribe[MyRO.EnemyModel[ code[0, j]].Owner]1423 .ModelPicture[MyRO.EnemyModel[ code[0, j]].mix];1422 PTestPicture := @Tribe[MyRO.EnemyModel[Code[0, J]].Owner] 1423 .ModelPicture[MyRO.EnemyModel[Code[0, J]].mix]; 1424 1424 if (PPicture.HGr = PTestPicture.HGr) and 1425 1425 (PPicture.pix = PTestPicture.pix) and 1426 1426 (ModelHash(MyRO.EnemyModel[emix]) 1427 = ModelHash(MyRO.EnemyModel[ code[0, j]])) then1427 = ModelHash(MyRO.EnemyModel[Code[0, J]])) then 1428 1428 begin 1429 code[1, j] := 1;1430 ok := false;1429 Code[1, J] := 1; 1430 ok := False; 1431 1431 Break; 1432 1432 end; … … 1434 1434 if ok then 1435 1435 begin 1436 code[0, Lines[0]] := emix;1437 code[1, Lines[0]] := 0;1438 code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], true);1439 inc(Lines[0]);1436 Code[0, Lines[0]] := emix; 1437 Code[1, Lines[0]] := 0; 1438 Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], True); 1439 Inc(Lines[0]); 1440 1440 end; 1441 1441 end; … … 1444 1444 end; 1445 1445 kTribe: 1446 for i:= 0 to TribeNames.Count - 1 do1447 begin 1448 code[0, Lines[0]] := i;1449 inc(Lines[0]);1446 for I := 0 to TribeNames.Count - 1 do 1447 begin 1448 Code[0, Lines[0]] := I; 1449 Inc(Lines[0]); 1450 1450 end; 1451 1451 (* kDeliver: 1452 if MyRO.Treaty[DipMem[ me].pContact]<trAlliance then1452 if MyRO.Treaty[DipMem[Me].pContact]<trAlliance then 1453 1453 begin // suggest next treaty level 1454 code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]+1;1455 inc(Lines[0]);1456 end; 1457 if MyRO.Treaty[DipMem[ me].pContact]=trNone then1454 Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]+1; 1455 Inc(Lines[0]); 1456 end; 1457 if MyRO.Treaty[DipMem[Me].pContact]=trNone then 1458 1458 begin // suggest peace 1459 code[0,Lines[0]]:=opTreaty+trPeace;1460 inc(Lines[0]);1461 end; 1462 if MyRO.Treaty[DipMem[ me].pContact]>trNone then1459 Code[0,Lines[0]]:=opTreaty+trPeace; 1460 Inc(Lines[0]); 1461 end; 1462 if MyRO.Treaty[DipMem[Me].pContact]>trNone then 1463 1463 begin // suggest next treaty level 1464 code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;1465 inc(Lines[0]);1464 Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1; 1465 Inc(Lines[0]); 1466 1466 end; *) 1467 1467 kShipPart: 1468 1468 begin 1469 1469 Lines[0] := 0; 1470 for i:= 0 to nShipPart - 1 do1471 if MyRO.Ship[ me].Parts[i] > 0 then1472 begin 1473 code[0, Lines[0]] := i;1474 inc(Lines[0]);1470 for I := 0 to nShipPart - 1 do 1471 if MyRO.Ship[Me].Parts[I] > 0 then 1472 begin 1473 Code[0, Lines[0]] := I; 1474 Inc(Lines[0]); 1475 1475 end; 1476 1476 end; … … 1478 1478 begin 1479 1479 Lines[0] := 0; 1480 for i:= 0 to nShipPart - 1 do1481 if MyRO.Ship[DipMem[ me].pContact].Parts[i] > 0 then1482 begin 1483 code[0, Lines[0]] := i;1484 inc(Lines[0]);1480 for I := 0 to nShipPart - 1 do 1481 if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then 1482 begin 1483 Code[0, Lines[0]] := I; 1484 Inc(Lines[0]); 1485 1485 end; 1486 1486 end; 1487 1487 kGov: 1488 for i:= 1 to nGov - 1 do1489 if (GovPreq[ i] <> preNA) and1490 ((GovPreq[ i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable))1488 for I := 1 to nGov - 1 do 1489 if (GovPreq[I] <> preNA) and 1490 ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable)) 1491 1491 then 1492 1492 begin 1493 code[0, Lines[0]] := i;1494 inc(Lines[0]);1493 Code[0, Lines[0]] := I; 1494 Inc(Lines[0]); 1495 1495 end; 1496 1496 kMission: 1497 for i:= 0 to nSpyMission - 1 do1498 begin 1499 code[0, Lines[0]] := i;1500 inc(Lines[0]);1497 for I := 0 to nSpyMission - 1 do 1498 begin 1499 Code[0, Lines[0]] := I; 1500 Inc(Lines[0]); 1501 1501 end; 1502 1502 end; … … 1505 1505 if Lines[0] + Lines[1] + Lines[2] <= MaxLines then 1506 1506 begin 1507 for i:= 0 to Lines[1] - 1 do // add wonders to first page1508 begin 1509 code[0, Lines[0]] := code[1, i];1510 inc(Lines[0]);1507 for I := 0 to Lines[1] - 1 do // add wonders to first page 1508 begin 1509 Code[0, Lines[0]] := Code[1, I]; 1510 Inc(Lines[0]); 1511 1511 end; 1512 1512 Lines[1] := 0; 1513 1513 FirstShrinkedLine[0] := Lines[0]; 1514 for i:= 0 to Lines[2] - 1 do // add models to first page1515 begin 1516 code[0, Lines[0]] := code[2, i];1517 inc(Lines[0]);1514 for I := 0 to Lines[2] - 1 do // add models to first page 1515 begin 1516 Code[0, Lines[0]] := Code[2, I]; 1517 Inc(Lines[0]); 1518 1518 end; 1519 1519 Lines[2] := 0; … … 1521 1521 end; 1522 1522 1523 function TListDlg.OnlyChoice(TestKind: TListKind): integer;1523 function TListDlg.OnlyChoice(TestKind: TListKind): Integer; 1524 1524 begin 1525 1525 Kind := TestKind; 1526 1526 InitLines; 1527 1527 if Lines[0] = 0 then 1528 result := -21528 Result := -2 1529 1529 else if Lines[0] > 1 then 1530 result := -11530 Result := -1 1531 1531 else 1532 result := code[0, 0];1532 Result := Code[0, 0]; 1533 1533 end; 1534 1534 1535 1535 procedure TListDlg.FormShow(Sender: TObject); 1536 1536 var 1537 i: integer;1538 begin 1539 result := -1;1540 Closable := false;1537 I: Integer; 1538 begin 1539 Result := -1; 1540 Closable := False; 1541 1541 1542 1542 if Kind = kTribe then … … 1554 1554 InitLines; 1555 1555 1556 MultiPage := false;1557 for i:= 1 to MaxLayer - 1 do1558 if Lines[ i] > 0 then1559 MultiPage := true;1556 MultiPage := False; 1557 for I := 1 to MaxLayer - 1 do 1558 if Lines[I] > 0 then 1559 MultiPage := True; 1560 1560 WideBottom := MultiPage or (Kind = kScience) or 1561 1561 not Phrases2FallenBackToEnglish and … … 1571 1571 1572 1572 DispLines := Lines[0]; 1573 for i:= 0 to MaxLayer - 1 do1574 if Lines[ i] > DispLines then1575 DispLines := Lines[ i];1573 for I := 0 to MaxLayer - 1 do 1574 if Lines[I] > DispLines then 1575 DispLines := Lines[I]; 1576 1576 if WideBottom then 1577 1577 begin … … 1588 1588 ClientHeight := InnerHeight + TitleHeight + NarrowFrame; 1589 1589 end; 1590 assert(ClientHeight <= Maintexture.Height);1590 Assert(ClientHeight <= Maintexture.Height); 1591 1591 1592 1592 TechNameSpace := 224; … … 1649 1649 Layer0Btn.Top := ClientHeight - 31; 1650 1650 Layer0Btn.Left := ClientWidth div 2 - (12 + 29); 1651 Layer0Btn.Down := true;1651 Layer0Btn.Down := True; 1652 1652 Layer1Btn.Top := ClientHeight - 31; 1653 1653 Layer1Btn.Left := ClientWidth div 2 - (12 - 29); 1654 Layer1Btn.Down := false;1654 Layer1Btn.Down := False; 1655 1655 Layer2Btn.Top := ClientHeight - 31; 1656 1656 Layer2Btn.Left := ClientWidth div 2 - 12; 1657 Layer2Btn.Down := false;1657 Layer2Btn.Down := False; 1658 1658 end; 1659 1659 … … 1668 1668 procedure TListDlg.ShowNewContent(NewMode: TWindowMode; ListKind: TListKind); 1669 1669 var 1670 i: integer;1671 ShowFocus, forceclose: boolean;1670 I: Integer; 1671 ShowFocus, forceclose: Boolean; 1672 1672 begin 1673 1673 forceclose := (ListKind <> Kind) and … … 1733 1733 if Kind = kAdvance then // show focus button? 1734 1734 if MyData.FarTech <> adNone then 1735 ShowFocus := true1735 ShowFocus := True 1736 1736 else 1737 1737 begin 1738 ShowFocus := false;1739 for i:= 0 to nAdv - 1 do1740 if not( i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and1741 ((AdvValue[ i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and1742 ((AdvValue[ i] < 1000) or (MyRO.Tech[adScience] > tsNA)) and1743 (Server(sSetResearch - sExecute, me, i, nil^) < rExecuted) then1744 ShowFocus := true;1738 ShowFocus := False; 1739 for I := 0 to nAdv - 1 do 1740 if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and 1741 ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and 1742 ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) and 1743 (Server(sSetResearch - sExecute, Me, I, nil^) < rExecuted) then 1744 ShowFocus := True; 1745 1745 end; 1746 ToggleBtn.Visible := (Kind = kCities) and not supervising or (Kind = kAdvance)1746 ToggleBtn.Visible := (Kind = kCities) and not Supervising or (Kind = kAdvance) 1747 1747 and ShowFocus or (Kind = kModels) or (Kind = kEModels); 1748 1748 CloseBtn.Visible := not(Kind in MustChooseKind); … … 1751 1751 end; 1752 1752 1753 procedure TListDlg.ShowNewContent_CityProject(NewMode: TWindowMode; cix: integer);1753 procedure TListDlg.ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer); 1754 1754 begin 1755 1755 cixProject := cix; … … 1757 1757 end; 1758 1758 1759 procedure TListDlg.ShowNewContent_MilReport(NewMode: TWindowMode; p: integer);1760 begin 1761 pView := p;1762 if p = me then1759 procedure TListDlg.ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer); 1760 begin 1761 pView := P; 1762 if P = Me then 1763 1763 ShowNewContent(NewMode, kModels) 1764 1764 else … … 1768 1768 procedure TListDlg.PlayerClick(Sender: TObject); 1769 1769 begin 1770 if TComponent(Sender).Tag = me then1770 if TComponent(Sender).Tag = Me then 1771 1771 Kind := kModels 1772 1772 else … … 1796 1796 procedure TListDlg.ToggleBtnClick(Sender: TObject); 1797 1797 var 1798 p1: integer;1799 m: TMenuItem;1798 p1: Integer; 1799 M: TMenuItem; 1800 1800 begin 1801 1801 case Kind of 1802 1802 kAdvance: 1803 1803 begin 1804 result := adFar;1805 Closable := true;1804 Result := adFar; 1805 Closable := True; 1806 1806 Close; 1807 1807 end; … … 1818 1818 begin 1819 1819 EmptyMenu(Popup.Items); 1820 if G.Difficulty[ me] > 0 then1821 begin 1822 m:= TMenuItem.Create(Popup);1823 m.RadioItem := true;1824 m.Caption := Tribe[me].TPhrase('SHORTNAME');1825 m.Tag := me;1826 m.OnClick := PlayerClick;1820 if G.Difficulty[Me] > 0 then 1821 begin 1822 M := TMenuItem.Create(Popup); 1823 M.RadioItem := True; 1824 M.Caption := Tribe[Me].TPhrase('SHORTNAME'); 1825 M.Tag := Me; 1826 M.OnClick := PlayerClick; 1827 1827 if Kind = kModels then 1828 m.Checked := true;1829 Popup.Items.Add( m);1828 M.Checked := True; 1829 Popup.Items.Add(M); 1830 1830 end; 1831 1831 for p1 := 0 to nPl - 1 do 1832 if (p1 <> me) and (MyRO.EnemyReport[p1] <> nil) and1832 if (p1 <> Me) and (MyRO.EnemyReport[p1] <> nil) and 1833 1833 (MyRO.EnemyReport[p1].TurnOfMilReport >= 0) then 1834 1834 begin 1835 m:= TMenuItem.Create(Popup);1836 m.RadioItem := true;1837 m.Caption := Tribe[p1].TPhrase('SHORTNAME');1838 m.Tag := p1;1839 m.OnClick := PlayerClick;1835 M := TMenuItem.Create(Popup); 1836 M.RadioItem := True; 1837 M.Caption := Tribe[p1].TPhrase('SHORTNAME'); 1838 M.Tag := p1; 1839 M.OnClick := PlayerClick; 1840 1840 if (Kind = kEModels) and (p1 = pView) then 1841 m.Checked := true;1842 Popup.Items.Add( m);1841 M.Checked := True; 1842 Popup.Items.Add(M); 1843 1843 end; 1844 1844 Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + … … 1848 1848 end; 1849 1849 1850 procedure TListDlg.FormKeyDown(Sender: TObject; var Key: word;1850 procedure TListDlg.FormKeyDown(Sender: TObject; var Key: Word; 1851 1851 Shift: TShiftState); 1852 1852 begin … … 1894 1894 begin 1895 1895 Selected := -2; 1896 SmartUpdateContent( true);1896 SmartUpdateContent(True); 1897 1897 end; 1898 1898 -
trunk/LocalPlayer/TechTree.pas
r426 r447 55 55 yLegendPitch = 32; 56 56 57 function min(a, b: Integer): Integer;58 begin 59 if a < bthen60 result := a57 function Min(A, B: Integer): Integer; 58 begin 59 if A < B then 60 Result := A 61 61 else 62 result := b;63 end; 64 65 function max(a, b: Integer): Integer;66 begin 67 if a > bthen68 result := a62 Result := B; 63 end; 64 65 function Max(A, B: Integer): Integer; 66 begin 67 if A > B then 68 Result := A 69 69 else 70 result := b;70 Result := B; 71 71 end; 72 72 … … 84 84 procedure TTechTreeDlg.FormPaint(Sender: TObject); 85 85 var 86 X, w: Integer;86 X, W: Integer; 87 87 begin 88 88 with Canvas do begin 89 89 // black border 90 brush.color := $000000;91 fillrect(rect(0, 0, BlackBorder, ClientHeight));92 fillrect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));93 fillrect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));94 fillrect(rect(BlackBorder, ClientHeight - BlackBorder,90 Brush.Color := $000000; 91 FillRect(rect(0, 0, BlackBorder, ClientHeight)); 92 FillRect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder)); 93 FillRect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight)); 94 FillRect(rect(BlackBorder, ClientHeight - BlackBorder, 95 95 ClientWidth - BlackBorder, ClientHeight)); 96 96 97 97 // texturize empty space 98 brush.color := $FFFFFF;98 Brush.Color := $FFFFFF; 99 99 if xOffset > 0 then 100 100 FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset, … … 105 105 ClientWidth - BlackBorder, ClientHeight - BlackBorder, 106 106 -BlackBorder - xOffset, -BlackBorder - yOffset, Paper); 107 X := max(BlackBorder, BlackBorder + xOffset);108 w := min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);107 X := Max(BlackBorder, BlackBorder + xOffset); 108 W := Min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder); 109 109 if yOffset > 0 then 110 FillRectSeamless(Canvas, X, BlackBorder, w, BlackBorder + yOffset,110 FillRectSeamless(Canvas, X, BlackBorder, W, BlackBorder + yOffset, 111 111 -BlackBorder - xOffset, -BlackBorder - yOffset, Paper); 112 112 if yOffset + Image.height < ClientHeight - 2 * BlackBorder then 113 FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, w,113 FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, W, 114 114 ClientHeight - BlackBorder, -BlackBorder - xOffset, 115 115 -BlackBorder - yOffset, Paper); 116 116 end; 117 BitBltCanvas(Canvas, max(BlackBorder, BlackBorder + xOffset),118 max(BlackBorder, BlackBorder + yOffset),119 min(Image.width, min(Image.width + xOffset,120 min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))121 ), min(Image.height, min(Image.height + yOffset,122 min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -123 yOffset))), Image.Canvas, max(0, -xOffset),124 max(0, -yOffset));117 BitBltCanvas(Canvas, Max(BlackBorder, BlackBorder + xOffset), 118 Max(BlackBorder, BlackBorder + yOffset), 119 Min(Image.width, Min(Image.width + xOffset, 120 Min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset)) 121 ), Min(Image.height, Min(Image.height + yOffset, 122 Min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder - 123 yOffset))), Image.Canvas, Max(0, -xOffset), 124 Max(0, -yOffset)); 125 125 end; 126 126 … … 128 128 var 129 129 X, Y, ad: Integer; 130 s: string;130 S: string; 131 131 NewWidth: Integer; 132 132 NewHeight: Integer; … … 142 142 // write advance names 143 143 Font.Assign(UniFont[ftSmall]); 144 Font. color := clBlack;145 brush.Style := bsClear;144 Font.Color := clBlack; 145 Brush.Style := bsClear; 146 146 for X := 0 to (Image.width - xStart) div xPitch do 147 147 for Y := 0 to (Image.height - yStart) div yPitch do … … 150 150 if ad and $FFFF00 = 0 then 151 151 begin 152 s:= Phrases.Lookup('ADVANCES', ad);153 while TextWidth( s) > 112 do154 Delete( s, Length(s), 1);155 TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, s);152 S := Phrases.Lookup('ADVANCES', ad); 153 while TextWidth(S) > 112 do 154 Delete(S, Length(S), 1); 155 TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, S); 156 156 Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1] 157 157 := TransparentColor2; … … 191 191 if Button = mbLeft then 192 192 begin 193 dragging := true;193 dragging := True; 194 194 xDown := X; 195 195 yDown := Y; … … 200 200 Shift: TShiftState; X, Y: Integer); 201 201 begin 202 dragging := false;202 dragging := False; 203 203 end; 204 204 -
trunk/LocalPlayer/Term.pas
r442 r447 232 232 procedure Timer1Timer(Sender: TObject); 233 233 procedure MapBoxMouseDown(Sender: TObject; Button: TMouseButton; 234 Shift: TShiftState; x, y: integer);234 Shift: TShiftState; X, Y: Integer); 235 235 procedure EOTClick(Sender: TObject); 236 236 procedure PanelBoxMouseDown(Sender: TObject; Button: TMouseButton; 237 Shift: TShiftState; x, y: integer);238 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);237 Shift: TShiftState; X, Y: Integer); 238 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 239 239 procedure mDisbandOrUtilizeClick(Sender: TObject); 240 240 procedure FormResize(Sender: TObject); 241 241 procedure PanelBtnClick(Sender: TObject); 242 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);242 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 243 243 procedure Toggle(Sender: TObject); 244 244 procedure PanelBoxMouseMove(Sender: TObject; Shift: TShiftState; 245 x, y: integer);245 X, Y: Integer); 246 246 procedure PanelBoxMouseUp(Sender: TObject; Button: TMouseButton; 247 Shift: TShiftState; x, y: integer);247 Shift: TShiftState; X, Y: Integer); 248 248 procedure MapBoxMouseMove(Sender: TObject; Shift: TShiftState; 249 x, y: integer);249 X, Y: Integer); 250 250 procedure mShowClick(Sender: TObject); 251 251 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 252 Shift: TShiftState; x, y: integer);253 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);252 Shift: TShiftState; X, Y: Integer); 253 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 254 254 procedure FormMouseUp(Sender: TObject; Button: TMouseButton; 255 Shift: TShiftState; x, y: integer);255 Shift: TShiftState; X, Y: Integer); 256 256 procedure FormPaint(Sender: TObject); 257 257 procedure mRepClicked(Sender: TObject); … … 263 263 procedure mNamesClick(Sender: TObject); 264 264 procedure MapBtnClick(Sender: TObject); 265 procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);265 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 266 266 procedure CreateUnitClick(Sender: TObject); 267 267 procedure mSoundOffClick(Sender: TObject); … … 324 324 NoMap: TIsoMap; 325 325 NoMapPanel: TIsoMap; 326 function ChooseUnusedTribe: integer;326 function ChooseUnusedTribe: Integer; 327 327 function DoJob(j0: Integer): Integer; 328 328 procedure GetTribeList; 329 329 procedure InitModule; 330 330 procedure DoneModule; 331 procedure InitTurn(NewPlayer: integer);331 procedure InitTurn(NewPlayer: Integer); 332 332 procedure SaveMenuItemsState; 333 333 procedure ScrollBarUpdate(Sender: TObject); … … 341 341 procedure FocusNextUnit(Dir: Integer = 1); 342 342 procedure NextUnit(NearLoc: Integer; AutoTurn: Boolean); 343 procedure Scroll(dx, dy: integer);344 procedure SetMapPos(Loc: integer; MapPos: TPoint);345 procedure Centre(Loc: integer);346 procedure SetTroopLoc(Loc: integer);347 procedure ProcessRect(x0, y0, nx, ny, Options: integer);348 procedure PaintLoc(Loc: integer; Radius: integer = 0);349 procedure PaintLoc_BeforeMove(FromLoc: integer);350 procedure PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle = pltsNormal);351 procedure PaintBufferToScreen(xMap, yMap, width, height: integer);343 procedure Scroll(dx, dy: Integer); 344 procedure SetMapPos(Loc: Integer; MapPos: TPoint); 345 procedure Centre(Loc: Integer); 346 procedure SetTroopLoc(Loc: Integer); 347 procedure ProcessRect(x0, y0, nx, ny, Options: Integer); 348 procedure PaintLoc(Loc: Integer; Radius: Integer = 0); 349 procedure PaintLoc_BeforeMove(FromLoc: Integer); 350 procedure PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle = pltsNormal); 351 procedure PaintBufferToScreen(xMap, yMap, width, height: Integer); 352 352 procedure PaintDestination; 353 procedure SetUnFocus(uix: integer);354 function MoveUnit(dx, dy: integer; Options: integer = 0): integer;355 procedure MoveToLoc(Loc: integer; CheckSuicide: boolean);356 procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: integer;357 Restore: boolean = true);358 procedure FocusOnLoc(Loc: integer; Options: integer = 0);359 function EndTurn(WasSkipped: boolean = false): boolean;353 procedure SetUnFocus(uix: Integer); 354 function MoveUnit(dx, dy: Integer; Options: Integer = 0): Integer; 355 procedure MoveToLoc(Loc: Integer; CheckSuicide: Boolean); 356 procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: Integer; 357 Restore: Boolean = True); 358 procedure FocusOnLoc(Loc: Integer; Options: Integer = 0); 359 function EndTurn(WasSkipped: Boolean = False): Boolean; 360 360 procedure EndNego; 361 function IsPanelPixel( x, y: integer): boolean;361 function IsPanelPixel(X, Y: Integer): Boolean; 362 362 procedure InitPopup(Popup: TPopupMenu); 363 363 procedure SetMapOptions; … … 365 365 procedure CheckTerrainBtnVisible; 366 366 procedure RememberPeaceViolation; 367 procedure SetDebugMap( p: integer);368 procedure SetViewpoint( p: integer);369 function LocationOfScreenPixel( x, y: integer): Integer;367 procedure SetDebugMap(P: Integer); 368 procedure SetViewpoint(P: Integer); 369 function LocationOfScreenPixel(X, Y: Integer): Integer; 370 370 function GetCenterLoc: Integer; 371 371 procedure SetTileSizeCenter(TileSize: TTileSize); 372 372 procedure SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint); 373 procedure RectInvalidate(Left, Top, Rigth, Bottom: integer);373 procedure RectInvalidate(Left, Top, Rigth, Bottom: Integer); 374 374 procedure ShowEnemyShipChange(ShowShipChange: TShowShipChange); 375 procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);375 procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer); 376 376 procedure LoadSettings; 377 377 procedure SaveSettings; … … 381 381 procedure UpdateKeyShortcuts; 382 382 procedure SetFullScreen(Active: Boolean); 383 procedure PaintZoomedTile(dst: TBitmap; x, y, Loc: integer);383 procedure PaintZoomedTile(dst: TBitmap; X, Y, Loc: Integer); 384 384 public 385 385 UsedOffscreenWidth: Integer; … … 387 387 Offscreen: TBitmap; 388 388 OffscreenUser: TForm; 389 procedure Client(Command, NewPlayer: integer; var Data);390 procedure SetAIName( p: integer; Name: string);391 function ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;392 ShowEvent: integer = 0): boolean;393 procedure CityClosed(Activateuix: integer; StepFocus: boolean = false;394 SelectFocus: boolean = false);395 function DipCall(Command: integer): integer;396 function OfferCall(var Offer: TOffer): integer;397 procedure UpdateViews(UpdateCityScreen: boolean = false);398 function ContactRefused( p: integer; Item: String): boolean;389 procedure Client(Command, NewPlayer: Integer; var Data); 390 procedure SetAIName(P: Integer; Name: string); 391 function ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False; 392 ShowEvent: Integer = 0): Boolean; 393 procedure CityClosed(Activateuix: Integer; StepFocus: Boolean = False; 394 SelectFocus: Boolean = False); 395 function DipCall(Command: Integer): Integer; 396 function OfferCall(var Offer: TOffer): Integer; 397 procedure UpdateViews(UpdateCityScreen: Boolean = False); 398 function ContactRefused(P: Integer; Item: String): Boolean; 399 399 end; 400 400 … … 407 407 408 408 TTribeInfo = record 409 trix: integer;409 trix: Integer; 410 410 FileName: ShortString; 411 411 function GetCommandDataSize: Byte; … … 415 415 416 416 TCityNameInfo = record 417 ID: integer;417 ID: Integer; 418 418 NewName: ShortString; 419 419 function GetCommandDataSize: Byte; … … 423 423 424 424 TModelNameInfo = record 425 mix: integer;425 mix: Integer; 426 426 NewName: ShortString; 427 427 function GetCommandDataSize: Byte; … … 472 472 usToldNoReturn = $100; 473 473 usPersistent = usStay or usGoto or usEnhance or usRecover or 474 integer($FFFF0000);474 Integer($FFFF0000); 475 475 476 476 { model status flags } … … 486 486 adNexus = $803; 487 487 488 SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of integer = (10,488 SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of Integer = (10, 489 489 11, 40, 41, 21, 30, { 50,51, } 64, 74, { 71, } 73); 490 490 … … 499 499 500 500 nCityEventPriority = 16; 501 CityEventPriority: array [0 .. nCityEventPriority - 1] of integer =501 CityEventPriority: array [0 .. nCityEventPriority - 1] of Integer = 502 502 (chDisorder, chImprovementLost, chUnitLost, chAllImpsMade, chProduction, 503 503 chOldWonder, chNoSettlerProd, chPopDecrease, chProductionSabotaged, … … 574 574 DipMem: array [0 .. nPl - 1] of TDipMem; 575 575 576 function CityEventName( i: integer): string;577 function RoughCredibility(Credibility: integer): integer;578 579 function InitEnemyModel(emix: integer): boolean;576 function CityEventName(I: Integer): string; 577 function RoughCredibility(Credibility: Integer): Integer; 578 579 function InitEnemyModel(emix: Integer): Boolean; 580 580 procedure InitAllEnemyModels; 581 procedure InitMyModel(mix: integer; final: boolean);582 583 procedure ImpImage(ca: TCanvas; x, y, iix: integer; Government: integer = -1;584 IsControl: boolean = false);581 procedure InitMyModel(mix: Integer; final: Boolean); 582 583 procedure ImpImage(ca: TCanvas; X, Y, iix: Integer; Government: Integer = -1; 584 IsControl: Boolean = False); 585 585 procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode); 586 586 function AlignUp(Value, Alignment: Integer): Integer; … … 610 610 MoveTime = 300; // {time for moving a unit in ms} 611 611 WaitAfterShowMove = 32; 612 FastScrolling = false; // causes problems with overlapping windows612 FastScrolling = False; // causes problems with overlapping windows 613 613 614 614 nBrushTypes = 26; … … 648 648 CurrentMoveInfo: TCurrentMoveInfo; 649 649 650 function CityEventName( i: integer): string;651 begin 652 if i= 14 then // chAllImpsMade650 function CityEventName(I: Integer): string; 651 begin 652 if I = 14 then // chAllImpsMade 653 653 if not Phrases2FallenBackToEnglish then 654 result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE')654 Result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE') 655 655 else 656 result := Phrases.Lookup('CITYEVENTS', 1)656 Result := Phrases.Lookup('CITYEVENTS', 1) 657 657 else 658 result := Phrases.Lookup('CITYEVENTS', i);658 Result := Phrases.Lookup('CITYEVENTS', I); 659 659 end; 660 660 … … 666 666 TBuffer = array [0 .. 99999, 0 .. 2] of Integer; 667 667 var 668 Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;668 Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, X, Y, C, ch: Integer; 669 669 xdivider, ydivider: Integer; 670 670 Resampled: ^TBuffer; … … 682 682 PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig), 683 683 ScaleToNative(Cut + iy * ySizeBig)); 684 for y:= 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin685 ydivider := (ScaleFromNative( y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) *686 (ySizeBig - 2 * Cut) - ScaleFromNative( y) * ySizeSmall;684 for Y := 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin 685 ydivider := (ScaleFromNative(Y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) * 686 (ySizeBig - 2 * Cut) - ScaleFromNative(Y) * ySizeSmall; 687 687 if ydivider > ySizeSmall then 688 688 ydivider := ySizeSmall; 689 for x:= 0 to ScaleToNative(xSizeBig) - 1 do begin690 ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative( x) *691 xSizeSmall div xSizeBig + ScaleFromNative( y) *689 for X := 0 to ScaleToNative(xSizeBig) - 1 do begin 690 ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(X) * 691 xSizeSmall div xSizeBig + ScaleFromNative(Y) * 692 692 ySizeSmall div (ySizeBig - 2 * Cut) * nx; 693 xdivider := (ScaleFromNative( x) * xSizeSmall div xSizeBig + 1) *694 xSizeBig - ScaleFromNative( x) * xSizeSmall;693 xdivider := (ScaleFromNative(X) * xSizeSmall div xSizeBig + 1) * 694 xSizeBig - ScaleFromNative(X) * xSizeSmall; 695 695 if xdivider > xSizeSmall then 696 696 xdivider := xSizeSmall; 697 697 for ch := 0 to 2 do begin 698 c:= PixelPtr.Pixel^.Planes[ch];699 Inc(Resampled[ir, ch], c* xdivider * ydivider);698 C := PixelPtr.Pixel^.Planes[ch]; 699 Inc(Resampled[ir, ch], C * xdivider * ydivider); 700 700 if xdivider < xSizeSmall then 701 Inc(Resampled[ir + 1, ch], c* (xSizeSmall - xdivider) *701 Inc(Resampled[ir + 1, ch], C * (xSizeSmall - xdivider) * 702 702 ydivider); 703 703 if ydivider < ySizeSmall then 704 704 Inc(Resampled[ir + nx, ch], 705 c* xdivider * (ySizeSmall - ydivider));705 C * xdivider * (ySizeSmall - ydivider)); 706 706 if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then 707 Inc(Resampled[ir + nx + 1, ch], c* (xSizeSmall - xdivider) *707 Inc(Resampled[ir + nx + 1, ch], C * (xSizeSmall - xdivider) * 708 708 (ySizeSmall - ydivider)); 709 709 end; … … 719 719 SmallImp.BeginUpdate; 720 720 PixelPtr := PixelPointer(SmallImp); 721 for y:= 0 to ScaleToNative(ny) - 1 do begin722 for x:= 0 to ScaleToNative(nx) - 1 do begin721 for Y := 0 to ScaleToNative(ny) - 1 do begin 722 for X := 0 to ScaleToNative(nx) - 1 do begin 723 723 for ch := 0 to 2 do begin 724 724 Sum := 0; 725 725 Cnt := 0; 726 726 for dy := -1 to 1 do 727 if ((dy >= 0) or (ScaleFromNative( y) mod ySizeSmall > 0)) and728 ((dy <= 0) or (ScaleFromNative( y) mod ySizeSmall < ySizeSmall - 1)) then727 if ((dy >= 0) or (ScaleFromNative(Y) mod ySizeSmall > 0)) and 728 ((dy <= 0) or (ScaleFromNative(Y) mod ySizeSmall < ySizeSmall - 1)) then 729 729 for dx := -1 to 1 do 730 if ((dx >= 0) or (ScaleFromNative( x) mod xSizeSmall > 0)) and731 ((dx <= 0) or (ScaleFromNative( x) mod xSizeSmall < xSizeSmall - 1)) then730 if ((dx >= 0) or (ScaleFromNative(X) mod xSizeSmall > 0)) and 731 ((dx <= 0) or (ScaleFromNative(X) mod xSizeSmall < xSizeSmall - 1)) then 732 732 begin 733 Inc(Sum, Resampled[ScaleFromNative( x) + dx + nx * (ScaleFromNative(y) + dy), ch]);733 Inc(Sum, Resampled[ScaleFromNative(X) + dx + nx * (ScaleFromNative(Y) + dy), ch]); 734 734 Inc(Cnt); 735 735 end; 736 Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative( x) + nx * ScaleFromNative(y), ch] - Sum *736 Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(X) + nx * ScaleFromNative(Y), ch] - Sum * 737 737 Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * Cut)); 738 738 if Sum < 0 then Sum := 0; … … 748 748 end; 749 749 750 procedure ImpImage(ca: TCanvas; x, y, iix: integer; Government: integer;751 IsControl: boolean);750 procedure ImpImage(ca: TCanvas; X, Y, iix: Integer; Government: Integer; 751 IsControl: Boolean); 752 752 begin 753 753 if Government < 0 then … … 755 755 if (iix = imPalace) and (Government <> gAnarchy) then 756 756 iix := Government - 8; 757 FrameImage(ca, BigImp, x, y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7)757 FrameImage(ca, BigImp, X, Y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7) 758 758 mod 7 * xSizeBig, (iix + SystemIconLines * 7) div 7 * ySizeBig, IsControl); 759 759 end; … … 778 778 { *** tribe management procedures *** } 779 779 780 function RoughCredibility(Credibility: integer): integer;780 function RoughCredibility(Credibility: Integer): Integer; 781 781 begin 782 782 case Credibility of 783 783 0 .. 69: 784 result := 0;784 Result := 0; 785 785 70 .. 89: 786 result := 1;786 Result := 1; 787 787 90 .. 99: 788 result := 2;788 Result := 2; 789 789 100: 790 result := 3;791 end; 792 end; 793 794 procedure ChooseModelPicture( p, mix, code, Hash, Turn: integer;795 ForceNew, final: boolean);790 Result := 3; 791 end; 792 end; 793 794 procedure ChooseModelPicture(P, mix, Code, Hash, Turn: Integer; 795 ForceNew, final: Boolean); 796 796 var 797 i: integer;797 I: Integer; 798 798 Picture: TModelPictureInfo; 799 IsNew: boolean;800 begin 801 Picture.trix := p;799 IsNew: Boolean; 800 begin 801 Picture.trix := P; 802 802 Picture.mix := mix; 803 if code = 74 then803 if Code = 74 then 804 804 begin // use correct pictures for slaves 805 if Tribe[ p].mixSlaves < 0 then806 if not TribeOriginal[ p] then807 Tribe[ p].mixSlaves := mix805 if Tribe[P].mixSlaves < 0 then 806 if not TribeOriginal[P] then 807 Tribe[P].mixSlaves := mix 808 808 else 809 809 begin 810 i := mix + pshl 16;811 Server(cSetSlaveIndex, 0, 0, i);810 I := mix + P shl 16; 811 Server(cSetSlaveIndex, 0, 0, I); 812 812 end; 813 813 if ToldSlavery = 1 then … … 817 817 Picture.Hash := 0; 818 818 Picture.GrName := 'StdUnits.png'; 819 IsNew := true;819 IsNew := True; 820 820 end 821 821 else 822 822 begin 823 823 Picture.Hash := Hash; 824 IsNew := Tribe[ p].ChooseModelPicture(Picture, code, Turn, ForceNew);824 IsNew := Tribe[P].ChooseModelPicture(Picture, Code, Turn, ForceNew); 825 825 end; 826 826 if final then 827 if not TribeOriginal[ p] then828 Tribe[ p].SetModelPicture(Picture, IsNew)827 if not TribeOriginal[P] then 828 Tribe[P].SetModelPicture(Picture, IsNew) 829 829 else if IsNew then 830 830 Server(CommandWithData(cSetNewModelPicture, Picture.GetCommandDataSize), … … 834 834 0, 0, Picture) 835 835 else 836 with Tribe[ p].ModelPicture[mix] do836 with Tribe[P].ModelPicture[mix] do 837 837 begin 838 838 HGr := LoadGraphicSet(Picture.GrName); … … 841 841 end; 842 842 843 function InitEnemyModel(emix: integer): boolean;843 function InitEnemyModel(emix: Integer): Boolean; 844 844 begin 845 845 if GameMode = cMovie then 846 846 begin 847 result := false;848 exit;847 Result := False; 848 Exit; 849 849 end; 850 850 with MyRO.EnemyModel[emix] do 851 851 ChooseModelPicture(Owner, mix, ModelCode(MyRO.EnemyModel[emix]), 852 ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, false, true);853 result := true;852 ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, False, True); 853 Result := True; 854 854 end; 855 855 856 856 procedure InitAllEnemyModels; 857 857 var 858 emix: integer;858 emix: Integer; 859 859 begin 860 860 for emix := 0 to MyRO.nEnemyModel - 1 do … … 864 864 end; 865 865 866 procedure InitMyModel(mix: integer; final: boolean);866 procedure InitMyModel(mix: Integer; final: Boolean); 867 867 var 868 868 mi: TModelInfo; 869 869 begin 870 870 if (GameMode = cMovie) and (MyModel[mix].Kind < $08) then 871 exit;871 Exit; 872 872 // don't exit for special units because cSetModelPicture comes after TellNewModels 873 MakeModelInfo( me, mix, MyModel[mix], mi);874 ChooseModelPicture( me, mix, ModelCode(mi), ModelHash(mi), MyRO.Turn,875 false, final);876 end; 877 878 function AttackSound( code: integer): string;879 begin 880 result := 'ATTACK_' + char(48 + code div 100 mod 10) +881 char(48 + code div 10 mod 10) + char(48 + code mod 10);882 end; 883 884 procedure CheckToldNoReturn(uix: integer);873 MakeModelInfo(Me, mix, MyModel[mix], mi); 874 ChooseModelPicture(Me, mix, ModelCode(mi), ModelHash(mi), MyRO.Turn, 875 False, final); 876 end; 877 878 function AttackSound(Code: Integer): string; 879 begin 880 Result := 'ATTACK_' + char(48 + Code div 100 mod 10) + 881 char(48 + Code div 10 mod 10) + char(48 + Code mod 10); 882 end; 883 884 procedure CheckToldNoReturn(uix: Integer); 885 885 // check whether aircraft survived low-fuel warning 886 886 begin 887 assert(not supervising);887 Assert(not Supervising); 888 888 with MyUn[uix] do 889 889 if (Status and usToldNoReturn <> 0) and … … 893 893 end; 894 894 895 function CreateTribe( p: integer; FileName: string; Original: boolean): boolean;895 function CreateTribe(P: Integer; FileName: string; Original: Boolean): Boolean; 896 896 begin 897 897 FileName := LocalizedFilePath('Tribes' + DirectorySeparator + FileName + … … 903 903 end; 904 904 905 TribeOriginal[ p] := Original;906 Tribe[ p] := TTribe.Create(FileName);907 with Tribe[ p] do905 TribeOriginal[P] := Original; 906 Tribe[P] := TTribe.Create(FileName); 907 with Tribe[P] do 908 908 begin 909 909 if (GameMode = cNewGame) or not Original then 910 910 begin 911 Term.ChooseModelPicture( p, 0, 010, 1, 0, true, true);912 Term.ChooseModelPicture( p, 1, 040, 1, 0, true, true);913 Term.ChooseModelPicture( p, 2, 041, 1, 0, true, true);914 Term.ChooseModelPicture( p, -1, 017, 1, 0, true, true);915 end; 916 DipMem[ p].pContact := -1;917 end; 918 result := true;911 Term.ChooseModelPicture(P, 0, 010, 1, 0, True, True); 912 Term.ChooseModelPicture(P, 1, 040, 1, 0, True, True); 913 Term.ChooseModelPicture(P, 2, 041, 1, 0, True, True); 914 Term.ChooseModelPicture(P, -1, 017, 1, 0, True, True); 915 end; 916 DipMem[P].pContact := -1; 917 end; 918 Result := True; 919 919 end; 920 920 921 921 procedure TellNewContacts; 922 922 var 923 p1: integer;924 begin 925 if not supervising then923 p1: Integer; 924 begin 925 if not Supervising then 926 926 for p1 := 0 to nPl - 1 do 927 if (p1 <> me) and (1 shl p1 and MyData.ToldContact = 0) and927 if (p1 <> Me) and (1 shl p1 and MyData.ToldContact = 0) and 928 928 (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] > trNoContact) then 929 929 begin … … 935 935 procedure TellNewModels; 936 936 var 937 mix: integer;937 mix: Integer; 938 938 ModelNameInfo: TModelNameInfo; 939 939 begin 940 if supervising then941 exit;942 with Tribe[ me] do940 if Supervising then 941 Exit; 942 with Tribe[Me] do 943 943 while MyData.ToldModels < MyRO.nModel do 944 944 begin { new Unit class available } … … 951 951 end; 952 952 if not Assigned(ModelPicture[MyData.ToldModels].HGr) then 953 InitMyModel(MyData.ToldModels, true);953 InitMyModel(MyData.ToldModels, True); 954 954 { only run if no researched model } 955 955 with MessgExDlg do … … 983 983 (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt); 984 984 Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize), 985 me, 0, ModelNameInfo);985 Me, 0, ModelNameInfo); 986 986 end; 987 987 end; … … 992 992 MyModel[mix].Status := MyModel[mix].Status or msObsolete; 993 993 end; 994 inc(MyData.ToldModels);994 Inc(MyData.ToldModels); 995 995 end; 996 996 end; … … 1017 1017 end; 1018 1018 1019 procedure TMainScreen.PaintZoomedTile(dst: TBitmap; x, y, Loc: integer);1020 1021 procedure TSprite(xDst, yDst, xSrc, ySrc: integer);1019 procedure TMainScreen.PaintZoomedTile(dst: TBitmap; X, Y, Loc: Integer); 1020 1021 procedure TSprite(xDst, yDst, xSrc, ySrc: Integer); 1022 1022 begin 1023 1023 with NoMapPanel do 1024 Sprite(dst, HGrTerrain, x + xDst, y+ yDst, xxt * 2, yyt * 3,1024 Sprite(dst, HGrTerrain, X + xDst, Y + yDst, xxt * 2, yyt * 3, 1025 1025 1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1)); 1026 1026 end; 1027 1027 1028 procedure TSprite4(xSrc, ySrc: integer);1028 procedure TSprite4(xSrc, ySrc: Integer); 1029 1029 begin 1030 1030 with NoMapPanel do begin 1031 Sprite(dst, HGrTerrain, x + xxt, y+ yyt + 2, xxt * 2, yyt * 2 - 2,1031 Sprite(dst, HGrTerrain, X + xxt, Y + yyt + 2, xxt * 2, yyt * 2 - 2, 1032 1032 1 + xSrc * (xxt * 2 + 1), 3 + yyt + ySrc * (yyt * 3 + 1)); 1033 Sprite(dst, HGrTerrain, x + 4, y+ 2 * yyt, xxt * 2 - 4, yyt * 2,1033 Sprite(dst, HGrTerrain, X + 4, Y + 2 * yyt, xxt * 2 - 4, yyt * 2, 1034 1034 5 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1)); 1035 Sprite(dst, HGrTerrain, x + xxt * 2, y+ 2 * yyt, xxt * 2 - 4, yyt * 2,1035 Sprite(dst, HGrTerrain, X + xxt * 2, Y + 2 * yyt, xxt * 2 - 4, yyt * 2, 1036 1036 1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1)); 1037 Sprite(dst, HGrTerrain, x + xxt, y+ yyt * 3, xxt * 2, yyt * 2 - 2,1037 Sprite(dst, HGrTerrain, X + xxt, Y + yyt * 3, xxt * 2, yyt * 2 - 2, 1038 1038 1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1)); 1039 1039 end; … … 1041 1041 1042 1042 var 1043 cix, ySrc, Tile: integer;1043 cix, ySrc, Tile: Integer; 1044 1044 begin 1045 1045 with NoMapPanel do begin … … 1055 1055 cix := MyRO.nCity - 1; 1056 1056 while (cix >= 0) and (MyCity[cix].Loc <> Loc) do 1057 dec(cix);1058 assert(cix >= 0);1057 Dec(cix); 1058 Assert(cix >= 0); 1059 1059 if MyCity[cix].Built[imSupermarket] > 0 then 1060 1060 Tile := Tile or tiFarm … … 1147 1147 end; 1148 1148 1149 function ChooseResearch: boolean;1149 function ChooseResearch: Boolean; 1150 1150 var 1151 ChosenResearch: integer;1151 ChosenResearch: Integer; 1152 1152 begin 1153 1153 if (MyData.FarTech <> adNone) and (MyRO.Tech[MyData.FarTech] >= tsApplicable) … … 1158 1158 repeat 1159 1159 ModalSelectDlg.ShowNewContent(wmModal, kAdvance); 1160 if ModalSelectDlg. result < 0 then1161 begin 1162 result := false;1163 exit;1164 end; 1165 ChosenResearch := ModalSelectDlg. result;1160 if ModalSelectDlg.Result < 0 then 1161 begin 1162 Result := False; 1163 Exit; 1164 end; 1165 ChosenResearch := ModalSelectDlg.Result; 1166 1166 if ChosenResearch = adMilitary then 1167 1167 begin 1168 1168 DraftDlg.ShowNewContent(wmModal); 1169 1169 if DraftDlg.ModalResult <> mrOK then 1170 Tribe[ me].ModelPicture[MyRO.nModel].HGr := nil;1170 Tribe[Me].ModelPicture[MyRO.nModel].HGr := nil; 1171 1171 end; 1172 1172 until (ChosenResearch <> adMilitary) or (DraftDlg.ModalResult = mrOK); 1173 1173 1174 1174 if ChosenResearch = adMilitary then 1175 InitMyModel(MyRO.nModel, true)1175 InitMyModel(MyRO.nModel, True) 1176 1176 else if ChosenResearch = adFar then 1177 1177 begin 1178 1178 ModalSelectDlg.ShowNewContent(wmModal, kFarAdvance); 1179 if ModalSelectDlg. result >= 0 then1180 if (ModalSelectDlg. result = adNone) or1181 (Server(sSetResearch - sExecute, me, ModalSelectDlg.result, nil^) <1179 if ModalSelectDlg.Result >= 0 then 1180 if (ModalSelectDlg.Result = adNone) or 1181 (Server(sSetResearch - sExecute, Me, ModalSelectDlg.Result, nil^) < 1182 1182 rExecuted) then 1183 MyData.FarTech := ModalSelectDlg. result1183 MyData.FarTech := ModalSelectDlg.Result 1184 1184 else 1185 1185 begin 1186 ChosenResearch := ModalSelectDlg. result;1186 ChosenResearch := ModalSelectDlg.Result; 1187 1187 // can be researched immediately 1188 1188 MyData.FarTech := adNone; … … 1193 1193 MyData.FarTech := adNexus 1194 1194 else 1195 Server(sSetResearch, me, ChosenResearch, nil^);1195 Server(sSetResearch, Me, ChosenResearch, nil^); 1196 1196 ListDlg.TechChange; 1197 result := true;1197 Result := True; 1198 1198 end; 1199 1199 … … 1223 1223 (* ** client function handling ** *) 1224 1224 1225 function TMainScreen.DipCall(Command: integer): integer;1225 function TMainScreen.DipCall(Command: Integer): Integer; 1226 1226 var 1227 i: integer;1228 IsTreatyDeal: boolean;1229 begin 1230 result := Server(Command, me, 0, nil^);1231 if result >= rExecuted then1227 I: Integer; 1228 IsTreatyDeal: Boolean; 1229 begin 1230 Result := Server(Command, Me, 0, nil^); 1231 if Result >= rExecuted then 1232 1232 begin 1233 1233 if Command and $FF0F = scContact then 1234 1234 begin 1235 DipMem[ me].pContact := Command shr 4 and $F;1235 DipMem[Me].pContact := Command shr 4 and $F; 1236 1236 NegoDlg.Initiate; 1237 DipMem[ me].DeliveredPrices := [];1238 DipMem[ me].ReceivedPrices := [];1239 end; 1240 1241 DipMem[ me].SentCommand := Command;1242 DipMem[ me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];1237 DipMem[Me].DeliveredPrices := []; 1238 DipMem[Me].ReceivedPrices := []; 1239 end; 1240 1241 DipMem[Me].SentCommand := Command; 1242 DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact]; 1243 1243 if Command = scDipCancelTreaty then 1244 1244 Play('CANCELTREATY') 1245 1245 else if Command = scDipAccept then 1246 1246 begin // remember delivered and received prices 1247 for i:= 0 to ReceivedOffer.nDeliver - 1 do1248 include(DipMem[me].ReceivedPrices, ReceivedOffer.Price[i] shr 24);1249 for i:= 0 to ReceivedOffer.nCost - 1 do1250 include(DipMem[me].DeliveredPrices,1251 ReceivedOffer.Price[ReceivedOffer.nDeliver + i] shr 24);1252 IsTreatyDeal := false;1253 for i:= 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do1254 if ReceivedOffer.Price[ i] and opMask = opTreaty then1255 IsTreatyDeal := true;1247 for I := 0 to ReceivedOffer.nDeliver - 1 do 1248 Include(DipMem[Me].ReceivedPrices, ReceivedOffer.Price[I] shr 24); 1249 for I := 0 to ReceivedOffer.nCost - 1 do 1250 Include(DipMem[Me].DeliveredPrices, 1251 ReceivedOffer.Price[ReceivedOffer.nDeliver + I] shr 24); 1252 IsTreatyDeal := False; 1253 for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do 1254 if ReceivedOffer.Price[I] and opMask = opTreaty then 1255 IsTreatyDeal := True; 1256 1256 if IsTreatyDeal then 1257 1257 Play('NEWTREATY') … … 1260 1260 end; 1261 1261 CityDlg.CloseAction := None; 1262 if G.RO[DipMem[ me].pContact] <> nil then1262 if G.RO[DipMem[Me].pContact] <> nil then 1263 1263 begin // close windows for next player 1264 1264 ApplyToVisibleForms(faClose); … … 1274 1274 end; 1275 1275 1276 function TMainScreen.OfferCall(var Offer: TOffer): integer;1277 begin 1278 result := Server(scDipOffer, me, 0, Offer);1279 if result >= rExecuted then1280 begin 1281 DipMem[ me].SentCommand := scDipOffer;1282 DipMem[ me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];1283 DipMem[ me].SentOffer := Offer;1276 function TMainScreen.OfferCall(var Offer: TOffer): Integer; 1277 begin 1278 Result := Server(scDipOffer, Me, 0, Offer); 1279 if Result >= rExecuted then 1280 begin 1281 DipMem[Me].SentCommand := scDipOffer; 1282 DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact]; 1283 DipMem[Me].SentOffer := Offer; 1284 1284 CityDlg.CloseAction := None; 1285 if G.RO[DipMem[ me].pContact] <> nil then1285 if G.RO[DipMem[Me].pContact] <> nil then 1286 1286 begin // close windows for next player 1287 1287 ApplyToVisibleForms(faClose); … … 1297 1297 end; 1298 1298 1299 procedure TMainScreen.SetUnFocus(uix: integer);1299 procedure TMainScreen.SetUnFocus(uix: Integer); 1300 1300 var 1301 Loc0: integer;1302 begin 1303 assert(not((uix >= 0) and supervising));1301 Loc0: Integer; 1302 begin 1303 Assert(not((uix >= 0) and Supervising)); 1304 1304 if uix <> UnFocus then 1305 1305 begin 1306 DestinationMarkON := false;1306 DestinationMarkON := False; 1307 1307 PaintDestination; 1308 1308 if uix >= 0 then 1309 1309 UnStartLoc := MyUn[uix].Loc; 1310 BlinkON := false;1310 BlinkON := False; 1311 1311 BlinkTime := -1; 1312 1312 if UnFocus >= 0 then … … 1328 1328 procedure TMainScreen.CheckTerrainBtnVisible; 1329 1329 var 1330 Tile: integer;1330 Tile: Integer; 1331 1331 mox: ^TModel; 1332 1332 begin … … 1340 1340 end 1341 1341 else 1342 TerrainBtn.Visible := false;1342 TerrainBtn.Visible := False; 1343 1343 end; 1344 1344 … … 1348 1348 begin 1349 1349 MovieSpeed1Btn.Down := MovieSpeed = 1; 1350 MovieSpeed1Btn.Visible := true;1350 MovieSpeed1Btn.Visible := True; 1351 1351 MovieSpeed2Btn.Down := MovieSpeed = 2; 1352 MovieSpeed2Btn.Visible := true;1352 MovieSpeed2Btn.Visible := True; 1353 1353 MovieSpeed3Btn.Down := MovieSpeed = 3; 1354 MovieSpeed3Btn.Visible := true;1354 MovieSpeed3Btn.Visible := True; 1355 1355 MovieSpeed4Btn.Down := MovieSpeed = 4; 1356 MovieSpeed4Btn.Visible := true;1356 MovieSpeed4Btn.Visible := True; 1357 1357 end 1358 1358 else 1359 1359 begin 1360 MovieSpeed1Btn.Visible := false;1361 MovieSpeed2Btn.Visible := false;1362 MovieSpeed3Btn.Visible := false;1363 MovieSpeed4Btn.Visible := false;1360 MovieSpeed1Btn.Visible := False; 1361 MovieSpeed2Btn.Visible := False; 1362 MovieSpeed3Btn.Visible := False; 1363 MovieSpeed4Btn.Visible := False; 1364 1364 end; 1365 1365 end; … … 1375 1375 end; 1376 1376 1377 procedure TMainScreen.UpdateViews(UpdateCityScreen: boolean);1377 procedure TMainScreen.UpdateViews(UpdateCityScreen: Boolean); 1378 1378 begin 1379 1379 SumCities(TaxSum, ScienceSum); … … 1385 1385 end; 1386 1386 1387 procedure TMainScreen.SetAIName( p: integer; Name: string);1387 procedure TMainScreen.SetAIName(P: Integer; Name: string); 1388 1388 begin 1389 1389 if Name = '' then 1390 1390 begin 1391 if AILogo[ p] <> nil then1392 begin 1393 FreeAndNil(AILogo[ p]);1391 if AILogo[P] <> nil then 1392 begin 1393 FreeAndNil(AILogo[P]); 1394 1394 end; 1395 1395 end 1396 1396 else 1397 1397 begin 1398 if AILogo[ p] = nil then1399 AILogo[ p] := TBitmap.Create;1400 if not LoadGraphicFile(AILogo[ p], HomeDir + Name + '.png', [gfNoError]) then1401 begin 1402 FreeAndNil(AILogo[ p]);1403 end; 1404 end; 1405 end; 1406 1407 function TMainScreen.ContactRefused( p: integer; Item: String): boolean;1398 if AILogo[P] = nil then 1399 AILogo[P] := TBitmap.Create; 1400 if not LoadGraphicFile(AILogo[P], HomeDir + Name + '.png', [gfNoError]) then 1401 begin 1402 FreeAndNil(AILogo[P]); 1403 end; 1404 end; 1405 end; 1406 1407 function TMainScreen.ContactRefused(P: Integer; Item: String): Boolean; 1408 1408 // return whether treaty was cancelled 1409 1409 var 1410 s: string;1411 begin 1412 assert(MyRO.Treaty[p] >= trPeace);1413 s := Tribe[p].TPhrase(Item);1414 if MyRO.Turn < MyRO.LastCancelTreaty[ p] + CancelTreatyTurns then1415 begin 1416 SimpleMessage( s);1417 result := false;1410 S: string; 1411 begin 1412 Assert(MyRO.Treaty[P] >= trPeace); 1413 S := Tribe[P].TPhrase(Item); 1414 if MyRO.Turn < MyRO.LastCancelTreaty[P] + CancelTreatyTurns then 1415 begin 1416 SimpleMessage(S); 1417 Result := False; 1418 1418 end 1419 1419 else 1420 1420 begin 1421 case MyRO.Treaty[ p] of1421 case MyRO.Treaty[P] of 1422 1422 trPeace: 1423 s := s+ ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE');1423 S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE'); 1424 1424 trFriendlyContact: 1425 s := s+ ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY');1425 S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY'); 1426 1426 trAlliance: 1427 s := s+ ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE');1428 end; 1429 result := SimpleQuery(mkYesNo, s, 'NEGO_REJECTED') = mrOK;1430 if result then1427 S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE'); 1428 end; 1429 Result := SimpleQuery(mkYesNo, S, 'NEGO_REJECTED') = mrOK; 1430 if Result then 1431 1431 begin 1432 1432 Play('CANCELTREATY'); 1433 Server(sCancelTreaty, me, 0, nil^);1434 if MyRO.Treaty[ p] = trNone then1433 Server(sCancelTreaty, Me, 0, nil^); 1434 if MyRO.Treaty[P] = trNone then 1435 1435 CityOptimizer_BeginOfTurn; 1436 1436 // peace treaty was cancelled -- use formerly forbidden tiles 1437 MapValid := false;1437 MapValid := False; 1438 1438 PaintAllMaps; 1439 1439 end; … … 1443 1443 procedure TMainScreen.RememberPeaceViolation; 1444 1444 var 1445 uix, p1: integer;1445 uix, p1: Integer; 1446 1446 begin 1447 1447 MyData.PeaceEvaHappened := 0; … … 1451 1451 begin 1452 1452 p1 := MyRO.Territory[Loc]; 1453 if (p1 <> me) and (p1 >= 0) and1453 if (p1 <> Me) and (p1 >= 0) and 1454 1454 (MyRO.Turn = MyRO.EvaStart[p1] + (PeaceEvaTurns - 1)) then 1455 1455 MyData.PeaceEvaHappened := MyData.PeaceEvaHappened or (1 shl p1); … … 1489 1489 1490 1490 var 1491 i, cix, mix: integer;1492 need: boolean;1491 I, cix, mix: Integer; 1492 need: Boolean; 1493 1493 mi: TModelInfo; 1494 1494 begin 1495 1495 if (sbStart in Check) and not (sbStart in SoundPreloadDone) then begin 1496 for i:= 0 to nStartBlock - 1 do1497 PreparePlay(StartBlock[ i]);1496 for I := 0 to nStartBlock - 1 do 1497 PreparePlay(StartBlock[I]); 1498 1498 SoundPreloadDone := SoundPreloadDone + [sbStart]; 1499 1499 end; 1500 1500 if (sbWonder in Check) and not (sbWonder in SoundPreloadDone) then begin 1501 need := false;1502 for i:= 0 to nWonder - 1 do1503 if MyRO.Wonder[ i].CityID <> WonderNotBuiltYet then1504 need := true;1501 need := False; 1502 for I := 0 to nWonder - 1 do 1503 if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then 1504 need := True; 1505 1505 if need then begin 1506 for i:= 0 to nWonderBlock - 1 do1507 PreparePlay(WonderBlock[ i]);1506 for I := 0 to nWonderBlock - 1 do 1507 PreparePlay(WonderBlock[I]); 1508 1508 SoundPreloadDone := SoundPreloadDone + [sbWonder]; 1509 1509 end; … … 1511 1511 if ((sbScience in Check) and not (sbScience in SoundPreloadDone)) and 1512 1512 (MyRO.Tech[adScience] >= tsApplicable) then begin 1513 for i:= 0 to nScienceBlock - 1 do1514 PreparePlay(ScienceBlock[ i]);1513 for I := 0 to nScienceBlock - 1 do 1514 PreparePlay(ScienceBlock[I]); 1515 1515 SoundPreloadDone := SoundPreloadDone + [sbScience]; 1516 1516 end; 1517 1517 if ((sbContact in Check) and not (sbContact in SoundPreloadDone)) and 1518 1518 (MyRO.nEnemyModel + MyRO.nEnemyCity > 0) then begin 1519 for i:= 0 to nContactBlock - 1 do1520 PreparePlay(ContactBlock[ i]);1519 for I := 0 to nContactBlock - 1 do 1520 PreparePlay(ContactBlock[I]); 1521 1521 SoundPreloadDone := SoundPreloadDone + [sbContact]; 1522 1522 end; … … 1529 1529 with MyCity[cix] do 1530 1530 if (Loc >= 0) and (Flags and CityRepMask <> 0) then 1531 for i:= 0 to 12 do1532 if 1 shl iand Flags and CityRepMask <> 0 then1533 PreparePlay(CityEventSoundItem[ i]);1531 for I := 0 to 12 do 1532 if 1 shl I and Flags and CityRepMask <> 0 then 1533 PreparePlay(CityEventSoundItem[I]); 1534 1534 for mix := 0 to MyRO.nModel - 1 do 1535 1535 with MyModel[mix] do 1536 1536 if Attack > 0 then 1537 1537 begin 1538 MakeModelInfo( me, mix, MyModel[mix], mi);1538 MakeModelInfo(Me, mix, MyModel[mix], mi); 1539 1539 PreparePlay(AttackSound(ModelCode(mi))); 1540 1540 end; … … 1547 1547 Color: TColor; 1548 1548 Name: string; 1549 ok: boolean;1549 ok: Boolean; 1550 1550 begin 1551 1551 UnusedTribeFiles.Clear; … … 1567 1567 end; 1568 1568 1569 function TMainScreen.ChooseUnusedTribe: integer;1569 function TMainScreen.ChooseUnusedTribe: Integer; 1570 1570 var 1571 i: Integer;1572 j: Integer;1571 I: Integer; 1572 J: Integer; 1573 1573 ColorDistance: Integer; 1574 1574 BestColorDistance: Integer; … … 1576 1576 CountBest: Integer; 1577 1577 begin 1578 assert(UnusedTribeFiles.Count > 0);1579 result := -1;1578 Assert(UnusedTribeFiles.Count > 0); 1579 Result := -1; 1580 1580 BestColorDistance := -1; 1581 for j:= 0 to UnusedTribeFiles.Count - 1 do1581 for J := 0 to UnusedTribeFiles.Count - 1 do 1582 1582 begin 1583 1583 ColorDistance := 250; // consider differences more than this infinite 1584 for i:= 0 to nPl - 1 do1585 if Tribe[ i] <> nil then1586 begin 1587 TestColorDistance := abs( integer(UnusedTribeFiles.Objects[j])1588 shr 16 and $FF - Tribe[ i].Color shr 16 and $FF) +1589 abs( integer(UnusedTribeFiles.Objects[j]) shr 8 and1590 $FF - Tribe[ i].Color shr 8 and $FF) * 3 +1591 abs( integer(UnusedTribeFiles.Objects[j]) and1592 $FF - Tribe[ i].Color and $FF) * 2;1584 for I := 0 to nPl - 1 do 1585 if Tribe[I] <> nil then 1586 begin 1587 TestColorDistance := abs(Integer(UnusedTribeFiles.Objects[J]) 1588 shr 16 and $FF - Tribe[I].Color shr 16 and $FF) + 1589 abs(Integer(UnusedTribeFiles.Objects[J]) shr 8 and 1590 $FF - Tribe[I].Color shr 8 and $FF) * 3 + 1591 abs(Integer(UnusedTribeFiles.Objects[J]) and 1592 $FF - Tribe[I].Color and $FF) * 2; 1593 1593 if TestColorDistance < ColorDistance then 1594 1594 ColorDistance := TestColorDistance; … … 1601 1601 if ColorDistance = BestColorDistance then 1602 1602 begin 1603 inc(CountBest);1603 Inc(CountBest); 1604 1604 if DelphiRandom(CountBest) = 0 then 1605 result := j;1605 Result := J; 1606 1606 end; 1607 1607 end; … … 1610 1610 procedure TMainScreen.ShowEnemyShipChange(ShowShipChange: TShowShipChange); 1611 1611 var 1612 i, TestCost, MostCost: integer;1613 Ship1Plus, Ship2Plus: boolean;1612 I, TestCost, MostCost: Integer; 1613 Ship1Plus, Ship2Plus: Boolean; 1614 1614 begin 1615 1615 with ShowShipChange, MessgExDlg do … … 1634 1634 begin 1635 1635 OpenSound := 'SHIP_TRADED'; 1636 Ship1Plus := false;1637 Ship2Plus := false;1638 for i:= 0 to nShipPart - 1 do1636 Ship1Plus := False; 1637 Ship2Plus := False; 1638 for I := 0 to nShipPart - 1 do 1639 1639 begin 1640 if Ship1Change[ i] > 0 then1641 Ship1Plus := true;1642 if Ship2Change[ i] > 0 then1643 Ship2Plus := true;1640 if Ship1Change[I] > 0 then 1641 Ship1Plus := True; 1642 if Ship2Change[I] > 0 then 1643 Ship2Plus := True; 1644 1644 end; 1645 1645 if Ship1Plus and Ship2Plus then … … 1668 1668 begin 1669 1669 MostCost := 0; 1670 for i:= 0 to nShipPart - 1 do1671 begin 1672 TestCost := abs(Ship1Change[ i]) * Imp[imShipComp + i].Cost;1670 for I := 0 to nShipPart - 1 do 1671 begin 1672 TestCost := abs(Ship1Change[I]) * Imp[imShipComp + I].Cost; 1673 1673 if TestCost > MostCost then 1674 1674 begin 1675 1675 MostCost := TestCost; 1676 IconIndex := imShipComp + i;1676 IconIndex := imShipComp + I; 1677 1677 end; 1678 1678 end; … … 1686 1686 procedure TMainScreen.InitModule; 1687 1687 var 1688 i, j, Domain: integer;1688 I, J, Domain: Integer; 1689 1689 begin 1690 1690 { search icons for advances: } 1691 for i:= 0 to nAdv - 1 do1692 if iin FutureTech then1693 AdvIcon[ i] := 96 + i- futResearchTechnology1691 for I := 0 to nAdv - 1 do 1692 if I in FutureTech then 1693 AdvIcon[I] := 96 + I - futResearchTechnology 1694 1694 else 1695 1695 begin 1696 AdvIcon[ i] := -1;1696 AdvIcon[I] := -1; 1697 1697 for Domain := 0 to nDomains - 1 do 1698 for j:= 0 to nUpgrade - 1 do1699 if upgrade[Domain, j].Preq = ithen1700 if AdvIcon[ i] >= 0 then1701 AdvIcon[ i] := 851698 for J := 0 to nUpgrade - 1 do 1699 if upgrade[Domain, J].Preq = I then 1700 if AdvIcon[I] >= 0 then 1701 AdvIcon[I] := 85 1702 1702 else 1703 AdvIcon[ i] := 86 + Domain;1704 for j:= 0 to nFeature - 1 do1705 if Feature[ j].Preq = ithen1703 AdvIcon[I] := 86 + Domain; 1704 for J := 0 to nFeature - 1 do 1705 if Feature[J].Preq = I then 1706 1706 for Domain := 0 to nDomains - 1 do 1707 if 1 shl Domain and Feature[ j].Domains <> 0 then1708 if (AdvIcon[ i] >= 0) and (AdvIcon[i] <> 86 + Domain) then1709 AdvIcon[ i] := 851707 if 1 shl Domain and Feature[J].Domains <> 0 then 1708 if (AdvIcon[I] >= 0) and (AdvIcon[I] <> 86 + Domain) then 1709 AdvIcon[I] := 85 1710 1710 else 1711 AdvIcon[ i] := 86 + Domain;1712 for j:= nWonder to nImp - 1 do1713 if Imp[ j].Preq = ithen1714 AdvIcon[ i] := j;1715 for j:= nWonder to nImp - 1 do1716 if (Imp[ j].Preq = i) and (Imp[j].Kind <> ikCommon) then1717 AdvIcon[ i] := j;1718 for j:= 0 to nJob - 1 do1719 if i = JobPreq[j] then1720 AdvIcon[ i] := 84;1721 for j:= 0 to nWonder - 1 do1722 if Imp[ j].Preq = ithen1723 AdvIcon[ i] := j;1724 if AdvIcon[ i] < 0 then1725 if AdvValue[ i] < 1000 then1726 AdvIcon[ i] := -71711 AdvIcon[I] := 86 + Domain; 1712 for J := nWonder to nImp - 1 do 1713 if Imp[J].Preq = I then 1714 AdvIcon[I] := J; 1715 for J := nWonder to nImp - 1 do 1716 if (Imp[J].Preq = I) and (Imp[J].Kind <> ikCommon) then 1717 AdvIcon[I] := J; 1718 for J := 0 to nJob - 1 do 1719 if I = JobPreq[J] then 1720 AdvIcon[I] := 84; 1721 for J := 0 to nWonder - 1 do 1722 if Imp[J].Preq = I then 1723 AdvIcon[I] := J; 1724 if AdvIcon[I] < 0 then 1725 if AdvValue[I] < 1000 then 1726 AdvIcon[I] := -7 1727 1727 else 1728 AdvIcon[ i] := 24 + AdvValue[i] div 1000;1729 for j:= 2 to nGov - 1 do1730 if GovPreq[ j] = ithen1731 AdvIcon[ i] := j- 8;1728 AdvIcon[I] := 24 + AdvValue[I] div 1000; 1729 for J := 2 to nGov - 1 do 1730 if GovPreq[J] = I then 1731 AdvIcon[I] := J - 8; 1732 1732 end; 1733 1733 AdvIcon[adConscription] := 86 + dGround; 1734 1734 1735 1735 UnusedTribeFiles := tstringlist.Create; 1736 UnusedTribeFiles.Sorted := true;1736 UnusedTribeFiles.Sorted := True; 1737 1737 TribeNames := tstringlist.Create; 1738 1738 1739 1739 IsoEngine.Init(InitEnemyModel); 1740 1740 // non-default tile size is missing a file, switch to default 1741 MainMap.SetOutput( offscreen);1741 MainMap.SetOutput(Offscreen); 1742 1742 1743 1743 HGrStdUnits := LoadGraphicSet('StdUnits.png'); … … 1746 1746 InitSmallImp; 1747 1747 SoundPreloadDone := []; 1748 StartRunning := false;1749 StayOnTop_Ensured := false;1748 StartRunning := False; 1749 StayOnTop_Ensured := False; 1750 1750 1751 1751 sb := TPVScrollbar.Create(Self); … … 1761 1761 end; 1762 1762 1763 procedure TMainScreen.InitTurn(NewPlayer: integer);1763 procedure TMainScreen.InitTurn(NewPlayer: Integer); 1764 1764 const 1765 1765 nAdvBookIcon = 16; 1766 1766 AdvBookIcon: array [0 .. nAdvBookIcon - 1] of record Adv, 1767 Icon: integer end = ((Adv: adPolyTheism; Icon: woZeus),1767 Icon: Integer end = ((Adv: adPolyTheism; Icon: woZeus), 1768 1768 (Adv: adBronzeWorking; Icon: woColossus), (Adv: adMapMaking; 1769 1769 Icon: woLighthouse), (Adv: adPoetry; Icon: imTheater), (Adv: adMonotheism; … … 1777 1777 sbAll = [sbStart, sbWonder, sbScience, sbContact, sbTurn]; 1778 1778 var 1779 p1, i, ad, uix, cix, MoveOptions, MoveResult, Loc1,1779 p1, I, ad, uix, cix, MoveOptions, MoveResult, Loc1, 1780 1780 NewAgeCenterTo, Winners, NewGovAvailable, dx, 1781 dy: integer;1781 dy: Integer; 1782 1782 MoveAdviceData: TMoveAdviceData; 1783 1783 Picture: TModelPictureInfo; 1784 s, Item, Item2: string;1784 S, Item, Item2: string; 1785 1785 UpdatePanel, OwnWonder, ok, Stop, ShowCityList, WondersOnly, 1786 AllowCityScreen: boolean;1787 begin 1788 if IsMultiPlayerGame and (NewPlayer <> me) then1789 begin 1790 UnitInfoBtn.Visible := false;1791 UnitBtn.Visible := false;1792 TerrainBtn.Visible := false;1793 EOT.Visible := false;1794 end; 1795 if IsMultiPlayerGame and (NewPlayer <> me) and1786 AllowCityScreen: Boolean; 1787 begin 1788 if IsMultiPlayerGame and (NewPlayer <> Me) then 1789 begin 1790 UnitInfoBtn.Visible := False; 1791 UnitBtn.Visible := False; 1792 TerrainBtn.Visible := False; 1793 EOT.Visible := False; 1794 end; 1795 if IsMultiPlayerGame and (NewPlayer <> Me) and 1796 1796 (G.RO[0].Happened and phShipComplete = 0) then 1797 1797 begin // inter player screen 1798 for i:= 0 to ControlCount - 1 do1799 if Controls[ i] is TButtonC then1800 Controls[ i].Visible := false;1801 me := -1;1798 for I := 0 to ControlCount - 1 do 1799 if Controls[I] is TButtonC then 1800 Controls[I].Visible := False; 1801 Me := -1; 1802 1802 MainTexture.Age := -1; 1803 1803 with Panel.Canvas do … … 1815 1815 Invalidate; 1816 1816 1817 s:= TurnToString(G.RO[0].Turn);1818 if supervising then1819 SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [ s]))1817 S := TurnToString(G.RO[0].Turn); 1818 if Supervising then 1819 SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [S])) 1820 1820 else 1821 SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [ s]));1822 end; 1823 for i:= 0 to ControlCount - 1 do1824 if Controls[ i] is TButtonC then1825 Controls[ i].Visible := true;1821 SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [S])); 1822 end; 1823 for I := 0 to ControlCount - 1 do 1824 if Controls[I] is TButtonC then 1825 Controls[I].Visible := True; 1826 1826 1827 1827 ItsMeAgain(NewPlayer); 1828 1828 MyData := G.RO[NewPlayer].Data; 1829 if not supervising then1829 if not Supervising then 1830 1830 SoundPreload(sbAll); 1831 if ( me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then1831 if (Me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then 1832 1832 Invalidate; // colorize empty space 1833 1833 1834 if not supervising then1834 if not Supervising then 1835 1835 begin 1836 1836 … … 1842 1842 else } 1843 1843 begin 1844 Age := GetAge( me);1844 Age := GetAge(Me); 1845 1845 if MainTexture.Age <> Age then begin 1846 1846 MainTexture.Age := Age; … … 1869 1869 NatStatDlg.CheckAge; 1870 1870 UnitStatDlg.CheckAge; 1871 HelpDlg.Difficulty := G.Difficulty[ me];1871 HelpDlg.Difficulty := G.Difficulty[Me]; 1872 1872 1873 1873 UnFocus := -1; 1874 1874 MarkCityLoc := -1; 1875 BlinkON := false;1875 BlinkON := False; 1876 1876 BlinkTime := -1; 1877 Tracking := false;1878 TurnComplete := false;1877 Tracking := False; 1878 TurnComplete := False; 1879 1879 1880 1880 if (ToldSlavery < 0) or … … 1896 1896 Hash := 0; 1897 1897 GrName := 'StdUnits.png'; 1898 Tribe[p1].SetModelPicture(Picture, true);1898 Tribe[p1].SetModelPicture(Picture, True); 1899 1899 end; 1900 1900 end; 1901 1901 1902 if not supervising and (ClientMode = cTurn) then1902 if not Supervising and (ClientMode = cTurn) then 1903 1903 begin 1904 1904 for cix := 0 to MyRO.nCity - 1 do … … 1915 1915 if ClientMode = cMovieTurn then 1916 1916 begin 1917 UnitInfoBtn.Visible := false;1918 UnitBtn.Visible := false;1919 TerrainBtn.Visible := false;1917 UnitInfoBtn.Visible := False; 1918 UnitBtn.Visible := False; 1919 TerrainBtn.Visible := False; 1920 1920 EOT.Hint := Phrases.Lookup('BTN_STOP'); 1921 EOT.Visible := true;1921 EOT.Visible := True; 1922 1922 end 1923 1923 else if ClientMode < scContact then … … 1926 1926 UnitBtn.Visible := UnFocus >= 0; 1927 1927 CheckTerrainBtnVisible; 1928 TurnComplete := supervising;1928 TurnComplete := Supervising; 1929 1929 EOT.Hint := Phrases.Lookup('BTN_ENDTURN'); 1930 EOT.Visible := Server(sTurn - sExecute, me, 0, nil^) >= rExecuted;1930 EOT.Visible := Server(sTurn - sExecute, Me, 0, nil^) >= rExecuted; 1931 1931 end 1932 1932 else 1933 1933 begin 1934 UnitInfoBtn.Visible := false;1935 UnitBtn.Visible := false;1936 TerrainBtn.Visible := false;1934 UnitInfoBtn.Visible := False; 1935 UnitBtn.Visible := False; 1936 TerrainBtn.Visible := False; 1937 1937 EOT.Hint := Phrases.Lookup('BTN_NEGO'); 1938 EOT.Visible := true;1938 EOT.Visible := True; 1939 1939 end; 1940 1940 SetTroopLoc(-1); 1941 MapValid := false;1941 MapValid := False; 1942 1942 NewAgeCenterTo := 0; 1943 if ((MyRO.Turn = 0) and not supervising or IsMultiPlayerGame or1943 if ((MyRO.Turn = 0) and not Supervising or IsMultiPlayerGame or 1944 1944 (ClientMode = cResume)) and (MyRO.nCity > 0) then 1945 1945 begin … … 1986 1986 begin 1987 1987 OpenSound := 'MSG_GAMEOVER'; 1988 MessgText := Tribe[ me].TPhrase('GAMEOVER');1988 MessgText := Tribe[Me].TPhrase('GAMEOVER'); 1989 1989 IconKind := mikBigIcon; 1990 1990 IconIndex := 8; … … 1997 1997 begin 1998 1998 Winners := Winners or 1 shl p1; 1999 for i:= 0 to nShipPart - 1 do2000 if MyRO.Ship[p1].Parts[ i] < ShipNeed[i] then1999 for I := 0 to nShipPart - 1 do 2000 if MyRO.Ship[p1].Parts[I] < ShipNeed[I] then 2001 2001 Winners := Winners and not(1 shl p1); 2002 2002 end; 2003 assert(Winners <> 0);2004 if Winners and (1 shl me) <> 0 then2003 Assert(Winners <> 0); 2004 if Winners and (1 shl Me) <> 0 then 2005 2005 begin 2006 s:= '';2006 S := ''; 2007 2007 for p1 := 0 to nPl - 1 do 2008 if (p1 <> me) and (1 shl p1 and Winners <> 0) then2009 if s= '' then2010 s:= Tribe[p1].TPhrase('SHORTNAME')2008 if (p1 <> Me) and (1 shl p1 and Winners <> 0) then 2009 if S = '' then 2010 S := Tribe[p1].TPhrase('SHORTNAME') 2011 2011 else 2012 s:= Format(Phrases.Lookup('SHAREDWIN_CONCAT'),2013 [ s, Tribe[p1].TPhrase('SHORTNAME')]);2012 S := Format(Phrases.Lookup('SHAREDWIN_CONCAT'), 2013 [S, Tribe[p1].TPhrase('SHORTNAME')]); 2014 2014 2015 2015 OpenSound := 'MSG_YOUWIN'; 2016 MessgText := Tribe[ me].TPhrase('MYSPACESHIP');2017 if s<> '' then2016 MessgText := Tribe[Me].TPhrase('MYSPACESHIP'); 2017 if S <> '' then 2018 2018 MessgText := MessgText + '\' + 2019 Format(Phrases.Lookup('SHAREDWIN'), [ s]);2019 Format(Phrases.Lookup('SHAREDWIN'), [S]); 2020 2020 IconKind := mikBigIcon; 2021 2021 IconIndex := 9; … … 2023 2023 else 2024 2024 begin 2025 assert(me = 0);2025 Assert(Me = 0); 2026 2026 OpenSound := 'MSG_GAMEOVER'; 2027 2027 MessgText := ''; … … 2035 2035 else { if MyRO.Happened and fTimeUp<>0 then } 2036 2036 begin 2037 assert(me = 0);2037 Assert(Me = 0); 2038 2038 OpenSound := 'MSG_GAMEOVER'; 2039 if not supervising then2040 MessgText := Tribe[ me].TPhrase('TIMEUP')2039 if not Supervising then 2040 MessgText := Tribe[Me].TPhrase('TIMEUP') 2041 2041 else 2042 2042 MessgText := Phrases.Lookup('TIMEUPSUPER'); … … 2050 2050 p1 := 0; 2051 2051 while (p1 < nPl - 1) and (Winners and (1 shl p1) = 0) do 2052 inc(p1);2052 Inc(p1); 2053 2053 if MyRO.Happened and phShipComplete = 0 then 2054 2054 DiaDlg.ShowNewContent_Charts(wmModal); 2055 2055 end; 2056 TurnComplete := true;2057 exit;2058 end; 2059 if not supervising and (1 shl me and MyRO.Alive = 0) then2060 begin 2061 TurnComplete := true;2062 exit;2056 TurnComplete := True; 2057 Exit; 2058 end; 2059 if not Supervising and (1 shl Me and MyRO.Alive = 0) then 2060 begin 2061 TurnComplete := True; 2062 Exit; 2063 2063 end; 2064 2064 2065 2065 if (ClientMode = cContinue) and 2066 (DipMem[ me].SentCommand and $FF0F = scContact) then2066 (DipMem[Me].SentCommand and $FF0F = scContact) then 2067 2067 // contact was refused 2068 if MyRO.Treaty[DipMem[ me].pContact] >= trPeace then2069 ContactRefused(DipMem[ me].pContact, 'FRREJECTED')2068 if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then 2069 ContactRefused(DipMem[Me].pContact, 'FRREJECTED') 2070 2070 else 2071 SoundMessage(Tribe[DipMem[ me].pContact].TPhrase('FRREJECTED'),2071 SoundMessage(Tribe[DipMem[Me].pContact].TPhrase('FRREJECTED'), 2072 2072 'NEGO_REJECTED'); 2073 2073 2074 if not supervising and (Age > MyData.ToldAge) and2074 if not Supervising and (Age > MyData.ToldAge) and 2075 2075 ((Age > 0) or (ClientMode <> cMovieTurn)) then 2076 2076 with MessgExDlg do … … 2080 2080 if Phrases2FallenBackToEnglish then 2081 2081 begin 2082 s := Tribe[me].TPhrase('AGE0');2082 S := Tribe[Me].TPhrase('AGE0'); 2083 2083 MessgText := 2084 Format( s, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)]);2084 Format(S, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)]); 2085 2085 end 2086 2086 else 2087 2087 begin 2088 s := Tribe[me].TString(Phrases2.Lookup('AGE0'));2089 MessgText := Format( s, [TurnToString(MyRO.Turn)]);2088 S := Tribe[Me].TString(Phrases2.Lookup('AGE0')); 2089 MessgText := Format(S, [TurnToString(MyRO.Turn)]); 2090 2090 end; 2091 2091 end 2092 2092 else 2093 2093 begin 2094 s := Tribe[me].TPhrase('AGE' + char(48 + Age));2095 MessgText := Format( s, [TurnToString(MyRO.Turn)]);2094 S := Tribe[Me].TPhrase('AGE' + char(48 + Age)); 2095 MessgText := Format(S, [TurnToString(MyRO.Turn)]); 2096 2096 end; 2097 2097 IconKind := mikAge; … … 2115 2115 begin 2116 2116 OpenSound := 'MSG_EXTINCT'; 2117 s:= Tribe[p1].TPhrase('EXTINCT');2118 MessgText := Format( s, [TurnToString(MyRO.Turn)]);2119 if MyRO.Alive = 1 shl me then2117 S := Tribe[p1].TPhrase('EXTINCT'); 2118 MessgText := Format(S, [TurnToString(MyRO.Turn)]); 2119 if MyRO.Alive = 1 shl Me then 2120 2120 MessgText := MessgText + Phrases.Lookup('EXTINCTALL'); 2121 2121 Kind := mkOk; … … 2124 2124 ShowModal; 2125 2125 end; 2126 if (ClientMode <> cMovieTurn) and not supervising then2126 if (ClientMode <> cMovieTurn) and not Supervising then 2127 2127 DiaDlg.ShowNewContent_Charts(wmModal); 2128 2128 end; 2129 2129 2130 2130 // tell changes of own credibility 2131 if not supervising then2131 if not Supervising then 2132 2132 begin 2133 2133 if RoughCredibility(MyRO.Credibility) <> … … 2136 2136 if RoughCredibility(MyRO.Credibility) > 2137 2137 RoughCredibility(MyData.ToldOwnCredibility) then 2138 s:= Phrases.Lookup('CREDUP')2138 S := Phrases.Lookup('CREDUP') 2139 2139 else 2140 s:= Phrases.Lookup('CREDDOWN');2141 TribeMessage( me, Format(s, [Phrases.Lookup('CREDIBILITY',2140 S := Phrases.Lookup('CREDDOWN'); 2141 TribeMessage(Me, Format(S, [Phrases.Lookup('CREDIBILITY', 2142 2142 RoughCredibility(MyRO.Credibility))]), ''); 2143 2143 end; … … 2145 2145 end; 2146 2146 2147 for i:= 0 to nWonder - 1 do2148 begin 2149 OwnWonder := false;2147 for I := 0 to nWonder - 1 do 2148 begin 2149 OwnWonder := False; 2150 2150 for cix := 0 to MyRO.nCity - 1 do 2151 if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[ i].CityID)2151 if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[I].CityID) 2152 2152 then 2153 OwnWonder := true;2154 if MyRO.Wonder[ i].CityID <> MyData.ToldWonders[i].CityID then2155 begin 2156 if MyRO.Wonder[ i].CityID = WonderDestroyed then2153 OwnWonder := True; 2154 if MyRO.Wonder[I].CityID <> MyData.ToldWonders[I].CityID then 2155 begin 2156 if MyRO.Wonder[I].CityID = WonderDestroyed then 2157 2157 with MessgExDlg do 2158 2158 begin { tell about destroyed wonders } 2159 2159 OpenSound := 'WONDER_DESTROYED'; 2160 2160 MessgText := Format(Phrases.Lookup('WONDERDEST'), 2161 [Phrases.Lookup('IMPROVEMENTS', i)]);2161 [Phrases.Lookup('IMPROVEMENTS', I)]); 2162 2162 Kind := mkOkHelp; 2163 2163 HelpKind := hkImp; 2164 HelpNo := i;2164 HelpNo := I; 2165 2165 IconKind := mikImp; 2166 IconIndex := i;2166 IconIndex := I; 2167 2167 ShowModal; 2168 2168 end 2169 2169 else 2170 2170 begin 2171 if i= woManhattan then2172 if MyRO.Wonder[ i].EffectiveOwner > me then2171 if I = woManhattan then 2172 if MyRO.Wonder[I].EffectiveOwner > Me then 2173 2173 MyData.ColdWarStart := MyRO.Turn - 1 2174 2174 else … … 2177 2177 with MessgExDlg do 2178 2178 begin { tell about newly built wonders } 2179 if i= woManhattan then2179 if I = woManhattan then 2180 2180 begin 2181 2181 OpenSound := 'MSG_COLDWAR'; 2182 s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('COLDWAR');2182 S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('COLDWAR'); 2183 2183 end 2184 else if MyRO.Wonder[ i].EffectiveOwner >= 0 then2184 else if MyRO.Wonder[I].EffectiveOwner >= 0 then 2185 2185 begin 2186 2186 OpenSound := 'WONDER_BUILT'; 2187 s := Tribe[MyRO.Wonder[i].EffectiveOwner]2187 S := Tribe[MyRO.Wonder[I].EffectiveOwner] 2188 2188 .TPhrase('WONDERBUILT'); 2189 2189 end … … 2191 2191 begin 2192 2192 OpenSound := 'MSG_DEFAULT'; 2193 s:= Phrases.Lookup('WONDERBUILTEXP');2193 S := Phrases.Lookup('WONDERBUILTEXP'); 2194 2194 // already expired when built 2195 2195 end; 2196 MessgText := Format( s, [Phrases.Lookup('IMPROVEMENTS', i),2197 CityName(MyRO.Wonder[ i].CityID)]);2196 MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I), 2197 CityName(MyRO.Wonder[I].CityID)]); 2198 2198 Kind := mkOkHelp; 2199 2199 HelpKind := hkImp; 2200 HelpNo := i;2200 HelpNo := I; 2201 2201 IconKind := mikImp; 2202 IconIndex := i;2202 IconIndex := I; 2203 2203 ShowModal; 2204 2204 end; 2205 2205 end; 2206 2206 end 2207 else if (MyRO.Wonder[ i].EffectiveOwner <> MyData.ToldWonders[i]2208 .EffectiveOwner) and (MyRO.Wonder[ i].CityID > WonderDestroyed) then2209 if MyRO.Wonder[ i].EffectiveOwner < 0 then2207 else if (MyRO.Wonder[I].EffectiveOwner <> MyData.ToldWonders[I] 2208 .EffectiveOwner) and (MyRO.Wonder[I].CityID > WonderDestroyed) then 2209 if MyRO.Wonder[I].EffectiveOwner < 0 then 2210 2210 begin 2211 if i<> woMIR then2211 if I <> woMIR then 2212 2212 with MessgExDlg do 2213 2213 begin { tell about expired wonders } 2214 2214 OpenSound := 'WONDER_EXPIRED'; 2215 2215 MessgText := Format(Phrases.Lookup('WONDEREXP'), 2216 [Phrases.Lookup('IMPROVEMENTS', i),2217 CityName(MyRO.Wonder[ i].CityID)]);2216 [Phrases.Lookup('IMPROVEMENTS', I), 2217 CityName(MyRO.Wonder[I].CityID)]); 2218 2218 Kind := mkOkHelp; 2219 2219 HelpKind := hkImp; 2220 HelpNo := i;2220 HelpNo := I; 2221 2221 IconKind := mikImp; 2222 IconIndex := i;2222 IconIndex := I; 2223 2223 ShowModal; 2224 2224 end; 2225 2225 end 2226 else if (MyData.ToldWonders[ i].EffectiveOwner >= 0) and not OwnWonder2226 else if (MyData.ToldWonders[I].EffectiveOwner >= 0) and not OwnWonder 2227 2227 then 2228 2228 with MessgExDlg do 2229 2229 begin { tell about capture of wonders } 2230 2230 OpenSound := 'WONDER_CAPTURED'; 2231 s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('WONDERCAPT');2232 MessgText := Format( s, [Phrases.Lookup('IMPROVEMENTS', i),2233 CityName(MyRO.Wonder[ i].CityID)]);2231 S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('WONDERCAPT'); 2232 MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I), 2233 CityName(MyRO.Wonder[I].CityID)]); 2234 2234 Kind := mkOkHelp; 2235 2235 HelpKind := hkImp; 2236 HelpNo := i;2236 HelpNo := I; 2237 2237 IconKind := mikImp; 2238 IconIndex := i;2238 IconIndex := I; 2239 2239 ShowModal; 2240 2240 end; … … 2250 2250 end; // ClientMode<>cResume 2251 2251 MyData.ToldAlive := MyRO.Alive; 2252 move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders));2252 Move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders)); 2253 2253 2254 2254 NewGovAvailable := -1; … … 2274 2274 IconKind := mikBook; 2275 2275 IconIndex := -1; 2276 for i:= 0 to nAdvBookIcon - 1 do2277 if AdvBookIcon[ i].Adv = ad then2278 IconIndex := AdvBookIcon[ i].Icon;2276 for I := 0 to nAdvBookIcon - 1 do 2277 if AdvBookIcon[I].Adv = ad then 2278 IconIndex := AdvBookIcon[I].Icon; 2279 2279 ShowModal; 2280 2280 MyData.ToldTech[ad] := MyRO.Tech[ad]; 2281 for i:= gMonarchy to nGov - 1 do2282 if GovPreq[ i] = ad then2283 NewGovAvailable := i;2281 for I := gMonarchy to nGov - 1 do 2282 if GovPreq[I] = ad then 2283 NewGovAvailable := I; 2284 2284 end; 2285 2285 end; 2286 2286 2287 ShowCityList := false;2287 ShowCityList := False; 2288 2288 if ClientMode = cTurn then 2289 2289 begin … … 2291 2291 ChooseResearch; 2292 2292 2293 UpdatePanel := false;2293 UpdatePanel := False; 2294 2294 if MyRO.Happened and phChangeGov <> 0 then 2295 2295 begin 2296 2296 ModalSelectDlg.ShowNewContent(wmModal, kGov); 2297 2297 Play('NEWGOV'); 2298 Server(sSetGovernment, me, ModalSelectDlg.result, nil^);2298 Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^); 2299 2299 CityOptimizer_BeginOfTurn; 2300 UpdatePanel := true;2300 UpdatePanel := True; 2301 2301 end; 2302 2302 end; // ClientMode=cTurn 2303 2303 2304 if not supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn))2304 if not Supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn)) 2305 2305 then 2306 2306 for cix := 0 to MyRO.nCity - 1 do … … 2312 2312 begin 2313 2313 // tell what happened in cities 2314 for WondersOnly := true downto false do2314 for WondersOnly := True downto False do 2315 2315 for cix := 0 to MyRO.nCity - 1 do 2316 2316 with MyCity[cix] do … … 2323 2323 begin { tell about newly built wonder } 2324 2324 OpenSound := 'WONDER_BUILT'; 2325 s := Tribe[me].TPhrase('WONDERBUILTOWN');2325 S := Tribe[Me].TPhrase('WONDERBUILTOWN'); 2326 2326 MessgText := 2327 Format( s, [Phrases.Lookup('IMPROVEMENTS',2327 Format(S, [Phrases.Lookup('IMPROVEMENTS', 2328 2328 Project0 and cpIndex), CityName(ID)]); 2329 2329 Kind := mkOkHelp; … … 2334 2334 ShowModal; 2335 2335 end; 2336 if not supervising and (ClientMode = cTurn) then2336 if not Supervising and (ClientMode = cTurn) then 2337 2337 begin 2338 AllowCityScreen := true;2338 AllowCityScreen := True; 2339 2339 if (Status and 7 <> 0) and 2340 2340 (Project and (cpImp + cpIndex) = cpImp + imTrGoods) then … … 2342 2342 begin 2343 2343 if AutoBuild(cix, MyData.ImpOrder[Status and 7 - 1]) then 2344 AllowCityScreen := false2344 AllowCityScreen := False 2345 2345 else if Flags and chProduction <> 0 then 2346 2346 Flags := (Flags and not chProduction) or chAllImpsMade … … 2370 2370 CityDlg.ShowNewContent(wmModal, MyCity[cix].Loc, 2371 2371 Flags and CityRepMask); 2372 UpdatePanel := true;2372 UpdatePanel := True; 2373 2373 end; 2374 2374 end … … 2376 2376 begin 2377 2377 if Flags and CityRepMask <> 0 then 2378 ShowCityList := true;2378 ShowCityList := True; 2379 2379 end; 2380 2380 end; … … 2396 2396 begin 2397 2397 Play('REVOLUTION'); 2398 Server(sRevolution, me, 0, nil^);2398 Server(sRevolution, Me, 0, nil^); 2399 2399 end; 2400 2400 end; … … 2430 2430 Application.ProcessMessages; 2431 2431 2432 if not supervising then2432 if not Supervising then 2433 2433 for uix := 0 to MyRO.nUn - 1 do 2434 2434 with MyUn[uix] do … … 2458 2458 begin // !!! Shinkansen 2459 2459 MoveResult := eOK; 2460 ok := true;2461 for i:= 0 to MoveAdviceData.nStep - 1 do2460 ok := True; 2461 for I := 0 to MoveAdviceData.nStep - 1 do 2462 2462 begin 2463 Loc1 := dLoc(Loc, MoveAdviceData.dx[ i],2464 MoveAdviceData.dy[ i]);2463 Loc1 := dLoc(Loc, MoveAdviceData.dx[I], 2464 MoveAdviceData.dy[I]); 2465 2465 if (MyMap[Loc1] and (fCity or fOwned) = fCity) 2466 2466 // don't capture cities during auto move … … 2468 2468 // don't attack during auto move 2469 2469 begin 2470 ok := false;2470 ok := False; 2471 2471 Break 2472 2472 end … … 2475 2475 if (Loc1 = MoveAdviceData.ToLoc) or 2476 2476 (MoveAdviceData.ToLoc = maNextCity) and 2477 (MyMap[dLoc(Loc, MoveAdviceData.dx[ i],2478 MoveAdviceData.dy[ i])] and fCity <> 0) then2477 (MyMap[dLoc(Loc, MoveAdviceData.dx[I], 2478 MoveAdviceData.dy[I])] and fCity <> 0) then 2479 2479 MoveOptions := muAutoNoWait 2480 2480 else 2481 2481 MoveOptions := 0; 2482 MoveResult := MoveUnit(MoveAdviceData.dx[ i],2483 MoveAdviceData.dy[ i], MoveOptions);2482 MoveResult := MoveUnit(MoveAdviceData.dx[I], 2483 MoveAdviceData.dy[I], MoveOptions); 2484 2484 if (MoveResult < rExecuted) or (MoveResult = eEnemySpotted) 2485 2485 then 2486 2486 begin 2487 ok := false;2487 ok := False; 2488 2488 Break 2489 2489 end; … … 2497 2497 begin 2498 2498 MoveResult := eOK; 2499 Stop := true;2499 Stop := True; 2500 2500 end; 2501 2501 … … 2520 2520 end; // ClientMode=cTurn 2521 2521 2522 HaveStrategyAdvice := false;2522 HaveStrategyAdvice := False; 2523 2523 // (GameMode<>cMovie) and not supervising 2524 2524 // and AdvisorDlg.HaveStrategyAdvice; 2525 GoOnPhase := true;2526 if supervising or (GameMode = cMovie) then2525 GoOnPhase := True; 2526 if Supervising or (GameMode = cMovie) then 2527 2527 begin 2528 2528 SetTroopLoc(-1); … … 2539 2539 SetUnFocus(-1) 2540 2540 else 2541 NextUnit(-1, false);2541 NextUnit(-1, False); 2542 2542 if UnFocus < 0 then 2543 2543 begin … … 2556 2556 end; 2557 2557 2558 procedure TMainScreen.Client(Command, NewPlayer: integer; var Data);2558 procedure TMainScreen.Client(Command, NewPlayer: Integer; var Data); 2559 2559 var 2560 i, j, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: integer;2560 I, J, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: Integer; 2561 2561 Color: TColor; 2562 Name, s: string;2562 Name, S: string; 2563 2563 TribeInfo: TTribeInfo; 2564 2564 mi: TModelInfo; 2565 SkipTurn, IsAlpine, IsTreatyDeal: boolean;2565 SkipTurn, IsAlpine, IsTreatyDeal: Boolean; 2566 2566 begin 2567 2567 case Command of 2568 2568 cTurn, cResume, cContinue, cMovieTurn, scContact, scDipStart .. scDipBreak: 2569 2569 begin 2570 supervising := G.Difficulty[NewPlayer] = 0;2570 Supervising := G.Difficulty[NewPlayer] = 0; 2571 2571 ArrangeMidPanel; 2572 2572 end … … 2574 2574 case Command of 2575 2575 cDebugMessage: 2576 LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(@Data));2576 LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(@Data)); 2577 2577 2578 2578 cShowNego: 2579 2579 with TShowNegoData(Data) do 2580 2580 begin 2581 s:= Format('P%d to P%d: ', [pSender, pTarget]);2581 S := Format('P%d to P%d: ', [pSender, pTarget]); 2582 2582 if (Action = scDipOffer) and (Offer.nDeliver + Offer.nCost > 0) then 2583 2583 begin 2584 s := s+ 'Offer ';2585 for i:= 0 to Offer.nDeliver + Offer.nCost - 1 do2584 S := S + 'Offer '; 2585 for I := 0 to Offer.nDeliver + Offer.nCost - 1 do 2586 2586 begin 2587 if i= Offer.nDeliver then2588 s := s+ ' for '2589 else if i> 0 then2590 s := s+ '+';2591 case Offer.Price[ i] and opMask of2587 if I = Offer.nDeliver then 2588 S := S + ' for ' 2589 else if I > 0 then 2590 S := S + '+'; 2591 case Offer.Price[I] and opMask of 2592 2592 opChoose: 2593 s := s+ 'Price of choice';2593 S := S + 'Price of choice'; 2594 2594 opCivilReport: 2595 s := s+ 'State report';2595 S := S + 'State report'; 2596 2596 opMilReport: 2597 s := s+ 'Military report';2597 S := S + 'Military report'; 2598 2598 opMap: 2599 s := s+ 'Map';2599 S := S + 'Map'; 2600 2600 opTreaty: 2601 s := s+ 'Treaty';2601 S := S + 'Treaty'; 2602 2602 opShipParts: 2603 s := s+ 'Ship part';2603 S := S + 'Ship part'; 2604 2604 opMoney: 2605 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o';2605 S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o'; 2606 2606 opTribute: 2607 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o tribute';2607 S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o tribute'; 2608 2608 opTech: 2609 s := s + Phrases.Lookup('ADVANCES', Offer.Price[i] and $FFFFFF);2609 S := S + Phrases.Lookup('ADVANCES', Offer.Price[I] and $FFFFFF); 2610 2610 opAllTech: 2611 s := s+ 'All advances';2611 S := S + 'All advances'; 2612 2612 opModel: 2613 s := s + Tribe[pSender].ModelName[Offer.Price[i] and $FFFFFF];2613 S := S + Tribe[pSender].ModelName[Offer.Price[I] and $FFFFFF]; 2614 2614 opAllModel: 2615 s := s+ 'All models';2615 S := S + 'All models'; 2616 2616 end; 2617 2617 end; 2618 LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));2618 LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S)); 2619 2619 end 2620 2620 else if Action = scDipAccept then 2621 2621 begin 2622 s := s+ '--- ACCEPTED! ---';2623 LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));2622 S := S + '--- ACCEPTED! ---'; 2623 LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S)); 2624 2624 end; 2625 2625 end; … … 2657 2657 AdvisorDlg.NewGame(Data); } 2658 2658 GenerateNames := mNames.Checked; 2659 GameOK := true;2659 GameOK := True; 2660 2660 G := TNewGameData(Data); 2661 me := -1;2661 Me := -1; 2662 2662 pLogo := -1; 2663 2663 ClientMode := -1; 2664 2664 SetMapOptions; 2665 2665 MainMap.pDebugMap := -1; 2666 idle := false;2666 Idle := False; 2667 2667 FillChar(Jump, SizeOf(Jump), 0); 2668 2668 if StartRunning then … … 2687 2687 ToldContact := 0; 2688 2688 ToldOwnCredibility := InitialCredibility; 2689 for i:= 0 to nPl - 1 do2690 if G.Difficulty[ i] > 0 then2691 inc(ToldAlive, 1 shl i);2689 for I := 0 to nPl - 1 do 2690 if G.Difficulty[I] > 0 then 2691 Inc(ToldAlive, 1 shl I); 2692 2692 PeaceEvaHappened := 0; 2693 for i:= 0 to nWonder - 1 do2694 with ToldWonders[ i] do2693 for I := 0 to nWonder - 1 do 2694 with ToldWonders[I] do 2695 2695 begin 2696 2696 CityID := -1; … … 2719 2719 Age := 0; 2720 2720 MovieSpeed := 1; 2721 LogDlg.mSlot.Visible := true;2721 LogDlg.mSlot.Visible := True; 2722 2722 LogDlg.Host := self; 2723 2723 HelpDlg.ClearHistory; … … 2725 2725 2726 2726 MiniMap.Size := Point(G.lx, G.ly); 2727 for i:= 0 to nPl - 1 do2727 for I := 0 to nPl - 1 do 2728 2728 begin 2729 Tribe[ i] := nil;2730 TribeOriginal[ i] := false;2729 Tribe[I] := nil; 2730 TribeOriginal[I] := False; 2731 2731 end; 2732 2732 ToldSlavery := -1; 2733 RepaintOnResize := false;2734 Closable := false;2735 FirstMovieTurn := true;2733 RepaintOnResize := False; 2734 Closable := False; 2735 FirstMovieTurn := True; 2736 2736 2737 2737 MenuArea.Visible := GameMode <> cMovie; … … 2744 2744 if NewPlayer = 0 then 2745 2745 begin 2746 i:= 0;2746 I := 0; 2747 2747 for p1 := 0 to nPl - 1 do 2748 2748 if (G.Difficulty[p1] > 0) and (Tribe[p1] = nil) then 2749 inc(i);2750 if i> UnusedTribeFiles.Count then2749 Inc(I); 2750 if I > UnusedTribeFiles.Count then 2751 2751 begin 2752 GameOK := false;2752 GameOK := False; 2753 2753 SimpleMessage(Phrases.Lookup('TOOFEWTRIBES')); 2754 2754 end … … 2761 2761 TribeInfo.trix := p1; 2762 2762 TribeNames.Clear; 2763 for j:= 0 to UnusedTribeFiles.Count - 1 do2763 for J := 0 to UnusedTribeFiles.Count - 1 do 2764 2764 begin 2765 GetTribeInfo(UnusedTribeFiles[ j], Name, Color);2765 GetTribeInfo(UnusedTribeFiles[J], Name, Color); 2766 2766 TribeNames.AddObject(Name, TObject(Color)); 2767 2767 end; 2768 assert(TribeNames.Count > 0);2768 Assert(TribeNames.Count > 0); 2769 2769 ModalSelectDlg.ShowNewContent(wmModal, kTribe); 2770 2770 Application.ProcessMessages; 2771 TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg. result];2772 UnusedTribeFiles.Delete(ModalSelectDlg. result);2771 TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg.Result]; 2772 UnusedTribeFiles.Delete(ModalSelectDlg.Result); 2773 2773 2774 2774 if GameMode = cLoadGame then 2775 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)2775 CreateTribe(TribeInfo.trix, TribeInfo.FileName, False) 2776 2776 else 2777 2777 Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize), … … 2783 2783 then 2784 2784 begin // autoselect enemy tribes 2785 j:= ChooseUnusedTribe;2786 TribeInfo.FileName := UnusedTribeFiles[ j];2787 UnusedTribeFiles.Delete( j);2785 J := ChooseUnusedTribe; 2786 TribeInfo.FileName := UnusedTribeFiles[J]; 2787 UnusedTribeFiles.Delete(J); 2788 2788 TribeInfo.trix := p1; 2789 2789 if GameMode = cLoadGame then 2790 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)2790 CreateTribe(TribeInfo.trix, TribeInfo.FileName, False) 2791 2791 else 2792 2792 Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize), … … 2808 2808 LogDlg.Close; 2809 2809 LogDlg.List.Clear; 2810 StartRunning := not idle and (Jump[0] > 0); // AI called Reload2811 me := -1;2812 idle := false;2810 StartRunning := not Idle and (Jump[0] > 0); // AI called Reload 2811 Me := -1; 2812 Idle := False; 2813 2813 ClientMode := -1; 2814 UnitInfoBtn.Visible := false;2815 UnitBtn.Visible := false;2816 TerrainBtn.Visible := false;2817 MovieSpeed1Btn.Visible := false;2818 MovieSpeed2Btn.Visible := false;2819 MovieSpeed3Btn.Visible := false;2820 MovieSpeed4Btn.Visible := false;2821 EOT.Visible := false;2822 for i:= 0 to ControlCount - 1 do2823 if Controls[ i] is TButtonC then2824 Controls[ i].Visible := false;2814 UnitInfoBtn.Visible := False; 2815 UnitBtn.Visible := False; 2816 TerrainBtn.Visible := False; 2817 MovieSpeed1Btn.Visible := False; 2818 MovieSpeed2Btn.Visible := False; 2819 MovieSpeed3Btn.Visible := False; 2820 MovieSpeed4Btn.Visible := False; 2821 EOT.Visible := False; 2822 for I := 0 to ControlCount - 1 do 2823 if Controls[I] is TButtonC then 2824 Controls[I].Visible := False; 2825 2825 sb.Init(0, 1); 2826 2826 for p1 := 0 to nPl - 1 do … … 2828 2828 FreeAndNil(Tribe[p1]); 2829 2829 Tribes.Done; 2830 RepaintOnResize := false;2831 Closable := true;2830 RepaintOnResize := False; 2831 Closable := True; 2832 2832 Close; 2833 2833 { if (GameMode=cNewGame) or (GameMode=cLoadGame) then … … 2852 2852 Show; 2853 2853 Update; 2854 RepaintOnResize := true;2854 RepaintOnResize := True; 2855 2855 xw := 0; 2856 2856 yw := ywcenter; 2857 2857 if not StayOnTop_Ensured then 2858 2858 begin 2859 StayOnTop_Ensured := true;2859 StayOnTop_Ensured := True; 2860 2860 CityDlg.StayOnTop_Workaround; 2861 2861 CityTypeDlg.StayOnTop_Workaround; … … 2876 2876 cShowTurnChange: 2877 2877 begin 2878 if integer(Data) >= 0 then2878 if Integer(Data) >= 0 then 2879 2879 begin 2880 pLogo := integer(Data);2880 pLogo := Integer(Data); 2881 2881 if G.RO[pLogo] = nil then 2882 2882 begin … … 2905 2905 ItsMeAgain(p1); 2906 2906 for mix := 0 to MyRO.nModel - 1 do 2907 if not Assigned(Tribe[ me].ModelPicture[mix].HGr) then2908 InitMyModel(mix, true);2907 if not Assigned(Tribe[Me].ModelPicture[mix].HGr) then 2908 InitMyModel(mix, True); 2909 2909 end; 2910 me := -1;2910 Me := -1; 2911 2911 end; 2912 2912 … … 2917 2917 Jump[pTurn] := 0 2918 2918 else 2919 dec(Jump[pTurn]);2919 Dec(Jump[pTurn]); 2920 2920 SkipTurn := Jump[pTurn] > 0; 2921 2921 if SkipTurn then … … 2926 2926 MiniMapPaint; 2927 2927 InitAllEnemyModels; // necessary for correct replay 2928 if not EndTurn( true) then2929 SkipTurn := false;2928 if not EndTurn(True) then 2929 SkipTurn := False; 2930 2930 end; 2931 2931 if not SkipTurn then … … 2934 2934 NegoDlg.Visible then 2935 2935 NegoDlg.Close; 2936 skipped := false; // always show my moves during my turn2937 idle := true;2936 skipped := False; // always show my moves during my turn 2937 Idle := True; 2938 2938 InitTurn(NewPlayer); 2939 DipMem[ me].pContact := -1;2940 (* if ( me=0) and (MyRO.Alive and (1 shl me)=0)} then2939 DipMem[Me].pContact := -1; 2940 (* if (Me=0) and (MyRO.Alive and (1 shl Me)=0)} then 2941 2941 begin 2942 2942 if SimpleQuery(Phrases.Lookup('RESIGN'))=mrIgnore then 2943 Server(sResign, me,0,nil^)2944 else Server(sBreak, me,0,nil^)2943 Server(sResign,Me,0,nil^) 2944 else Server(sBreak,Me,0,nil^) 2945 2945 end 2946 2946 else Play('TURNSTART'); *) … … 2953 2953 pTurn := NewPlayer; 2954 2954 pLogo := -1; 2955 skipped := false; // always show my moves during my turn2956 idle := true;2955 skipped := False; // always show my moves during my turn 2956 Idle := True; 2957 2957 if FirstMovieTurn then 2958 2958 begin 2959 2959 CheckMovieSpeedBtnState; 2960 FirstMovieTurn := false;2960 FirstMovieTurn := False; 2961 2961 end; 2962 2962 InitTurn(NewPlayer); … … 2975 2975 pTurn := -1; 2976 2976 pLogo := -1; 2977 MapValid := false;2977 MapValid := False; 2978 2978 ClientMode := -1; 2979 idle := false;2980 skipped := false;2979 Idle := False; 2980 skipped := False; 2981 2981 end; 2982 2982 … … 2988 2988 ItsMeAgain(0); 2989 2989 MyData := nil; 2990 UnitInfoBtn.Visible := false;2991 UnitBtn.Visible := false;2992 TerrainBtn.Visible := false;2993 MovieSpeed1Btn.Visible := false;2994 MovieSpeed2Btn.Visible := false;2995 MovieSpeed3Btn.Visible := false;2996 MovieSpeed4Btn.Visible := false;2997 EOT.Visible := false;2990 UnitInfoBtn.Visible := False; 2991 UnitBtn.Visible := False; 2992 TerrainBtn.Visible := False; 2993 MovieSpeed1Btn.Visible := False; 2994 MovieSpeed2Btn.Visible := False; 2995 MovieSpeed3Btn.Visible := False; 2996 MovieSpeed4Btn.Visible := False; 2997 EOT.Visible := False; 2998 2998 HelpDlg.Difficulty := 0; 2999 2999 BrushType := fGrass; 3000 3000 BrushLoc := -1; 3001 Edited := false;3001 Edited := False; 3002 3002 UnFocus := -1; 3003 3003 MarkCityLoc := -1; 3004 Tracking := false;3005 TurnComplete := false;3006 MapValid := false;3004 Tracking := False; 3005 TurnComplete := False; 3006 MapValid := False; 3007 3007 FormResize(nil); // calculate geometrics and paint all 3008 3008 SetTroopLoc(-1); 3009 idle := true;3009 Idle := True; 3010 3010 end; 3011 3011 … … 3017 3017 scContact: 3018 3018 begin 3019 DipMem[NewPlayer].pContact := integer(Data);3019 DipMem[NewPlayer].pContact := Integer(Data); 3020 3020 if Jump[NewPlayer] > 0 then 3021 3021 DipCall(scReject) … … 3024 3024 ClientMode := Command; 3025 3025 InitTurn(NewPlayer); 3026 MyData.ToldContact := MyData.ToldContact or (1 shl integer(Data));3026 MyData.ToldContact := MyData.ToldContact or (1 shl Integer(Data)); 3027 3027 // don't tell about new nation when already contacted by them 3028 3028 with MessgExDlg do 3029 3029 begin 3030 OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[ integer(Data)3030 OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[Integer(Data) 3031 3031 ].Attitude); 3032 MessgText := Tribe[ integer(Data)].TPhrase('FRCONTACT');3032 MessgText := Tribe[Integer(Data)].TPhrase('FRCONTACT'); 3033 3033 Kind := mkYesNo; 3034 3034 IconKind := mikTribe; 3035 IconIndex := integer(Data);3035 IconIndex := Integer(Data); 3036 3036 ShowModal; 3037 3037 if ModalResult = mrOK then 3038 3038 begin 3039 3039 NegoDlg.Respond; 3040 DipMem[ me].DeliveredPrices := [];3041 DipMem[ me].ReceivedPrices := [];3040 DipMem[Me].DeliveredPrices := []; 3041 DipMem[Me].ReceivedPrices := []; 3042 3042 DipCall(scDipStart); 3043 3043 end … … 3067 3067 else if Command = scDipAccept then 3068 3068 begin // remember delivered and received prices 3069 for i := 0 to DipMem[me].SentOffer.nDeliver - 1 do3070 include(DipMem[me].DeliveredPrices,3071 DipMem[ me].SentOffer.Price[i] shr 24);3072 for i := 0 to DipMem[me].SentOffer.nCost - 1 do3073 include(DipMem[me].ReceivedPrices,3074 DipMem[ me].SentOffer.Price[DipMem[me].SentOffer.nDeliver +3075 i] shr 24);3076 IsTreatyDeal := false;3077 for i:= 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do3078 if DipMem[ me].SentOffer.Price[i] and opMask = opTreaty then3079 IsTreatyDeal := true;3069 for I := 0 to DipMem[Me].SentOffer.nDeliver - 1 do 3070 Include(DipMem[Me].DeliveredPrices, 3071 DipMem[Me].SentOffer.Price[I] shr 24); 3072 for I := 0 to DipMem[Me].SentOffer.nCost - 1 do 3073 Include(DipMem[Me].ReceivedPrices, 3074 DipMem[Me].SentOffer.Price[DipMem[Me].SentOffer.nDeliver + 3075 I] shr 24); 3076 IsTreatyDeal := False; 3077 for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do 3078 if DipMem[Me].SentOffer.Price[I] and opMask = opTreaty then 3079 IsTreatyDeal := True; 3080 3080 if IsTreatyDeal then 3081 3081 Play('NEWTREATY') … … 3084 3084 end; 3085 3085 NegoDlg.Start; 3086 idle := true;3086 Idle := True; 3087 3087 end; 3088 3088 … … 3090 3090 if not IsMultiPlayerGame then 3091 3091 begin 3092 case G.RO[NewPlayer].Treaty[ integer(Data)] of3092 case G.RO[NewPlayer].Treaty[Integer(Data)] of 3093 3093 trPeace: 3094 s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE');3094 S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE'); 3095 3095 trFriendlyContact: 3096 s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY');3096 S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY'); 3097 3097 trAlliance: 3098 s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE');3098 S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE'); 3099 3099 end; 3100 TribeMessage( integer(Data), s, 'CANCELTREATY');3100 TribeMessage(Integer(Data), S, 'CANCELTREATY'); 3101 3101 end; 3102 3102 3103 3103 cShowCancelTreatyByAlliance: 3104 if idle and (NewPlayer = me) then3105 TribeMessage( integer(Data), Tribe[integer(Data)3104 if Idle and (NewPlayer = Me) then 3105 TribeMessage(Integer(Data), Tribe[Integer(Data) 3106 3106 ].TPhrase('FRENEMYALLIANCE'), 'CANCELTREATY'); 3107 3107 3108 3108 cShowSupportAllianceAgainst: 3109 3109 if not IsMultiPlayerGame and (Jump[0] = 0) then 3110 TribeMessage( integer(Data) and $F, Tribe[integer(Data) and $F]3111 .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[ integer(Data) shr 4]3110 TribeMessage(Integer(Data) and $F, Tribe[Integer(Data) and $F] 3111 .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[Integer(Data) shr 4] 3112 3112 .TPhrase('FRMYALLIANCE2'), 'CANCELTREATY'); 3113 3113 3114 3114 cShowPeaceViolation: 3115 3115 if not IsMultiPlayerGame and (Jump[0] = 0) then 3116 TribeMessage( integer(Data),3117 Format(Tribe[ integer(Data)].TPhrase('EVIOLATION'),3116 TribeMessage(Integer(Data), 3117 Format(Tribe[Integer(Data)].TPhrase('EVIOLATION'), 3118 3118 [TurnToString(MyRO.Turn + PeaceEvaTurns - 1)]), 'MSG_WITHDRAW'); 3119 3119 … … 3122 3122 3123 3123 cShowUnitChanged, cShowCityChanged, cShowAfterMove, cShowAfterAttack: 3124 if ( idle and (NewPlayer = me) or not idle and not skipped) and3124 if (Idle and (NewPlayer = Me) or not Idle and not skipped) and 3125 3125 not((GameMode = cMovie) and (MovieSpeed = 4)) then 3126 3126 begin 3127 assert(NewPlayer = me);3128 if not idle or (GameMode = cMovie) then3127 Assert(NewPlayer = Me); 3128 if not Idle or (GameMode = cMovie) then 3129 3129 Application.ProcessMessages; 3130 3130 if Command = cShowCityChanged then 3131 3131 begin 3132 CurrentMoveInfo.DoShow := false;3133 if idle then3134 CurrentMoveInfo.DoShow := true3132 CurrentMoveInfo.DoShow := False; 3133 if Idle then 3134 CurrentMoveInfo.DoShow := True 3135 3135 else if CurrentMoveInfo.IsAlly then 3136 3136 CurrentMoveInfo.DoShow := not mAlNoMoves.Checked … … 3140 3140 else if Command = cShowUnitChanged then 3141 3141 begin 3142 CurrentMoveInfo.DoShow := false;3143 if idle then3142 CurrentMoveInfo.DoShow := False; 3143 if Idle then 3144 3144 CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked 3145 3145 else if CurrentMoveInfo.IsAlly then … … 3155 3155 begin 3156 3156 if Command = cShowCityChanged then 3157 MapValid := false;3158 FocusOnLoc( integer(Data), flImmUpdate);3157 MapValid := False; 3158 FocusOnLoc(Integer(Data), flImmUpdate); 3159 3159 // OldUnFocus:=UnFocus; 3160 3160 // UnFocus:=-1; 3161 3161 if Command = cShowAfterMove then 3162 PaintLoc( integer(Data), CurrentMoveInfo.AfterMovePaintRadius)3162 PaintLoc(Integer(Data), CurrentMoveInfo.AfterMovePaintRadius) 3163 3163 // show discovered areas 3164 3164 else 3165 PaintLoc( integer(Data), 1);3165 PaintLoc(Integer(Data), 1); 3166 3166 // UnFocus:=OldUnFocus; 3167 3167 if (Command = cShowAfterAttack) and … … 3173 3173 Update; // remove message box from screen 3174 3174 end 3175 else if not idle then3175 else if not Idle then 3176 3176 if Command = cShowCityChanged then 3177 3177 Sleep(MoveTime * WaitAfterShowMove div 16) 3178 3178 else if (Command = cShowUnitChanged) and 3179 (MyMap[ integer(Data)] and fUnit <> 0) then3179 (MyMap[Integer(Data)] and fUnit <> 0) then 3180 3180 Sleep(MoveTime * WaitAfterShowMove div 32) 3181 3181 end // if CurrentMoveInfo.DoShow 3182 3182 else 3183 MapValid := false;3183 MapValid := False; 3184 3184 end; 3185 3185 3186 3186 cShowMoving, cShowCapturing: 3187 if ( idle and (NewPlayer = me) or not idle and not skipped and3187 if (Idle and (NewPlayer = Me) or not Idle and not skipped and 3188 3188 (TShowMove(Data).emix <> $FFFF)) and 3189 3189 not((GameMode = cMovie) and (MovieSpeed = 4)) then 3190 3190 begin 3191 assert(NewPlayer = me);3192 if not idle or (GameMode = cMovie) then3191 Assert(NewPlayer = Me); 3192 if not Idle or (GameMode = cMovie) then 3193 3193 Application.ProcessMessages; 3194 3194 with TShowMove(Data) do 3195 3195 begin 3196 CurrentMoveInfo.DoShow := false;3197 if not idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then3196 CurrentMoveInfo.DoShow := False; 3197 if not Idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then 3198 3198 InitEnemyModel(emix); 3199 3199 3200 3200 ToLoc := dLoc(FromLoc, dx, dy); 3201 if idle then3201 if Idle then 3202 3202 begin // own unit -- make discovered land visible 3203 assert(Owner = me); // no foreign moves during my turn!3203 Assert(Owner = Me); // no foreign moves during my turn! 3204 3204 CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked or 3205 3205 (Command = cShowCapturing); … … 3234 3234 else 3235 3235 CurrentMoveInfo.AfterMovePaintRadius := 1; 3236 if (MyRO.Wonder[woShinkansen].EffectiveOwner = me) and3236 if (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) and 3237 3237 (Domain = dGround) and 3238 3238 (MyMap[FromLoc] and (fRR or fCity) <> 0) and … … 3249 3249 CurrentMoveInfo.IsAlly := MyRO.Treaty[Owner] = trAlliance; 3250 3250 if GameMode = cMovie then 3251 CurrentMoveInfo.DoShow := true3251 CurrentMoveInfo.DoShow := True 3252 3252 else if CurrentMoveInfo.IsAlly then 3253 3253 CurrentMoveInfo.DoShow := not mAlNoMoves.Checked and … … 3265 3265 cix := MyRO.nCity - 1; 3266 3266 while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do 3267 dec(cix);3268 s:= CityName(MyCity[cix].ID);3267 Dec(cix); 3268 S := CityName(MyCity[cix].ID); 3269 3269 end 3270 3270 else … … 3272 3272 ecix := MyRO.nEnemyCity - 1; 3273 3273 while (ecix >= 0) and (MyRO.EnemyCity[ecix].Loc <> ToLoc) do 3274 dec(ecix);3275 s:= CityName(MyRO.EnemyCity[ecix].ID);3274 Dec(ecix); 3275 S := CityName(MyRO.EnemyCity[ecix].ID); 3276 3276 end; 3277 3277 TribeMessage(Owner, Format(Tribe[Owner].TPhrase('CAPTURE'), 3278 [ s]), '');3278 [S]), ''); 3279 3279 Update; // remove message box from screen 3280 3280 end; … … 3361 3361 end // if CurrentMoveInfo.DoShow 3362 3362 else 3363 MapValid := false;3363 MapValid := False; 3364 3364 end; 3365 3365 end; 3366 3366 3367 3367 cShowAttacking: 3368 if ( idle and (NewPlayer = me) or not idle and not skipped and3368 if (Idle and (NewPlayer = Me) or not Idle and not skipped and 3369 3369 (TShowMove(Data).emix <> $FFFF)) and 3370 3370 not((GameMode = cMovie) and (MovieSpeed = 4)) then 3371 3371 begin 3372 assert(NewPlayer = me);3373 if not idle or (GameMode = cMovie) then3372 Assert(NewPlayer = Me); 3373 if not Idle or (GameMode = cMovie) then 3374 3374 Application.ProcessMessages; 3375 3375 with TShowMove(Data) do 3376 3376 begin 3377 3377 CurrentMoveInfo.AfterAttackExpeller := -1; 3378 CurrentMoveInfo.DoShow := false;3379 if idle then3380 CurrentMoveInfo.DoShow := true // own unit -- always show attacks3378 CurrentMoveInfo.DoShow := False; 3379 if Idle then 3380 CurrentMoveInfo.DoShow := True // own unit -- always show attacks 3381 3381 else 3382 3382 begin … … 3398 3398 cix := MyRO.nCity - 1; 3399 3399 while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do 3400 dec(cix);3400 Dec(cix); 3401 3401 if MyCity[cix].Status and csToldBombard = 0 then 3402 3402 begin 3403 if not supervising then3403 if not Supervising then 3404 3404 MyCity[cix].Status := MyCity[cix].Status or csToldBombard; 3405 s:= CityName(MyCity[cix].ID);3405 S := CityName(MyCity[cix].ID); 3406 3406 SoundMessageEx(Format(Tribe[Owner].TPhrase('BOMBARD'), 3407 [ s]), '');3407 [S]), ''); 3408 3408 Update; // remove message box from screen 3409 3409 end; … … 3414 3414 if Flags and umExpelling <> 0 then 3415 3415 Play('MOVE_EXPEL') 3416 else if Owner = me then3416 else if Owner = Me then 3417 3417 begin 3418 MakeModelInfo( me, mix, MyModel[mix], mi);3418 MakeModelInfo(Me, mix, MyModel[mix], mi); 3419 3419 Play(AttackSound(ModelCode(mi))); 3420 3420 end … … 3441 3441 MoveOnScreen(TShowMove(Data), 10, 0, 16); 3442 3442 end 3443 else if not idle then3443 else if not Idle then 3444 3444 Sleep(MoveTime div 2); 3445 3445 MainMap.AttackEnd; 3446 3446 end // if CurrentMoveInfo.DoShow 3447 3447 else 3448 MapValid := false;3448 MapValid := False; 3449 3449 end; 3450 3450 end; … … 3455 3455 else 3456 3456 begin 3457 s:= Phrases.Lookup('FOREIGNINFO');3457 S := Phrases.Lookup('FOREIGNINFO'); 3458 3458 for p1 := 0 to nPl - 1 do 3459 3459 if 3 shl (p1 * 2) and Cardinal(Data) <> 0 then 3460 s := s+ '\' + Tribe[p1].TPhrase('SHORTNAME');3461 SoundMessageEx( s, '');3460 S := S + '\' + Tribe[p1].TPhrase('SHORTNAME'); 3461 SoundMessageEx(S, ''); 3462 3462 end; 3463 3463 … … 3471 3471 begin 3472 3472 MessgText := Format(Phrases.Lookup('GRLIB_GENERAL'), 3473 [Phrases.Lookup('ADVANCES', integer(Data))]);3473 [Phrases.Lookup('ADVANCES', Integer(Data))]); 3474 3474 OpenSound := 'NEWADVANCE_GRLIB'; 3475 3475 Kind := mkOk; … … 3481 3481 cRefreshDebugMap: 3482 3482 begin 3483 if integer(Data) = MainMap.pDebugMap then3483 if Integer(Data) = MainMap.pDebugMap then 3484 3484 begin 3485 MapValid := false;3485 MapValid := False; 3486 3486 MainOffscreenPaint; 3487 3487 Update; … … 3494 3494 cSetTribe: 3495 3495 with TTribeInfo(Data) do begin 3496 i:= UnusedTribeFiles.Count - 1;3497 while ( i>= 0) and3498 (AnsiCompareFileName(UnusedTribeFiles[ i], FileName) <> 0) do3499 dec(i);3500 if i>= 0 then3501 UnusedTribeFiles.Delete( i);3502 CreateTribe(trix, FileName, true);3496 I := UnusedTribeFiles.Count - 1; 3497 while (I >= 0) and 3498 (AnsiCompareFileName(UnusedTribeFiles[I], FileName) <> 0) do 3499 Dec(I); 3500 if I >= 0 then 3501 UnusedTribeFiles.Delete(I); 3502 CreateTribe(trix, FileName, True); 3503 3503 end; 3504 3504 cSetNewModelPicture: … … 3511 3511 (TModelPictureInfo(Data), False); 3512 3512 cSetSlaveIndex: 3513 Tribe[ integer(Data) shr 16].mixSlaves := integer(Data) and $FFFF;3513 Tribe[Integer(Data) shr 16].mixSlaves := Integer(Data) and $FFFF; 3514 3514 cSetCityName: 3515 3515 with TCityNameInfo(Data) do … … 3528 3528 procedure TMainScreen.FormCreate(Sender: TObject); 3529 3529 var 3530 i, j: integer;3530 I, J: Integer; 3531 3531 begin 3532 3532 NoMap := TIsoMap.Create; … … 3570 3570 3571 3571 // tag-controlled language 3572 for i:= 0 to ComponentCount - 1 do3573 if Components[ i].Tag and $FF <> 0 then3574 if Components[ i] is TMenuItem then begin3575 TMenuItem(Components[ i]).Caption := Phrases.Lookup('CONTROLS',3576 -1 + Components[ i].Tag and $FF);3577 for j:= 0 to Length(SaveOption) - 1 do3578 if Components[ i].Tag and $FF = SaveOption[j] then3579 TMenuItem(Components[ i]).Checked := TSaveOption(j) in OptionChecked;3572 for I := 0 to ComponentCount - 1 do 3573 if Components[I].Tag and $FF <> 0 then 3574 if Components[I] is TMenuItem then begin 3575 TMenuItem(Components[I]).Caption := Phrases.Lookup('CONTROLS', 3576 -1 + Components[I].Tag and $FF); 3577 for J := 0 to Length(SaveOption) - 1 do 3578 if Components[I].Tag and $FF = SaveOption[J] then 3579 TMenuItem(Components[I]).Checked := TSaveOption(J) in OptionChecked; 3580 3580 end else 3581 if Components[ i] is TButtonBase then begin3582 TButtonBase(Components[ i]).Hint := Phrases.Lookup('CONTROLS',3583 -1 + Components[ i].Tag and $FF);3584 if (Components[ i] is TButtonC) and3585 (TButtonC(Components[ i]).ButtonIndex <> 1) then3586 TButtonC(Components[ i]).ButtonIndex :=3587 Integer(MapOptionChecked) shr (Components[ i].Tag shr 8) and 1 + 23581 if Components[I] is TButtonBase then begin 3582 TButtonBase(Components[I]).Hint := Phrases.Lookup('CONTROLS', 3583 -1 + Components[I].Tag and $FF); 3584 if (Components[I] is TButtonC) and 3585 (TButtonC(Components[I]).ButtonIndex <> 1) then 3586 TButtonC(Components[I]).ButtonIndex := 3587 Integer(MapOptionChecked) shr (Components[I].Tag shr 8) and 1 + 2 3588 3588 end; 3589 3589 … … 3598 3598 ManagementArea.Hint := Phrases2.Lookup('BTN_MANAGE'); 3599 3599 end; 3600 for i:= 0 to mRep.Count - 1 do3601 begin 3602 j := mRep[i].Tag shr 8;3603 mRep[ i].Caption := CityEventName(j);3604 mRep[ i].Checked := CityRepMask and (1 shl j) <> 0;3600 for I := 0 to mRep.Count - 1 do 3601 begin 3602 J := mRep[I].Tag shr 8; 3603 mRep[I].Caption := CityEventName(J); 3604 mRep[I].Checked := CityRepMask and (1 shl J) <> 0; 3605 3605 end; 3606 3606 … … 3621 3621 else Buffer.height := 3 * ySizeBig; 3622 3622 Buffer.Canvas.Font.Assign(UniFont[ftSmall]); 3623 for i:= 0 to nPl - 1 do3624 AILogo[ i] := nil;3623 for I := 0 to nPl - 1 do 3624 AILogo[I] := nil; 3625 3625 Canvas.Font.Assign(UniFont[ftSmall]); 3626 3626 InitButtons; … … 3639 3639 FreeAndNil(Panel); 3640 3640 for I := 0 to nPl - 1 do 3641 if AILogo[ i] <> nil then3641 if AILogo[I] <> nil then 3642 3642 FreeAndNil(AILogo[I]); 3643 3643 FreeAndNil(Offscreen); … … 3699 3699 Status := Status and ($FFFF - usRecover - usGoto - usEnhance); 3700 3700 if Job > jNone then 3701 Server(sStartJob + jNone shl 4, me, UnFocus, nil^);3701 Server(sStartJob + jNone shl 4, Me, UnFocus, nil^); 3702 3702 end; 3703 3703 end; … … 3725 3725 if DoJob(jCity) = eCity then 3726 3726 begin 3727 MapValid := false;3727 MapValid := False; 3728 3728 PaintAll; 3729 ZoomToCity(Loc0, true, chFounded);3729 ZoomToCity(Loc0, True, chFounded); 3730 3730 end; 3731 3731 end else begin 3732 3732 CityOptimizer_BeforeRemoveUnit(UnFocus); 3733 ServerResult := Server(sAddToCity, me, UnFocus, nil^);3733 ServerResult := Server(sAddToCity, Me, UnFocus, nil^); 3734 3734 if ServerResult >= rExecuted then 3735 3735 begin 3736 3736 cix := MyRO.nCity - 1; 3737 3737 while (cix >= 0) and (MyCity[cix].Loc <> Loc0) do 3738 dec(cix);3739 assert(cix >= 0);3738 Dec(cix); 3739 Assert(cix >= 0); 3740 3740 CityOptimizer_CityChange(cix); 3741 3741 CityOptimizer_AfterRemoveUnit; // does nothing here 3742 3742 SetTroopLoc(Loc0); 3743 UpdateViews( true);3744 DestinationMarkON := false;3743 UpdateViews(True); 3744 DestinationMarkON := False; 3745 3745 PaintDestination; 3746 3746 UnFocus := -1; 3747 3747 PaintLoc(Loc0); 3748 NextUnit(UnStartLoc, true);3748 NextUnit(UnStartLoc, True); 3749 3749 end 3750 3750 else if ServerResult = eMaxSize then … … 3829 3829 Destination := Status shr 16; 3830 3830 Status := Status and not(usStay or usRecover) or usWaiting; 3831 MoveToLoc(Destination, true);3831 MoveToLoc(Destination, True); 3832 3832 end; 3833 3833 end; … … 3850 3850 begin 3851 3851 cixOldHome := Home; 3852 if Server(sSetUnitHome, me, UnFocus, nil^) >= rExecuted then3852 if Server(sSetUnitHome, Me, UnFocus, nil^) >= rExecuted then 3853 3853 begin 3854 3854 CityOptimizer_CityChange(cixOldHome); 3855 3855 CityOptimizer_CityChange(Home); 3856 UpdateViews( true);3856 UpdateViews(True); 3857 3857 end 3858 3858 else … … 3862 3862 begin 3863 3863 Status := Status and not(usStay or usRecover or usEnhance); 3864 MoveToLoc(maNextCity, true);3864 MoveToLoc(maNextCity, True); 3865 3865 end; 3866 3866 end; … … 3882 3882 procedure TMainScreen.mJumpClick(Sender: TObject); 3883 3883 begin 3884 if supervising then3884 if Supervising then 3885 3885 Jump[0] := 20 3886 3886 else 3887 Jump[ me] := 20;3888 EndTurn( true);3887 Jump[Me] := 20; 3888 EndTurn(True); 3889 3889 end; 3890 3890 … … 3895 3895 if UnFocus >= 0 then 3896 3896 with MyUn[UnFocus] do begin 3897 i := Server(sLoadUnit, me, UnFocus, nil^);3898 if i>= rExecuted then3897 I := Server(sLoadUnit, Me, UnFocus, nil^); 3898 if I >= rExecuted then 3899 3899 begin 3900 3900 if MyModel[mix].Domain = dAir then … … 3902 3902 else 3903 3903 Play('MOVE_LOAD'); 3904 DestinationMarkON := false;3904 DestinationMarkON := False; 3905 3905 PaintDestination; 3906 3906 Status := Status and ($FFFF - usWaiting - usStay - usRecover - usGoto - usEnhance); 3907 NextUnit(UnStartLoc, true);3907 NextUnit(UnStartLoc, True); 3908 3908 end 3909 else if i= eNoTime_Load then3909 else if I = eNoTime_Load then 3910 3910 if MyModel[mix].Domain = dAir then 3911 3911 SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME') … … 3942 3942 with MyUn[UnFocus] do begin 3943 3943 Status := Status and not usWaiting; 3944 NextUnit(UnStartLoc, true);3944 NextUnit(UnStartLoc, True); 3945 3945 end; 3946 3946 end; … … 3971 3971 if not Edited or (SimpleQuery(mkYesNo, Phrases.Lookup('MAP_RANDOM'), '') 3972 3972 = mrOK) then begin 3973 Server(sRandomMap, me, 0, nil^);3974 Edited := true;3975 MapValid := false;3973 Server(sRandomMap, Me, 0, nil^); 3974 Edited := True; 3975 MapValid := False; 3976 3976 PaintAllMaps; 3977 3977 end; … … 3982 3982 if UnFocus >= 0 then 3983 3983 with MyUn[UnFocus] do begin 3984 DestinationMarkON := false;3984 DestinationMarkON := False; 3985 3985 PaintDestination; 3986 3986 Status := Status and ($FFFF - usStay - usGoto - usEnhance) or usRecover; 3987 3987 if Job > jNone then 3988 Server(sStartJob + jNone shl 4, me, UnFocus, nil^);3989 NextUnit(UnStartLoc, true);3988 Server(sStartJob + jNone shl 4, Me, UnFocus, nil^); 3989 NextUnit(UnStartLoc, True); 3990 3990 end; 3991 3991 end; … … 3999 3999 QueryText := Phrases.Lookup('MAP_CLOSE'); 4000 4000 case SimpleQuery(mkYesNoCancel, QueryText, '') of 4001 mrIgnore: Server(sAbandonMap, me, 0, nil^);4002 mrOK: Server(sSaveMap, me, 0, nil^);4001 mrIgnore: Server(sAbandonMap, Me, 0, nil^); 4002 mrOK: Server(sSaveMap, Me, 0, nil^); 4003 4003 end; 4004 4004 end else 4005 Server(sAbandonMap, me, 0, nil^);4005 Server(sAbandonMap, Me, 0, nil^); 4006 4006 end else begin 4007 4007 if Server(sGetGameChanged, 0, 0, nil^) = eOK then begin … … 4022 4022 I: Integer; 4023 4023 begin 4024 AltGovs := false;4025 for i:= 2 to nGov - 1 do4026 if (GovPreq[ i] <> preNA) and4027 ((GovPreq[ i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable)) then4028 AltGovs := true;4024 AltGovs := False; 4025 for I := 2 to nGov - 1 do 4026 if (GovPreq[I] <> preNA) and 4027 ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable)) then 4028 AltGovs := True; 4029 4029 4030 4030 if not AltGovs then … … 4032 4032 else 4033 4033 begin 4034 RevolutionChanged := false;4034 RevolutionChanged := False; 4035 4035 if MyRO.Happened and phChangeGov <> 0 then 4036 4036 begin 4037 4037 ModalSelectDlg.ShowNewContent(wmModal, kGov); 4038 if ModalSelectDlg. result >= 0 then4038 if ModalSelectDlg.Result >= 0 then 4039 4039 begin 4040 4040 Play('NEWGOV'); 4041 Server(sSetGovernment, me, ModalSelectDlg.result, nil^);4041 Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^); 4042 4042 CityOptimizer_BeginOfTurn; 4043 RevolutionChanged := true;4043 RevolutionChanged := True; 4044 4044 end; 4045 4045 end … … 4047 4047 with MessgExDlg do 4048 4048 begin // revolution! 4049 MessgExDlg.MessgText := Tribe[ me].TPhrase('REVOLUTION');4049 MessgExDlg.MessgText := Tribe[Me].TPhrase('REVOLUTION'); 4050 4050 MessgExDlg.Kind := mkYesNo; 4051 4051 MessgExDlg.IconKind := mikPureIcon; … … 4055 4055 begin 4056 4056 Play('REVOLUTION'); 4057 Server(sRevolution, me, 0, nil^);4058 RevolutionChanged := true;4057 Server(sRevolution, Me, 0, nil^); 4058 RevolutionChanged := True; 4059 4059 if NatStatDlg.Visible then 4060 4060 NatStatDlg.Close; … … 4064 4064 end; 4065 4065 if RevolutionChanged then 4066 UpdateViews( true);4066 UpdateViews(True); 4067 4067 end; 4068 4068 end; … … 4084 4084 procedure TMainScreen.mRunClick(Sender: TObject); 4085 4085 begin 4086 if supervising then4086 if Supervising then 4087 4087 Jump[0] := 999999 4088 4088 else 4089 Jump[ me] := 999999;4090 EndTurn( true);4089 Jump[Me] := 999999; 4090 EndTurn(True); 4091 4091 end; 4092 4092 … … 4100 4100 if UnFocus >= 0 then 4101 4101 with TUn(MyUn[UnFocus]) do 4102 Server(sSelectTransport, me, UnFocus, nil^);4102 Server(sSelectTransport, Me, UnFocus, nil^); 4103 4103 end; 4104 4104 … … 4112 4112 if UnFocus >= 0 then 4113 4113 with TUn(MyUn[UnFocus]) do begin 4114 DestinationMarkON := false;4114 DestinationMarkON := False; 4115 4115 PaintDestination; 4116 4116 Status := Status and ($FFFF - usRecover - usGoto - usEnhance) or usStay; 4117 4117 if Job > jNone then 4118 Server(sStartJob + jNone shl 4, me, UnFocus, nil^);4119 NextUnit(UnStartLoc, true);4118 Server(sStartJob + jNone shl 4, Me, UnFocus, nil^); 4119 NextUnit(UnStartLoc, True); 4120 4120 end; 4121 4121 end; … … 4137 4137 I: Integer; 4138 4138 begin 4139 if G.Difficulty[ me] > 0 then4140 ListDlg.ShowNewContent_MilReport(wmPersistent, me)4139 if G.Difficulty[Me] > 0 then 4140 ListDlg.ShowNewContent_MilReport(wmPersistent, Me) 4141 4141 else 4142 4142 begin 4143 i:= 1;4144 while ( i < nPl) and (1 shl iand MyRO.Alive = 0) do4145 inc(i);4146 if i< nPl then4147 ListDlg.ShowNewContent_MilReport(wmPersistent, i);4143 I := 1; 4144 while (I < nPl) and (1 shl I and MyRO.Alive = 0) do 4145 Inc(I); 4146 if I < nPl then 4147 ListDlg.ShowNewContent_MilReport(wmPersistent, I); 4148 4148 end; 4149 4149 end; … … 4160 4160 if Master >= 0 then begin 4161 4161 OldMaster := Master; 4162 i := Server(sUnloadUnit, me, UnFocus, nil^);4163 if i>= rExecuted then4162 I := Server(sUnloadUnit, Me, UnFocus, nil^); 4163 if I >= rExecuted then 4164 4164 begin 4165 4165 if MyModel[mix].Domain = dAir then … … 4173 4173 Status := Status and not usWaiting; 4174 4174 if MyModel[mix].Domain <> dAir then 4175 NextUnit(Loc, true)4175 NextUnit(Loc, True) 4176 4176 else 4177 4177 PanelPaint; 4178 4178 end 4179 else if i= eNoTime_Load then4179 else if I = eNoTime_Load then 4180 4180 if MyModel[mix].Domain = dAir then 4181 4181 SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME') … … 4186 4186 NewFocus := -1; 4187 4187 uix := UnFocus; 4188 for i:= 1 to MyRO.nUn - 1 do4188 for I := 1 to MyRO.nUn - 1 do 4189 4189 begin 4190 4190 uix := (uix + MyRO.nUn - 1) mod MyRO.nUn; 4191 4191 if (MyUn[uix].Master = UnFocus) and 4192 (MyUn[uix].Movement = integer(MyModel[MyUn[uix].mix].speed)) then4192 (MyUn[uix].Movement = Integer(MyModel[MyUn[uix].mix].speed)) then 4193 4193 begin 4194 4194 MyUn[uix].Status := MyUn[uix].Status or usWaiting; … … 4210 4210 if UnFocus >= 0 then 4211 4211 with MyUn[UnFocus] do begin 4212 DestinationMarkON := false;4212 DestinationMarkON := False; 4213 4213 PaintDestination; 4214 4214 Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting; 4215 4215 end; 4216 NextUnit(-1, false);4216 NextUnit(-1, False); 4217 4217 end; 4218 4218 … … 4229 4229 procedure TMainScreen.FormResize(Sender: TObject); 4230 4230 var 4231 MiniFrame, MaxMapWidth: integer;4231 MiniFrame, MaxMapWidth: Integer; 4232 4232 begin 4233 4233 SmallScreen := ClientWidth < 1024; … … 4307 4307 begin 4308 4308 RectInvalidate(0, TopBarHeight, ClientWidth, TopBarHeight + MapHeight); 4309 MapValid := false;4309 MapValid := False; 4310 4310 PaintAll; 4311 4311 end; 4312 4312 end; 4313 4313 4314 procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: boolean);4314 procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 4315 4315 begin 4316 4316 CanClose := Closable; 4317 if not Closable and idle and (me = 0) and (ClientMode < scContact) then4317 if not Closable and Idle and (Me = 0) and (ClientMode < scContact) then 4318 4318 mResign.Click; 4319 4319 end; … … 4337 4337 begin 4338 4338 MessgExDlg.CancelMovie; 4339 Server(sBreak, me, 0, nil^);4339 Server(sBreak, Me, 0, nil^); 4340 4340 end 4341 4341 else if ClientMode < 0 then 4342 skipped := true4342 skipped := True 4343 4343 else if ClientMode >= scContact then 4344 4344 NegoDlg.ShowNewContent(wmPersistent) … … 4346 4346 begin 4347 4347 Jump[pTurn] := 0; 4348 StartRunning := false;4348 StartRunning := False; 4349 4349 end 4350 4350 else … … 4359 4359 else 4360 4360 with MainMap do begin 4361 if supervising then4361 if Supervising then 4362 4362 xTerrain := xMidPanel + 2 * xxt + 14 4363 4363 else if ClientWidth < 1280 then … … 4366 4366 xTerrain := ClientWidth div 2; 4367 4367 xTroop := xTerrain + 2 * xxt + 12; 4368 if SmallScreen and not supervising then4368 if SmallScreen and not Supervising then 4369 4369 xTroop := xRightPanel + 10 - 3 * 66 - 4370 4370 GetSystemMetrics(SM_CXVSCROLL) - 19 - 4; … … 4375 4375 end; 4376 4376 4377 function TMainScreen.EndTurn(WasSkipped: boolean): boolean;4378 4379 function IsResourceUnused(cix, NeedFood, NeedProd: integer): boolean;4377 function TMainScreen.EndTurn(WasSkipped: Boolean): Boolean; 4378 4379 function IsResourceUnused(cix, NeedFood, NeedProd: Integer): Boolean; 4380 4380 var 4381 dx, dy, fix: integer;4381 dx, dy, fix: Integer; 4382 4382 CityAreaInfo: TCityAreaInfo; 4383 4383 TileInfo: TTileInfo; 4384 4384 begin 4385 Server(sGetCityAreaInfo, me, cix, CityAreaInfo);4385 Server(sGetCityAreaInfo, Me, cix, CityAreaInfo); 4386 4386 for dy := -3 to 3 do 4387 4387 for dx := -3 to 3 do … … 4393 4393 begin 4394 4394 TileInfo.ExplCity := cix; 4395 Server(sGetHypoCityTileInfo, me, dLoc(MyCity[cix].Loc, dx, dy),4395 Server(sGetHypoCityTileInfo, Me, dLoc(MyCity[cix].Loc, dx, dy), 4396 4396 TileInfo); 4397 4397 if (TileInfo.Food >= NeedFood) and (TileInfo.Prod >= NeedProd) then 4398 4398 begin 4399 result := true;4400 exit4399 Result := True; 4400 Exit 4401 4401 end; 4402 4402 end 4403 4403 end; 4404 result := false;4404 Result := False; 4405 4405 end; 4406 4406 4407 4407 var 4408 p1, uix, cix, CenterLoc: integer;4408 p1, uix, cix, CenterLoc: Integer; 4409 4409 MsgItem: string; 4410 4410 CityReport: TCityReport; 4411 4411 PlaneReturnData: TPlaneReturnData; 4412 Zoom: boolean;4413 begin 4414 result := false;4412 Zoom: Boolean; 4413 begin 4414 Result := False; 4415 4415 if ClientMode >= scDipOffer then 4416 4416 Exit; 4417 4417 4418 if supervising and (me <> 0) then begin4418 if Supervising and (Me <> 0) then begin 4419 4419 ApplyToVisibleForms(faClose); 4420 4420 ItsMeAgain(0); … … 4435 4435 PlaneReturnData.Loc := Loc; 4436 4436 PlaneReturnData.Movement := 0; // end turn without further movement? 4437 if Server(sGetPlaneReturn, me, uix, PlaneReturnData) = eNoWay then4437 if Server(sGetPlaneReturn, Me, uix, PlaneReturnData) = eNoWay then 4438 4438 begin 4439 4439 CenterLoc := Loc + G.lx * 6; 4440 4440 // centering the unit itself would make it covered by the query dialog 4441 4441 while CenterLoc >= G.lx * G.ly do 4442 dec(CenterLoc, G.lx * 2);4442 Dec(CenterLoc, G.lx * 2); 4443 4443 Centre(CenterLoc); 4444 4444 SetTroopLoc(-1); … … 4455 4455 SetTroopLoc(Loc); 4456 4456 PanelPaint; 4457 exit;4457 Exit; 4458 4458 end; 4459 4459 MyUn[uix].Status := MyUn[uix].Status or usToldNoReturn; … … 4461 4461 end; 4462 4462 4463 if not supervising and (MyRO.TestFlags and tfImmImprove = 0) and4463 if not Supervising and (MyRO.TestFlags and tfImmImprove = 0) and 4464 4464 (MyRO.Government <> gAnarchy) and (MyRO.Money + TaxSum < 0) and 4465 4465 (MyRO.TaxRate < 100) then // low funds! … … 4473 4473 ShowModal; 4474 4474 if ModalResult <> mrOK then 4475 exit;4475 Exit; 4476 4476 end; 4477 4477 … … 4481 4481 if (Loc >= 0) and (Flags and chCaptured = 0) then 4482 4482 begin 4483 Zoom := false;4483 Zoom := False; 4484 4484 CityReport.HypoTiles := -1; 4485 4485 CityReport.HypoTax := -1; 4486 4486 CityReport.HypoLux := -1; 4487 Server(sGetCityReport, me, cix, CityReport);4487 Server(sGetCityReport, Me, cix, CityReport); 4488 4488 4489 4489 if (CityReport.Working - CityReport.Happy > Size shr 1) and … … 4576 4576 else 4577 4577 EOT.Hint := Phrases.Lookup('BTN_SKIP'); 4578 result := true;4578 Result := True; 4579 4579 SetTroopLoc(-1); 4580 4580 pTurn := -1; 4581 4581 pLogo := -1; 4582 UnitInfoBtn.Visible := false;4583 UnitBtn.Visible := false;4584 TerrainBtn.Visible := false;4582 UnitInfoBtn.Visible := False; 4583 UnitBtn.Visible := False; 4584 TerrainBtn.Visible := False; 4585 4585 EOT.ButtonIndex := eotCancel; 4586 EOT.Visible := true;4587 MapValid := false;4586 EOT.Visible := True; 4587 MapValid := False; 4588 4588 PanelPaint; 4589 4589 Update; 4590 4590 ClientMode := -1; 4591 idle := false;4591 Idle := False; 4592 4592 skipped := WasSkipped; 4593 4593 for p1 := 1 to nPl - 1 do 4594 4594 if G.RO[p1] <> nil then 4595 skipped := true; // don't show enemy moves in hotseat mode4595 skipped := True; // don't show enemy moves in hotseat mode 4596 4596 end 4597 4597 else … … 4603 4603 if NegoDlg.Visible then 4604 4604 NegoDlg.Close; 4605 HaveStrategyAdvice := false;4605 HaveStrategyAdvice := False; 4606 4606 // AdvisorDlg.HaveStrategyAdvice; 4607 4607 // negotiation might have changed advices 4608 4608 EOT.ButtonIndex := eotCancel; 4609 EOT.Visible := true;4609 EOT.Visible := True; 4610 4610 PanelPaint; 4611 4611 Update; 4612 4612 ClientMode := -1; 4613 idle := false;4614 end; 4615 4616 procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: integer);4613 Idle := False; 4614 end; 4615 4616 procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: Integer); 4617 4617 var 4618 xs, ys, xl, yl: integer;4618 xs, ys, xl, yl: Integer; 4619 4619 begin 4620 4620 with MainMap do begin … … 4625 4625 while abs(2 * (xs + G.lx * (xxt * 2)) + xl - MapWidth) < 4626 4626 abs(2 * xs + xl - MapWidth) do 4627 inc(xs, G.lx * (xxt * 2));4627 Inc(xs, G.lx * (xxt * 2)); 4628 4628 ys := (y0 - yw) * yyt - yyt; 4629 4629 if xs + xl > MapWidth then … … 4632 4632 yl := MapHeight - ys; 4633 4633 if (xl <= 0) or (yl <= 0) then 4634 exit;4634 Exit; 4635 4635 if Options and prPaint <> 0 then begin 4636 4636 if Options and prAutoBounds <> 0 then … … 4644 4644 end; 4645 4645 4646 procedure TMainScreen.PaintLoc(Loc: integer; Radius: integer = 0);4646 procedure TMainScreen.PaintLoc(Loc: Integer; Radius: Integer = 0); 4647 4647 var 4648 yLoc, x0: integer;4648 yLoc, x0: Integer; 4649 4649 begin 4650 4650 if MapValid then begin 4651 4651 yLoc := (Loc + G.lx * 1024) div G.lx - 1024; 4652 4652 x0 := (Loc + (yLoc and 1 - 2 * Radius + G.lx * 1024) div 2) mod G.lx; 4653 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);4653 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 4654 4654 ProcessRect(x0, yLoc - 2 * Radius, 4 * Radius + 1, 4 * Radius + 1, 4655 4655 prPaint or prAutoBounds or prInvalidate); … … 4658 4658 end; 4659 4659 4660 procedure TMainScreen.PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle);4660 procedure TMainScreen.PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle); 4661 4661 var 4662 y0, x0, xMap, yMap: integer;4662 y0, x0, xMap, yMap: Integer; 4663 4663 begin 4664 4664 with NoMap do begin 4665 4665 if not MapValid then 4666 exit;4666 Exit; 4667 4667 Buffer.Canvas.Font.Assign(UniFont[ftSmall]); 4668 4668 y0 := Loc div G.lx; … … 4672 4672 while abs(2 * (xMap + G.lx * (xxt * 2)) + 2 * xxt - MapWidth) < 4673 4673 abs(2 * xMap + 2 * xxt - MapWidth) do 4674 inc(xMap, G.lx * (xxt * 2));4674 Inc(xMap, G.lx * (xxt * 2)); 4675 4675 yMap := (y0 - yw) * yyt - yyt; 4676 4676 NoMap.SetOutput(Buffer); … … 4684 4684 // panel protusions are added 4685 4685 // NoMap must be set to buffer and bounds before 4686 procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: integer);4686 procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: Integer); 4687 4687 begin 4688 4688 if xMap + width > MapWidth then … … 4692 4692 if (width <= 0) or (height <= 0) or (width + xMap <= 0) or (height + yMap <= 0) 4693 4693 then 4694 exit;4694 Exit; 4695 4695 4696 4696 NoMap.BitBltBitmap(Panel, -xMap - MapOffset, -yMap + MapHeight - overlap, xMidPanel, … … 4719 4719 end; 4720 4720 4721 procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: integer);4721 procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: Integer); 4722 4722 var 4723 yLoc, x0: integer;4723 yLoc, x0: Integer; 4724 4724 begin 4725 4725 if MapValid then … … 4727 4727 yLoc := (FromLoc + G.lx * 1024) div G.lx - 1024; 4728 4728 x0 := (FromLoc + (yLoc and 1 + G.lx * 1024) div 2) mod G.lx; 4729 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);4729 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 4730 4730 ProcessRect(x0, yLoc, 1, 1, prPaint or prAutoBounds); 4731 4731 end … … 4734 4734 procedure TMainScreen.PaintDestination; 4735 4735 var 4736 Destination: integer;4736 Destination: Integer; 4737 4737 begin 4738 4738 if (UnFocus >= 0) and (MyUn[UnFocus].Status and usGoto <> 0) then … … 4755 4755 procedure TMainScreen.MainOffscreenPaint; 4756 4756 var 4757 ProcessOptions: integer;4757 ProcessOptions: Integer; 4758 4758 rec: TRect; 4759 DoInvalidate: boolean;4760 begin 4761 if me < 0 then4762 with offscreen.Canvas do4759 DoInvalidate: Boolean; 4760 begin 4761 if Me < 0 then 4762 with Offscreen.Canvas do 4763 4763 begin 4764 4764 Brush.Color := $000000; … … 4766 4766 Brush.Style := bsClear; 4767 4767 OffscreenUser := self; 4768 exit;4768 Exit; 4769 4769 end; 4770 4770 … … 4777 4777 if MapValid and (xwd = xw) and (ywd = yw) then 4778 4778 MainMap.SetPaintBounds(0, 0, UsedOffscreenWidth, UsedOffscreenHeight); 4779 MapValid := false;4779 MapValid := False; 4780 4780 OffscreenUser := self; 4781 4781 end; … … 4790 4790 (ywd - yw > MapHeight div yyt) then 4791 4791 begin 4792 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);4792 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 4793 4793 ProcessRect(xw, yw, MapWidth div xxt, MapHeight div yyt, 4794 4794 prPaint or prInvalidate); 4795 4795 end else begin 4796 4796 if (xwd = xw) and (ywd = yw) then 4797 exit; { map window not moved }4798 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);4797 Exit; { map window not moved } 4798 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 4799 4799 rec := Rect(0, 0, MapWidth, MapHeight); 4800 4800 {$IFDEF WINDOWS} 4801 ScrollDC( offscreen.Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,4801 ScrollDC(Offscreen.Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt, 4802 4802 rec, rec, 0, nil); 4803 4803 {$ENDIF} 4804 4804 {$IFDEF UNIX} 4805 ScrollDC( offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,4805 ScrollDC(Offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt, 4806 4806 rec, rec, 0, nil); 4807 4807 {$ENDIF} 4808 for DoInvalidate := false to FastScrolling do begin4808 for DoInvalidate := False to FastScrolling do begin 4809 4809 if DoInvalidate then begin 4810 4810 rec.Bottom := MapHeight - overlap; … … 4863 4863 xwd := xw; 4864 4864 ywd := yw; 4865 MapValid := true;4865 MapValid := True; 4866 4866 end; 4867 4867 … … 4920 4920 function MovementToString(var Un: TUn): string; 4921 4921 begin 4922 result := ScreenTools.MovementToString(Un.Movement);4922 Result := ScreenTools.MovementToString(Un.Movement); 4923 4923 if Un.Master >= 0 then 4924 result := '(' + result + ')'4924 Result := '(' + Result + ')' 4925 4925 else if (MyModel[Un.mix].Domain = dAir) and 4926 4926 (MyModel[Un.mix].Kind <> mkSpecial_Glider) then 4927 result := Format('%s(%d)', [result, Un.Fuel]);4927 Result := Format('%s(%d)', [Result, Un.Fuel]); 4928 4928 end; 4929 4929 4930 4930 var 4931 i, uix, uixDefender, x, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count,4931 I, uix, uixDefender, X, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count, 4932 4932 mixShow, xTreasurySection, xResearchSection, JobFocus, TrueMoney, 4933 TrueResearch: integer;4933 TrueResearch: Integer; 4934 4934 Tile: Cardinal; 4935 s: string;4935 S: string; 4936 4936 unx: TUn; 4937 4937 UnitInfo: TUnitInfo; 4938 4938 JobProgressData: TJobProgressData; 4939 Prio: boolean;4939 Prio: Boolean; 4940 4940 begin 4941 4941 if not Assigned(MyRO) then Exit; … … 5014 5014 CopyMiniToPanel; 5015 5015 if ClientMode <> cEditMap then // MapBtn icons 5016 for i:= 0 to 5 do5017 if i<> 3 then5018 Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * i, PanelHeight - 26,5019 8, 8, 121 + i* 9, 61);5016 for I := 0 to 5 do 5017 if I <> 3 then 5018 Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * I, PanelHeight - 26, 5019 8, 8, 121 + I * 9, 61); 5020 5020 5021 5021 if ClientMode = cEditMap then 5022 5022 begin 5023 for i:= 0 to TrRow - 1 do5024 trix[ i] := -1;5023 for I := 0 to TrRow - 1 do 5024 trix[I] := -1; 5025 5025 Count := 0; 5026 for i:= 0 to nBrushTypes - 1 do5026 for I := 0 to nBrushTypes - 1 do 5027 5027 begin // display terrain types 5028 5028 if (Count >= TrRow * sb.Position) and (Count < TrRow * (sb.Position + 1)) 5029 5029 then 5030 5030 begin 5031 trix[Count - TrRow * sb.Position] := BrushTypes[ i];5032 x:= (Count - TrRow * sb.Position) * TrPitch;5031 trix[Count - TrRow * sb.Position] := BrushTypes[I]; 5032 X := (Count - TrRow * sb.Position) * TrPitch; 5033 5033 xSrcBase := -1; 5034 case BrushTypes[ i] of5034 case BrushTypes[I] of 5035 5035 0 .. 8: 5036 5036 begin 5037 xSrc := BrushTypes[ i];5037 xSrc := BrushTypes[I]; 5038 5038 ySrc := 0 5039 5039 end; … … 5043 5043 ySrcBase := 2; 5044 5044 xSrc := 0; 5045 ySrc := 2 * integer(BrushTypes[i]) - 155045 ySrc := 2 * Integer(BrushTypes[I]) - 15 5046 5046 end; 5047 5047 fRiver: … … 5076 5076 ySrcBase := 2; 5077 5077 xSrc := 8; 5078 ySrc := 12 + BrushTypes[ i] shr 25;5078 ySrc := 12 + BrushTypes[I] shr 25; 5079 5079 end; 5080 5080 tiIrrigation, tiFarm, tiMine, tiBase: 5081 5081 begin 5082 xSrc := BrushTypes[ i] shr 12 - 1;5082 xSrc := BrushTypes[I] shr 12 - 1; 5083 5083 ySrc := 12 5084 5084 end; … … 5103 5103 with MainMap do begin 5104 5104 if xSrcBase >= 0 then 5105 Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,5105 Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2, 5106 5106 yyt * 3, 1 + xSrcBase * (xxt * 2 + 1), 5107 5107 1 + ySrcBase * (yyt * 3 + 1)); 5108 Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,5108 Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2, 5109 5109 yyt * 3, 1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1)); 5110 if BrushTypes[ i] = BrushType then begin5111 ScreenTools.Frame(Panel.Canvas, xTroop + 2 + x,5112 yTroop + 7 - yyt div 2, xTroop + 2 * xxt + x,5110 if BrushTypes[I] = BrushType then begin 5111 ScreenTools.Frame(Panel.Canvas, xTroop + 2 + X, 5112 yTroop + 7 - yyt div 2, xTroop + 2 * xxt + X, 5113 5113 yTroop + 2 * yyt + 11, $000000, $000000); 5114 ScreenTools.Frame(Panel.Canvas, xTroop + 1 + x,5115 yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + x,5114 ScreenTools.Frame(Panel.Canvas, xTroop + 1 + X, 5115 yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + X, 5116 5116 yTroop + 2 * yyt + 10, MainTexture.ColorMark, MainTexture.ColorMark); 5117 5117 end; 5118 5118 end; 5119 5119 end; 5120 inc(Count)5120 Inc(Count) 5121 5121 end; 5122 5122 case BrushType of 5123 5123 fDesert, fPrairie, fTundra, fArctic, fSwamp, fHills, fMountains: 5124 s:= Phrases.Lookup('TERRAIN', BrushType);5124 S := Phrases.Lookup('TERRAIN', BrushType); 5125 5125 fShore: 5126 s:= Format(Phrases.Lookup('TWOTERRAINS'),5126 S := Format(Phrases.Lookup('TWOTERRAINS'), 5127 5127 [Phrases.Lookup('TERRAIN', fOcean), Phrases.Lookup('TERRAIN', 5128 5128 fShore)]); 5129 5129 fGrass: 5130 s:= Format(Phrases.Lookup('TWOTERRAINS'),5130 S := Format(Phrases.Lookup('TWOTERRAINS'), 5131 5131 [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN', 5132 5132 fGrass + 12)]); 5133 5133 fForest: 5134 s:= Format(Phrases.Lookup('TWOTERRAINS'),5134 S := Format(Phrases.Lookup('TWOTERRAINS'), 5135 5135 [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN', 5136 5136 fJungle)]); 5137 5137 fRiver: 5138 s:= Phrases.Lookup('RIVER');5138 S := Phrases.Lookup('RIVER'); 5139 5139 fDeadLands, fDeadLands or fCobalt, fDeadLands or fUranium, 5140 5140 fDeadLands or fMercury: 5141 s:= Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25);5141 S := Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25); 5142 5142 fPrefStartPos: 5143 s:= Phrases.Lookup('MAP_PREFSTART');5143 S := Phrases.Lookup('MAP_PREFSTART'); 5144 5144 fStartPos: 5145 s:= Phrases.Lookup('MAP_START');5145 S := Phrases.Lookup('MAP_START'); 5146 5146 fPoll: 5147 s:= Phrases.Lookup('POLL');5147 S := Phrases.Lookup('POLL'); 5148 5148 else // terrain improvements 5149 5149 begin 5150 5150 case BrushType of 5151 5151 fRoad: 5152 i:= 1;5152 I := 1; 5153 5153 fRR: 5154 i:= 2;5154 I := 2; 5155 5155 tiIrrigation: 5156 i:= 4;5156 I := 4; 5157 5157 tiFarm: 5158 i:= 5;5158 I := 5; 5159 5159 tiMine: 5160 i:= 7;5160 I := 7; 5161 5161 fCanal: 5162 i:= 8;5162 I := 8; 5163 5163 tiFort: 5164 i:= 10;5164 I := 10; 5165 5165 tiBase: 5166 i:= 12;5166 I := 12; 5167 5167 end; 5168 s := Phrases.Lookup('JOBRESULT', i);5168 S := Phrases.Lookup('JOBRESULT', I); 5169 5169 end 5170 5170 end; 5171 5171 LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 1, 5172 PanelHeight - 19, s);5172 PanelHeight - 19, S); 5173 5173 end 5174 5174 else if TroopLoc >= 0 then … … 5183 5183 else 5184 5184 mixShow := mix; 5185 with Tribe[ me].ModelPicture[mixShow] do5185 with Tribe[Me].ModelPicture[mixShow] do 5186 5186 begin 5187 5187 Sprite(Panel, HGr, xMidPanel + 7 + 12, yTroop + 1, 64, 48, … … 5193 5193 5194 5194 MakeBlue(Panel, xMidPanel + 7 + 12 + 10, yTroop - 13, 44, 12); 5195 s:= MovementToString(MyUn[UnFocus]);5195 S := MovementToString(MyUn[UnFocus]); 5196 5196 RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 - 5197 BiColorTextWidth(Panel.Canvas, s) div 2, yTroop - 16, s);5198 5199 s:= IntToStr(Health) + '%';5197 BiColorTextWidth(Panel.Canvas, S) div 2, yTroop - 16, S); 5198 5199 S := IntToStr(Health) + '%'; 5200 5200 LightGradient(Panel.Canvas, xMidPanel + 7 + 12 + 7, PanelHeight - 22, 5201 5201 (Health + 1) div 2, (ColorOfHealth(Health) and $FEFEFE shr 2) * 3); … … 5204 5204 div 2, PanelHeight - 22, 50 - (Health + 1) div 2, $000000); 5205 5205 RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 - 5206 BiColorTextWidth(Panel.Canvas, s) div 2, PanelHeight - 23, s);5206 BiColorTextWidth(Panel.Canvas, S) div 2, PanelHeight - 23, S); 5207 5207 5208 5208 FrameImage(Panel.Canvas, HGrSystem.Data, … … 5210 5210 121 + Exp div ExpCost * 13, 28); 5211 5211 if Job = jCity then 5212 s := Tribe[me].ModelName[-1]5212 S := Tribe[Me].ModelName[-1] 5213 5213 else 5214 s := Tribe[me].ModelName[mix];5214 S := Tribe[Me].ModelName[mix]; 5215 5215 if Home >= 0 then 5216 5216 begin 5217 5217 LoweredTextOut(Panel.Canvas, -1, MainTexture, 5218 xMidPanel + 7 + xUnitText + 18, yTroop + 5, s);5218 xMidPanel + 7 + xUnitText + 18, yTroop + 5, S); 5219 5219 LoweredTextOut(Panel.Canvas, -1, MainTexture, 5220 5220 xMidPanel + 7 + xUnitText + 18, yTroop + 21, … … 5223 5223 else 5224 5224 LoweredTextOut(Panel.Canvas, -1, MainTexture, 5225 xMidPanel + 7 + xUnitText + 18, yTroop + 13, s);5225 xMidPanel + 7 + xUnitText + 18, yTroop + 13, S); 5226 5226 end; 5227 5227 5228 5228 if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> TroopLoc) then 5229 5229 begin // divide panel 5230 if SmallScreen and not supervising then5231 x:= xTroop - 85230 if SmallScreen and not Supervising then 5231 X := xTroop - 8 5232 5232 else 5233 x:= xTroop - 152;5233 X := xTroop - 152; 5234 5234 Pen.Color := MainTexture.ColorBevelShade; 5235 MoveTo( x- 1, PanelHeight - MidPanelHeight + 2);5236 LineTo( x- 1, PanelHeight);5235 MoveTo(X - 1, PanelHeight - MidPanelHeight + 2); 5236 LineTo(X - 1, PanelHeight); 5237 5237 Pen.Color := MainTexture.ColorBevelLight; 5238 MoveTo( x, PanelHeight - MidPanelHeight + 2);5239 LineTo( x, PanelHeight);5240 end; 5241 5242 for i:= 0 to 23 do5243 trix[ i] := -1;5238 MoveTo(X, PanelHeight - MidPanelHeight + 2); 5239 LineTo(X, PanelHeight); 5240 end; 5241 5242 for I := 0 to 23 do 5243 trix[I] := -1; 5244 5244 if MyMap[TroopLoc] and fUnit <> 0 then 5245 5245 begin … … 5251 5251 LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 10, 5252 5252 PanelHeight - 24, Phrases.Lookup('PRESENT')); 5253 Server(sGetDefender, me, TroopLoc, uixDefender);5253 Server(sGetDefender, Me, TroopLoc, uixDefender); 5254 5254 Count := 0; 5255 for Prio := true downto false do5255 for Prio := True downto False do 5256 5256 for uix := 0 to MyRO.nUn - 1 do 5257 5257 if (uix = uixDefender) = Prio then … … 5264 5264 begin 5265 5265 trix[Count - TrRow * sb.Position] := uix; 5266 MakeUnitInfo( me, unx, UnitInfo);5267 x:= (Count - TrRow * sb.Position) * TrPitch;5266 MakeUnitInfo(Me, unx, UnitInfo); 5267 X := (Count - TrRow * sb.Position) * TrPitch; 5268 5268 if uix = UnFocus then 5269 5269 begin 5270 ScreenTools.Frame(Panel.Canvas, xTroop + 4 + x,5271 yTroop + 3, xTroop + 64 + x, yTroop + 47,5270 ScreenTools.Frame(Panel.Canvas, xTroop + 4 + X, 5271 yTroop + 3, xTroop + 64 + X, yTroop + 47, 5272 5272 $000000, $000000); 5273 ScreenTools.Frame(Panel.Canvas, xTroop + 3 + x,5274 yTroop + 2, xTroop + 63 + x, yTroop + 46,5273 ScreenTools.Frame(Panel.Canvas, xTroop + 3 + X, 5274 yTroop + 2, xTroop + 63 + X, yTroop + 46, 5275 5275 MainTexture.ColorMark, MainTexture.ColorMark); 5276 5276 end 5277 5277 else if (unx.Master >= 0) and (unx.Master = UnFocus) then 5278 5278 begin 5279 CFrame(Panel.Canvas, xTroop + 4 + x, yTroop + 3,5280 xTroop + 64 + x, yTroop + 47, 8, $000000);5281 CFrame(Panel.Canvas, xTroop + 3 + x, yTroop + 2,5282 xTroop + 63 + x, yTroop + 46, 8, MainTexture.ColorMark);5279 CFrame(Panel.Canvas, xTroop + 4 + X, yTroop + 3, 5280 xTroop + 64 + X, yTroop + 47, 8, $000000); 5281 CFrame(Panel.Canvas, xTroop + 3 + X, yTroop + 2, 5282 xTroop + 63 + X, yTroop + 46, 8, MainTexture.ColorMark); 5283 5283 end; 5284 5284 NoMapPanel.SetOutput(Panel); 5285 NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1, UnitInfo,5285 NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1, UnitInfo, 5286 5286 unx.Status); 5287 5287 if (ClientMode < scContact) and … … 5289 5289 (unx.Status and (usStay or usRecover or usGoto) <> 0)) 5290 5290 then 5291 Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + x,5291 Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + X, 5292 5292 yTroop + 35, 20, 20, 81, 25); 5293 5293 5294 if not supervising then5294 if not Supervising then 5295 5295 begin 5296 MakeBlue(Panel, xTroop + 2 + 10 + x,5296 MakeBlue(Panel, xTroop + 2 + 10 + X, 5297 5297 yTroop - 13, 44, 12); 5298 s:= MovementToString(unx);5298 S := MovementToString(unx); 5299 5299 RisedTextOut(Panel.Canvas, 5300 xTroop + x + 34 - BiColorTextWidth(Panel.Canvas, s)5301 div 2, yTroop - 16, s);5300 xTroop + X + 34 - BiColorTextWidth(Panel.Canvas, S) 5301 div 2, yTroop - 16, S); 5302 5302 end; 5303 5303 end; 5304 inc(Count)5304 Inc(Count) 5305 5305 end; 5306 5306 end; // for uix:=0 to MyRO.nUn-1 5307 assert(Count = TrCnt);5307 Assert(Count = TrCnt); 5308 5308 end; 5309 5309 end … … 5312 5312 LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 8, 5313 5313 PanelHeight - 24, Phrases.Lookup('PRESENT')); 5314 Server(sGetUnits, me, TroopLoc, Count);5315 for i:= 0 to Count - 1 do5316 if ( i >= TrRow * sb.Position) and (i< TrRow * (sb.Position + 1)) then5314 Server(sGetUnits, Me, TroopLoc, Count); 5315 for I := 0 to Count - 1 do 5316 if (I >= TrRow * sb.Position) and (I < TrRow * (sb.Position + 1)) then 5317 5317 begin // display enemy units 5318 trix[ i - TrRow * sb.Position] := i;5319 x := (i- TrRow * sb.Position) * TrPitch;5318 trix[I - TrRow * sb.Position] := I; 5319 X := (I - TrRow * sb.Position) * TrPitch; 5320 5320 NoMapPanel.SetOutput(Panel); 5321 NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1,5322 MyRO.EnemyUn[MyRO.nEnemyUn + i], 0);5321 NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1, 5322 MyRO.EnemyUn[MyRO.nEnemyUn + I], 0); 5323 5323 end; 5324 5324 end; 5325 5325 end; 5326 if not SmallScreen or supervising then5326 if not SmallScreen or Supervising then 5327 5327 begin // show terrain and improvements 5328 5328 with NoMapPanel do … … 5330 5330 if (UnFocus >= 0) and (MyUn[UnFocus].Job <> jNone) then begin 5331 5331 JobFocus := MyUn[UnFocus].Job; 5332 Server(sGetJobProgress, me, MyUn[UnFocus].Loc, JobProgressData);5332 Server(sGetJobProgress, Me, MyUn[UnFocus].Loc, JobProgressData); 5333 5333 MakeBlue(Panel, xTerrain - 72, 148 - 17, 144, 31); 5334 5334 PaintRelativeProgressBar(Panel.Canvas, 3, xTerrain - 68, 148 + 3, 63, 5335 5335 JobProgressData[JobFocus].Done, 5336 5336 JobProgressData[JobFocus].NextTurnPlus, 5337 JobProgressData[JobFocus].Required, true, MainTexture);5338 s:= Format('%s/%s',5337 JobProgressData[JobFocus].Required, True, MainTexture); 5338 S := Format('%s/%s', 5339 5339 [ScreenTools.MovementToString(JobProgressData[JobFocus].Done), 5340 5340 ScreenTools.MovementToString(JobProgressData[JobFocus].Required)]); 5341 RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, s);5341 RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, S); 5342 5342 Tile := MyMap[MyUn[UnFocus].Loc]; 5343 5343 if (JobFocus = jRoad) and (Tile and fRiver <> 0) then … … 5354 5354 JobFocus := nJob + 4 5355 5355 end; 5356 s:= Phrases.Lookup('JOBRESULT', JobFocus);5356 S := Phrases.Lookup('JOBRESULT', JobFocus); 5357 5357 RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, 5358 s) div 2, 148 - 19, s);5358 S) div 2, 148 - 19, S); 5359 5359 end; 5360 5360 if MyMap[TroopLoc] and (fTerrain or fSpecial) = fGrass or fSpecial1 then 5361 s:= Phrases.Lookup('TERRAIN', fGrass + 12)5361 S := Phrases.Lookup('TERRAIN', fGrass + 12) 5362 5362 else if MyMap[TroopLoc] and fDeadLands <> 0 then 5363 s:= Phrases.Lookup('TERRAIN', 3 * 12)5363 S := Phrases.Lookup('TERRAIN', 3 * 12) 5364 5364 else if (MyMap[TroopLoc] and fTerrain = fForest) and 5365 5365 IsJungle(TroopLoc div G.lx) then 5366 s:= Phrases.Lookup('TERRAIN', fJungle)5366 S := Phrases.Lookup('TERRAIN', fJungle) 5367 5367 else 5368 s:= Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain);5369 RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, s)5370 div 2, 99, s);5368 S := Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain); 5369 RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, S) 5370 div 2, 99, S); 5371 5371 end; 5372 5372 … … 5379 5379 end; 5380 5380 5381 for i:= 0 to ControlCount - 1 do5382 if Controls[ i] is TButtonB then5383 with TButtonB(Controls[ i]) do5381 for I := 0 to ControlCount - 1 do 5382 if Controls[I] is TButtonB then 5383 with TButtonB(Controls[I]) do 5384 5384 begin 5385 5385 if Visible then … … 5397 5397 if ClientMode <> cEditMap then 5398 5398 begin 5399 for i:= 0 to ControlCount - 1 do5400 if Controls[ i] is TButtonC then5401 with TButtonC(Controls[ i]) do5399 for I := 0 to ControlCount - 1 do 5400 if Controls[I] is TButtonC then 5401 with TButtonC(Controls[I]) do 5402 5402 begin 5403 5403 Dump(Panel, HGrSystem, Left, Top - self.ClientHeight + PanelHeight, … … 5439 5439 TrueMoney := MyRO.Money; 5440 5440 TrueResearch := MyRO.Research; 5441 if supervising then5441 if Supervising then 5442 5442 begin // normalize values from after-turn state 5443 dec(TrueMoney, TaxSum);5443 Dec(TrueMoney, TaxSum); 5444 5444 if TrueMoney < 0 then 5445 5445 TrueMoney := 0; // shouldn't happen 5446 dec(TrueResearch, ScienceSum);5446 Dec(TrueResearch, ScienceSum); 5447 5447 if TrueResearch < 0 then 5448 5448 TrueResearch := 0; // shouldn't happen … … 5452 5452 ImageOp_BCC(TopBar, Templates.Data, Point(xTreasurySection + 8, 1), TreasuryIcon.BoundsRect, 5453 5453 $40A040, $4030C0); 5454 s:= IntToStr(TrueMoney);5454 S := IntToStr(TrueMoney); 5455 5455 LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48, 0, 5456 s+ '%c');5456 S + '%c'); 5457 5457 if MyRO.Government <> gAnarchy then 5458 5458 begin … … 5460 5460 $0000C0, $0080C0); 5461 5461 if TaxSum >= 0 then 5462 s:= Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum])5462 S := Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum]) 5463 5463 else 5464 s:= Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]);5464 S := Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]); 5465 5465 LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48 + 5466 15, 18, s);5466 15, 18, S); 5467 5467 end; 5468 5468 … … 5484 5484 else 5485 5485 CostFactor := 2; 5486 Server(sGetTechCost, me, 0, i);5486 Server(sGetTechCost, Me, 0, I); 5487 5487 CostFactor := CostFactor * 22; // length of progress bar 5488 5488 PaintRelativeProgressBar(TopBar.Canvas, 2, xResearchSection + 48 + 1, 26, 5489 CostFactor, TrueResearch, ScienceSum, i, true, MainTexture);5489 CostFactor, TrueResearch, ScienceSum, I, True, MainTexture); 5490 5490 5491 5491 if MyRO.ResearchTech < 0 then 5492 s:= Phrases.Lookup('SCIENCE')5492 S := Phrases.Lookup('SCIENCE') 5493 5493 else if MyRO.ResearchTech = adMilitary then 5494 s:= Phrases.Lookup('INITUNIT')5494 S := Phrases.Lookup('INITUNIT') 5495 5495 else 5496 5496 begin 5497 s:= Phrases.Lookup('ADVANCES', MyRO.ResearchTech);5497 S := Phrases.Lookup('ADVANCES', MyRO.ResearchTech); 5498 5498 if MyRO.ResearchTech in FutureTech then 5499 5499 if MyRO.Tech[MyRO.ResearchTech] >= 1 then 5500 s := s+ ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1)5500 S := S + ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1) 5501 5501 else 5502 s := s+ ' 1';5502 S := S + ' 1'; 5503 5503 end; 5504 5504 if ScienceSum > 0 then 5505 5505 begin 5506 5506 { j:=(i-MyRO.Research-1) div ScienceSum +1; 5507 if j<1 then j:=1;5508 if j>1 then5509 s:=Format(Phrases.Lookup('TECHWAIT'),[s,j]); }5507 if J<1 then J:=1; 5508 if J>1 then 5509 S:=Format(Phrases.Lookup('TECHWAIT'),[S,J]); } 5510 5510 LoweredTextOut(TopBar.Canvas, -1, MainTexture, 5511 xResearchSection + 48, 0, s);5511 xResearchSection + 48, 0, S); 5512 5512 end 5513 5513 else 5514 5514 LoweredTextOut(TopBar.Canvas, -1, MainTexture, 5515 xResearchSection + 48, 0, s);5515 xResearchSection + 48, 0, S); 5516 5516 end 5517 5517 else … … 5521 5521 ImageOp_BCC(TopBar, Templates.Data, Point(xResearchSection + 48 + CostFactor + 11, 5522 5522 22), ChangeIcon.BoundsRect, $0000C0, $0080C0); 5523 s:= Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]);5523 S := Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]); 5524 5524 LoweredTextOut(TopBar.Canvas, -1, MainTexture, xResearchSection + 48 + 5525 CostFactor + 26, 18, s);5525 CostFactor + 26, 18, S); 5526 5526 end; 5527 5527 end; … … 5529 5529 begin 5530 5530 TopBar.Canvas.Font.Assign(UniFont[ftCaption]); 5531 s:= TurnToString(MyRO.Turn);5531 S := TurnToString(MyRO.Turn); 5532 5532 RisedTextOut(TopBar.Canvas, 5533 40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, s))5534 div 2, 6, s);5533 40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, S)) 5534 div 2, 6, S); 5535 5535 TopBar.Canvas.Font.Assign(UniFont[ftNormal]); 5536 5536 end; … … 5540 5540 procedure TMainScreen.FocusNextUnit(Dir: Integer); 5541 5541 var 5542 i, uix, NewFocus: Integer;5542 I, uix, NewFocus: Integer; 5543 5543 begin 5544 5544 if ClientMode >= scContact then … … 5547 5547 PaintDestination; 5548 5548 NewFocus := -1; 5549 for i:= 1 to MyRO.nUn do begin5550 uix := (UnFocus + i* Dir + MyRO.nUn) mod MyRO.nUn;5549 for I := 1 to MyRO.nUn do begin 5550 uix := (UnFocus + I * Dir + MyRO.nUn) mod MyRO.nUn; 5551 5551 if (MyUn[uix].Loc >= 0) and (MyUn[uix].Status and usStay = 0) then begin 5552 5552 NewFocus := uix; … … 5561 5561 end; 5562 5562 5563 procedure TMainScreen.FocusOnLoc(Loc: integer; Options: integer = 0);5563 procedure TMainScreen.FocusOnLoc(Loc: Integer; Options: Integer = 0); 5564 5564 var 5565 dx: integer;5566 Outside, Changed: boolean;5565 dx: Integer; 5566 Outside, Changed: Boolean; 5567 5567 begin 5568 5568 with MainMap do begin … … 5572 5572 (Loc div G.lx >= yw + (MapHeight - 1) div yyt - 2)); 5573 5573 end; 5574 Changed := true;5574 Changed := True; 5575 5575 if Outside then begin 5576 5576 Centre(Loc); … … 5580 5580 PaintAllMaps 5581 5581 else 5582 Changed := false;5582 Changed := False; 5583 5583 if Options and flRepaintPanel <> 0 then 5584 5584 PanelPaint; … … 5590 5590 var 5591 5591 Dist, TestDist: Single; 5592 i, uix, NewFocus: Integer;5592 I, uix, NewFocus: Integer; 5593 5593 GotoOnly: Boolean; 5594 5594 begin … … 5600 5600 for GotoOnly := GoOnPhase downto False do begin 5601 5601 NewFocus := -1; 5602 for i:= 1 to MyRO.nUn do begin5603 uix := (UnFocus + i) mod MyRO.nUn;5602 for I := 1 to MyRO.nUn do begin 5603 uix := (UnFocus + I) mod MyRO.nUn; 5604 5604 if (MyUn[uix].Loc >= 0) and (MyUn[uix].Job = jNone) and 5605 5605 (MyUn[uix].Status and (usStay or usRecover or usWaiting) = usWaiting) … … 5640 5640 end; 5641 5641 5642 procedure TMainScreen.Scroll(dx, dy: integer);5642 procedure TMainScreen.Scroll(dx, dy: Integer); 5643 5643 begin 5644 5644 xw := (xw + G.lx + dx) mod G.lx; … … 5664 5664 procedure TMainScreen.Timer1Timer(Sender: TObject); 5665 5665 var 5666 dx, dy, ScrollSpeed: integer;5667 begin 5668 if idle and (me >= 0) and (GameMode <> cMovie) then5666 dx, dy, ScrollSpeed: Integer; 5667 begin 5668 if Idle and (Me >= 0) and (GameMode <> cMovie) then 5669 5669 if (fsModal in Screen.ActiveForm.FormState) or 5670 5670 (Screen.ActiveForm is TBufferedDrawDlg) and … … 5674 5674 if not BlinkON then 5675 5675 begin 5676 BlinkON := true;5676 BlinkON := True; 5677 5677 if UnFocus >= 0 then 5678 5678 PaintLocTemp(MyUn[UnFocus].Loc) 5679 else if TurnComplete and not supervising then5679 else if TurnComplete and not Supervising then 5680 5680 EOT.SetButtonIndexFast(eotBlinkOn); 5681 5681 end; … … 5689 5689 dx := 0; 5690 5690 dy := 0; 5691 if Mouse.CursorPos. y< Screen.height - PanelHeight then5692 if Mouse.CursorPos. x= 0 then5691 if Mouse.CursorPos.Y < Screen.height - PanelHeight then 5692 if Mouse.CursorPos.X = 0 then 5693 5693 dx := -ScrollSpeed // scroll left 5694 else if Mouse.CursorPos. x= Screen.width - 1 then5694 else if Mouse.CursorPos.X = Screen.width - 1 then 5695 5695 dx := ScrollSpeed; // scroll right 5696 if Mouse.CursorPos. y= 0 then5696 if Mouse.CursorPos.Y = 0 then 5697 5697 dy := -ScrollSpeed // scroll up 5698 else if (Mouse.CursorPos. y= Screen.height - 1) and5699 (Mouse.CursorPos. x>= TerrainBtn.Left + TerrainBtn.width) and5700 (Mouse.CursorPos. x< xRightPanel + 10 - 8) then5698 else if (Mouse.CursorPos.Y = Screen.height - 1) and 5699 (Mouse.CursorPos.X >= TerrainBtn.Left + TerrainBtn.width) and 5700 (Mouse.CursorPos.X < xRightPanel + 10 - 8) then 5701 5701 dy := ScrollSpeed; // scroll down 5702 5702 if (dx <> 0) or (dy <> 0) then … … 5711 5711 BlinkTime := (BlinkTime + 1) mod (BlinkOnTime + BlinkOffTime); 5712 5712 BlinkON := BlinkTime >= BlinkOffTime; 5713 DestinationMarkON := true;5713 DestinationMarkON := True; 5714 5714 if UnFocus >= 0 then 5715 5715 begin … … 5722 5722 end; 5723 5723 end 5724 else if TurnComplete and not supervising then5724 else if TurnComplete and not Supervising then 5725 5725 begin 5726 5726 if BlinkTime = 0 then … … 5732 5732 end; 5733 5733 5734 procedure TMainScreen.SetMapPos(Loc: integer; MapPos: TPoint);5734 procedure TMainScreen.SetMapPos(Loc: Integer; MapPos: TPoint); 5735 5735 begin 5736 5736 with MainMap do begin … … 5750 5750 end; 5751 5751 5752 procedure TMainScreen.Centre(Loc: integer);5752 procedure TMainScreen.Centre(Loc: Integer); 5753 5753 begin 5754 5754 SetMapPos(Loc, Point(MapWidth div 2, MapHeight div 2)); 5755 5755 end; 5756 5756 5757 function TMainScreen.ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;5758 ShowEvent: integer = 0): boolean;5759 begin 5760 result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0;5761 if result then5757 function TMainScreen.ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False; 5758 ShowEvent: Integer = 0): Boolean; 5759 begin 5760 Result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0; 5761 if Result then 5762 5762 with CityDlg do 5763 5763 begin … … 5785 5785 end; 5786 5786 5787 function TMainScreen.LocationOfScreenPixel( x, y: integer): Integer;5787 function TMainScreen.LocationOfScreenPixel(X, Y: Integer): Integer; 5788 5788 var 5789 qx, qy: integer;5789 qx, qy: Integer; 5790 5790 begin 5791 5791 with MainMap do begin 5792 qx := ( x * (yyt * 2) + y* (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1;5793 qy := ( y * (xxt * 2) - x* (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)5792 qx := (X * (yyt * 2) + Y * (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1; 5793 qy := (Y * (xxt * 2) - X * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt) 5794 5794 div (xxt * yyt * 4) - 999; 5795 5795 Result := (xw + (qx - qy + 2048) div 2 - 1024 + G.lx) mod G.lx + G.lx * … … 5805 5805 5806 5806 procedure TMainScreen.MapBoxMouseDown(Sender: TObject; Button: TMouseButton; 5807 Shift: TShiftState; x, y: integer);5807 Shift: TShiftState; X, Y: Integer); 5808 5808 var 5809 i, uix, emix, p1, dx, dy, MouseLoc: integer;5809 I, uix, emix, p1, dx, dy, MouseLoc: Integer; 5810 5810 EditTileData: TEditTileData; 5811 m, m2: TMenuItem;5811 M, m2: TMenuItem; 5812 5812 MoveAdviceData: TMoveAdviceData; 5813 DoCenter: boolean;5813 DoCenter: Boolean; 5814 5814 begin 5815 5815 if GameMode = cMovie then 5816 exit;5816 Exit; 5817 5817 5818 5818 if CityDlg.Visible then … … 5820 5820 if UnitStatDlg.Visible then 5821 5821 UnitStatDlg.Close; 5822 MouseLoc := LocationOfScreenPixel( x, y);5822 MouseLoc := LocationOfScreenPixel(X, Y); 5823 5823 if (MouseLoc < 0) or (MouseLoc >= G.lx * G.ly) then 5824 exit;5824 Exit; 5825 5825 if (Button = mbLeft) and not(ssShift in Shift) then 5826 5826 begin 5827 DoCenter := true;5827 DoCenter := True; 5828 5828 if ClientMode = cEditMap then 5829 5829 begin 5830 DoCenter := false;5830 DoCenter := False; 5831 5831 EditTileData.Loc := MouseLoc; 5832 5832 if ssCtrl in Shift then // toggle special resource … … 5866 5866 else 5867 5867 EditTileData.NewTile := MyMap[MouseLoc] xor BrushType; 5868 Server(sEditTile, me, 0, EditTileData);5869 Edited := true;5868 Server(sEditTile, Me, 0, EditTileData); 5869 Edited := True; 5870 5870 BrushLoc := MouseLoc; 5871 5871 PaintLoc(MouseLoc, 2); … … 5893 5893 begin 5894 5894 ZoomToCity(MouseLoc); 5895 DoCenter := false;5895 DoCenter := False; 5896 5896 end 5897 5897 else 5898 5898 begin 5899 5899 UnitStatDlg.ShowNewContent_EnemyCity(wmPersistent, MouseLoc); 5900 DoCenter := false;5900 DoCenter := False; 5901 5901 end; 5902 5902 end … … 5904 5904 if MyMap[MouseLoc] and fOwned <> 0 then 5905 5905 begin 5906 DoCenter := false;5907 if not supervising and (ClientMode < scContact) then5906 DoCenter := False; 5907 if not Supervising and (ClientMode < scContact) then 5908 5908 begin // not in negotiation mode 5909 5909 if (UnFocus >= 0) and (MyUn[UnFocus].Loc = MouseLoc) then 5910 5910 begin // rotate 5911 5911 uix := (UnFocus + 1) mod MyRO.nUn; 5912 i:= MyRO.nUn - 1;5913 while i> 0 do5912 I := MyRO.nUn - 1; 5913 while I > 0 do 5914 5914 begin 5915 5915 if (MyUn[uix].Loc = MouseLoc) and (MyUn[uix].Job = jNone) and … … 5917 5917 usWaiting) = usWaiting) then 5918 5918 Break; 5919 dec(i);5919 Dec(I); 5920 5920 uix := (uix + 1) mod MyRO.nUn; 5921 5921 end; 5922 if i= 0 then5922 if I = 0 then 5923 5923 uix := UnFocus; 5924 5924 end 5925 5925 else 5926 Server(sGetDefender, me, MouseLoc, uix);5926 Server(sGetDefender, Me, MouseLoc, uix); 5927 5927 if uix <> UnFocus then 5928 5928 SetUnFocus(uix); 5929 TurnComplete := false;5929 TurnComplete := False; 5930 5930 EOT.ButtonIndex := eotGray; 5931 5931 end; … … 5935 5935 else if (MyMap[MouseLoc] and fSpiedOut <> 0) and not(ssCtrl in Shift) then 5936 5936 begin 5937 DoCenter := false;5937 DoCenter := False; 5938 5938 SetTroopLoc(MouseLoc); 5939 5939 PanelPaint; … … 5941 5941 else 5942 5942 begin 5943 DoCenter := false;5943 DoCenter := False; 5944 5944 UnitStatDlg.ShowNewContent_EnemyLoc(wmPersistent, MouseLoc); 5945 5945 end; … … 5953 5953 not(ssShift in Shift) then 5954 5954 begin 5955 if supervising then5955 if Supervising then 5956 5956 begin 5957 5957 EditLoc := MouseLoc; 5958 Server(sGetModels, me, 0, nil^);5958 Server(sGetModels, Me, 0, nil^); 5959 5959 EmptyMenu(mCreateUnit); 5960 5960 for p1 := 0 to nPl - 1 do 5961 5961 if 1 shl p1 and MyRO.Alive <> 0 then 5962 5962 begin 5963 m:= TMenuItem.Create(mCreateUnit);5964 m.Caption := Tribe[p1].TPhrase('SHORTNAME');5963 M := TMenuItem.Create(mCreateUnit); 5964 M.Caption := Tribe[p1].TPhrase('SHORTNAME'); 5965 5965 for emix := MyRO.nEnemyModel - 1 downto 0 do 5966 5966 if (MyRO.EnemyModel[emix].Owner = p1) and 5967 (Server(sCreateUnit - sExecute + p1 shl 4, me,5967 (Server(sCreateUnit - sExecute + p1 shl 4, Me, 5968 5968 MyRO.EnemyModel[emix].mix, MouseLoc) >= rExecuted) then 5969 5969 begin 5970 5970 if not Assigned(Tribe[p1].ModelPicture[MyRO.EnemyModel[emix].mix].HGr) then 5971 5971 InitEnemyModel(emix); 5972 m2 := TMenuItem.Create( m);5972 m2 := TMenuItem.Create(M); 5973 5973 m2.Caption := Tribe[p1].ModelName[MyRO.EnemyModel[emix].mix]; 5974 5974 m2.Tag := p1 shl 16 + MyRO.EnemyModel[emix].mix; 5975 5975 m2.OnClick := CreateUnitClick; 5976 m.Add(m2);5976 M.Add(m2); 5977 5977 end; 5978 m.Visible := m.Count > 0;5979 mCreateUnit.Add( m);5978 M.Visible := M.Count > 0; 5979 mCreateUnit.Add(M); 5980 5980 end; 5981 5981 if FullScreen then 5982 EditPopup.Popup(Left + x, Top + y)5982 EditPopup.Popup(Left + X, Top + Y) 5983 5983 else 5984 EditPopup.Popup(Left + x+ 4,5985 Top + y+ GetSystemMetrics(SM_CYCAPTION) + 4);5984 EditPopup.Popup(Left + X + 4, 5985 Top + Y + GetSystemMetrics(SM_CYCAPTION) + 4); 5986 5986 end 5987 5987 else if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> MouseLoc) then … … 5994 5994 if abs(dx) + abs(dy) < 3 then 5995 5995 begin 5996 DestinationMarkON := false;5996 DestinationMarkON := False; 5997 5997 PaintDestination; 5998 5998 Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance) … … 6007 6007 with MyUn[UnFocus], BattleDlg.Forecast do 6008 6008 begin 6009 pAtt := me;6009 pAtt := Me; 6010 6010 mixAtt := mix; 6011 6011 HealthAtt := Health; … … 6014 6014 end; 6015 6015 BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement; 6016 if (Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast)6016 if (Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast) 6017 6017 >= rExecuted) and (BattleDlg.Forecast.EndHealthAtt <= 0) then 6018 6018 begin 6019 6019 BattleDlg.uix := UnFocus; 6020 6020 BattleDlg.ToLoc := MouseLoc; 6021 BattleDlg.IsSuicideQuery := true;6021 BattleDlg.IsSuicideQuery := True; 6022 6022 BattleDlg.ShowModal; 6023 6023 if BattleDlg.ModalResult <> mrOK then 6024 exit;6024 Exit; 6025 6025 end; 6026 6026 end; 6027 DestinationMarkON := false;6027 DestinationMarkON := False; 6028 6028 PaintDestination; 6029 6029 Status := Status and not(usStay or usRecover or usEnhance) or 6030 6030 usWaiting; 6031 MoveToLoc(MouseLoc, false); { goto }6031 MoveToLoc(MouseLoc, False); { goto } 6032 6032 end; 6033 6033 end; … … 6036 6036 (MyModel[MyUn[UnFocus].mix].Kind in [mkSettler, mkSlaves]) then 6037 6037 begin 6038 DestinationMarkON := false;6038 DestinationMarkON := False; 6039 6039 PaintDestination; 6040 6040 MyUn[UnFocus].Status := MyUn[UnFocus].Status and … … 6042 6042 uix := UnFocus; 6043 6043 if MouseLoc <> MyUn[uix].Loc then 6044 MoveToLoc(MouseLoc, true); { goto }6044 MoveToLoc(MouseLoc, True); { goto } 6045 6045 if (UnFocus = uix) and (MyUn[uix].Loc = MouseLoc) then 6046 6046 mEnhance.Click; … … 6055 6055 with MyUn[UnFocus], BattleDlg.Forecast do 6056 6056 begin 6057 pAtt := me;6057 pAtt := Me; 6058 6058 mixAtt := mix; 6059 6059 HealthAtt := Health; … … 6062 6062 end; 6063 6063 BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement; 6064 if Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast) >= rExecuted6064 if Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast) >= rExecuted 6065 6065 then 6066 6066 begin 6067 6067 BattleDlg.uix := UnFocus; 6068 6068 BattleDlg.ToLoc := MouseLoc; 6069 BattleDlg.Left := x- BattleDlg.width div 2;6069 BattleDlg.Left := X - BattleDlg.width div 2; 6070 6070 if BattleDlg.Left < 0 then 6071 6071 BattleDlg.Left := 0 6072 6072 else if BattleDlg.Left + BattleDlg.width > Screen.width then 6073 6073 BattleDlg.Left := Screen.width - BattleDlg.width; 6074 BattleDlg.Top := y- BattleDlg.height div 2;6074 BattleDlg.Top := Y - BattleDlg.height div 2; 6075 6075 if BattleDlg.Top < 0 then 6076 6076 BattleDlg.Top := 0 6077 6077 else if BattleDlg.Top + BattleDlg.height > Screen.height then 6078 6078 BattleDlg.Top := Screen.height - BattleDlg.height; 6079 BattleDlg.IsSuicideQuery := false;6079 BattleDlg.IsSuicideQuery := False; 6080 6080 BattleDlg.Show; 6081 6081 end; … … 6083 6083 end; 6084 6084 6085 function TMainScreen.MoveUnit(dx, dy: integer; Options: integer): integer;6085 function TMainScreen.MoveUnit(dx, dy: Integer; Options: Integer): Integer; 6086 6086 // move focused unit to adjacent tile 6087 6087 var 6088 i, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1,6089 NewTiles, cixChanged: integer;6088 I, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1, 6089 NewTiles, cixChanged: Integer; 6090 6090 OldToTile: Cardinal; 6091 6091 CityCaptured, IsAttack, OldUnrest, NewUnrest, NeedEcoUpdate, NeedRepaintPanel, 6092 ToTransport, ToShip: boolean;6092 ToTransport, ToShip: Boolean; 6093 6093 PlaneReturnData: TPlaneReturnData; 6094 6094 QueryItem: string; 6095 6095 begin 6096 result := eInvalid;6096 Result := eInvalid; 6097 6097 UnFocus0 := UnFocus; 6098 6098 FromLoc := MyUn[UnFocus].Loc; … … 6100 6100 if (ToLoc < 0) or (ToLoc >= G.lx * G.ly) then 6101 6101 begin 6102 result := eInvalid;6103 exit;6102 Result := eInvalid; 6103 Exit; 6104 6104 end; 6105 6105 if MyMap[ToLoc] and fStealthUnit <> 0 then 6106 6106 begin 6107 6107 SoundMessage(Phrases.Lookup('ATTACKSTEALTH'), ''); 6108 exit;6108 Exit; 6109 6109 end; 6110 6110 if MyMap[ToLoc] and fHiddenUnit <> 0 then 6111 6111 begin 6112 6112 SoundMessage(Phrases.Lookup('ATTACKSUB'), ''); 6113 exit;6113 Exit; 6114 6114 end; 6115 6115 … … 6121 6121 begin 6122 6122 SoundMessage(Phrases.Lookup('NOATTACKER'), ''); 6123 exit;6123 Exit; 6124 6124 end; 6125 6125 euix := MyRO.nEnemyUn - 1; 6126 6126 while (euix >= 0) and (MyRO.EnemyUn[euix].Loc <> ToLoc) do 6127 dec(euix);6127 Dec(euix); 6128 6128 end; 6129 6129 6130 6130 DirCode := dx and 7 shl 4 + dy and 7 shl 7; 6131 result := Server(sMoveUnit - sExecute + DirCode, me, UnFocus, nil^);6132 if ( result < rExecuted) and (MyUn[UnFocus].Job > jNone) then6133 Server(sStartJob + jNone shl 4, me, UnFocus, nil^);6134 if ( result < rExecuted) and (result <> eNoTime_Move) then6135 begin 6136 case result of6131 Result := Server(sMoveUnit - sExecute + DirCode, Me, UnFocus, nil^); 6132 if (Result < rExecuted) and (MyUn[UnFocus].Job > jNone) then 6133 Server(sStartJob + jNone shl 4, Me, UnFocus, nil^); 6134 if (Result < rExecuted) and (Result <> eNoTime_Move) then 6135 begin 6136 case Result of 6137 6137 eNoTime_Load: 6138 6138 if MyModel[MyUn[UnFocus].mix].Domain = dAir then … … 6170 6170 (MyMap[ToLoc] and (fUnit or fOwned) = fUnit or fOwned) then 6171 6171 begin // false load attempt 6172 ToShip := false;6173 ToTransport := false;6172 ToShip := False; 6173 ToTransport := False; 6174 6174 for uix := 0 to MyRO.nUn - 1 do 6175 6175 if (MyUn[uix].Loc = ToLoc) and 6176 6176 (MyModel[MyUn[uix].mix].Domain = dSea) then 6177 6177 begin 6178 ToShip := true;6178 ToShip := True; 6179 6179 if MyModel[MyUn[uix].mix].Cap[mcSeaTrans] > 0 then 6180 ToTransport := true;6180 ToTransport := True; 6181 6181 end; 6182 6182 if ToTransport then … … 6193 6193 Play('NOMOVE_DEFAULT'); 6194 6194 end; 6195 exit;6196 end; 6197 6198 if (( result = eWon) or (result = eLost) or (result = eBloody)) and6195 Exit; 6196 end; 6197 6198 if ((Result = eWon) or (Result = eLost) or (Result = eBloody)) and 6199 6199 (MyUn[UnFocus].Movement < 100) and 6200 6200 (MyModel[MyUn[UnFocus].mix].Cap[mcWill] = 0) then … … 6203 6203 [MyUn[UnFocus].Movement]), 'NOMOVE_TIME') <> mrOK then 6204 6204 begin 6205 result := eInvalid;6206 exit;6205 Result := eInvalid; 6206 Exit; 6207 6207 end; 6208 6208 Update; // remove message box from screen 6209 6209 end; 6210 6210 6211 OldUnrest := false;6212 NewUnrest := false;6213 if ( result >= rExecuted) and (result and rUnitRemoved = 0) and6211 OldUnrest := False; 6212 NewUnrest := False; 6213 if (Result >= rExecuted) and (Result and rUnitRemoved = 0) and 6214 6214 (MyMap[ToLoc] and (fUnit or fOwned) <> fUnit) then 6215 6215 begin … … 6221 6221 begin 6222 6222 QueryItem := 'UNREST_NOTOWN'; 6223 p1 := me;6223 p1 := Me; 6224 6224 end 6225 6225 else … … 6238 6238 if ModalResult <> mrOK then 6239 6239 begin 6240 result := eInvalid;6241 exit;6240 Result := eInvalid; 6241 Exit; 6242 6242 end; 6243 6243 end; … … 6246 6246 end; 6247 6247 6248 if ( result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and6248 if (Result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and 6249 6249 (MyUn[UnFocus].Status and usToldNoReturn = 0) then 6250 6250 begin // can plane return? … … 6266 6266 PlaneReturnData.Movement := MyUn[UnFocus].Movement - 150; 6267 6267 end; 6268 if Server(sGetPlaneReturn, me, UnFocus, PlaneReturnData) = eNoWay then6268 if Server(sGetPlaneReturn, Me, UnFocus, PlaneReturnData) = eNoWay then 6269 6269 begin 6270 6270 if MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_Glider then … … 6275 6275 <> mrOK then 6276 6276 begin 6277 result := eInvalid;6278 exit;6277 Result := eInvalid; 6278 Exit; 6279 6279 end; 6280 6280 Update; // remove message box from screen … … 6283 6283 end; 6284 6284 6285 if result = eMissionDone then6285 if Result = eMissionDone then 6286 6286 begin 6287 6287 ModalSelectDlg.ShowNewContent(wmModal, kMission); 6288 6288 Update; // dialog still on screen 6289 Mission := ModalSelectDlg. result;6289 Mission := ModalSelectDlg.Result; 6290 6290 if Mission < 0 then 6291 exit;6292 Server(sSetSpyMission + Mission shl 4, me, 0, nil^);6293 end; 6294 6295 CityCaptured := false;6296 if result = eNoTime_Move then6291 Exit; 6292 Server(sSetSpyMission + Mission shl 4, Me, 0, nil^); 6293 end; 6294 6295 CityCaptured := False; 6296 if Result = eNoTime_Move then 6297 6297 Play('NOMOVE_TIME') 6298 6298 else 6299 6299 begin 6300 NeedEcoUpdate := false;6301 DestinationMarkON := false;6300 NeedEcoUpdate := False; 6301 DestinationMarkON := False; 6302 6302 PaintDestination; 6303 if result and rUnitRemoved <> 0 then6303 if Result and rUnitRemoved <> 0 then 6304 6304 CityOptimizer_BeforeRemoveUnit(UnFocus); 6305 IsAttack := ( result = eBombarded) or (result <> eMissionDone) and6305 IsAttack := (Result = eBombarded) or (Result <> eMissionDone) and 6306 6306 (MyMap[ToLoc] and (fUnit or fOwned) = fUnit); 6307 6307 if not IsAttack then … … 6309 6309 cix := MyRO.nCity - 1; { look for own city at dest location } 6310 6310 while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do 6311 dec(cix);6312 if ( result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0)6311 Dec(cix); 6312 if (Result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0) 6313 6313 then 6314 CityCaptured := true;6315 result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);6316 case result of6314 CityCaptured := True; 6315 Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^); 6316 case Result of 6317 6317 eHiddenUnit: 6318 6318 begin … … 6332 6332 rExecuted .. maxint: 6333 6333 begin 6334 if result and rUnitRemoved <> 0 then6334 if Result and rUnitRemoved <> 0 then 6335 6335 UnFocus := -1 // unit died 6336 6336 else 6337 6337 begin 6338 assert(UnFocus >= 0);6338 Assert(UnFocus >= 0); 6339 6339 MyUn[UnFocus].Status := MyUn[UnFocus].Status and 6340 6340 not(usStay or usRecover); … … 6346 6346 begin // borders have moved, unrest might have changed in any city 6347 6347 CityOptimizer_BeginOfTurn; 6348 NeedEcoUpdate := true;6348 NeedEcoUpdate := True; 6349 6349 end 6350 6350 else … … 6356 6356 if MyUn[uix].Master = UnFocus then 6357 6357 CityOptimizer_CityChange(MyUn[uix].Home); 6358 NeedEcoUpdate := true;6358 NeedEcoUpdate := True; 6359 6359 end; 6360 6360 if (MyRO.Government = gDespotism) and … … 6366 6366 while (cixChanged >= 0) and 6367 6367 (MyCity[cixChanged].Loc <> FromLoc) do 6368 dec(cixChanged);6369 assert(cixChanged >= 0);6368 Dec(cixChanged); 6369 Assert(cixChanged >= 0); 6370 6370 if cixChanged >= 0 then 6371 6371 begin 6372 6372 CityOptimizer_CityChange(cixChanged); 6373 NeedEcoUpdate := true;6373 NeedEcoUpdate := True; 6374 6374 end; 6375 6375 end; … … 6379 6379 while (cixChanged >= 0) and 6380 6380 (MyCity[cixChanged].Loc <> ToLoc) do 6381 dec(cixChanged);6382 assert(cixChanged >= 0);6381 Dec(cixChanged); 6382 Assert(cixChanged >= 0); 6383 6383 if cixChanged >= 0 then 6384 6384 begin 6385 6385 CityOptimizer_CityChange(cixChanged); 6386 NeedEcoUpdate := true;6386 NeedEcoUpdate := True; 6387 6387 end; 6388 6388 end; … … 6392 6392 end; 6393 6393 else 6394 assert(false);6394 Assert(False); 6395 6395 end; 6396 6396 SetTroopLoc(ToLoc); … … 6398 6398 else 6399 6399 begin { enemy unit -- attack } 6400 if result = eBombarded then6400 if Result = eBombarded then 6401 6401 Defender := MyRO.Territory[ToLoc] 6402 6402 else … … 6405 6405 if SimpleQuery(mkYesNo,Phrases.Lookup('FRCANCELQUERY_CEASEFIRE'), 6406 6406 'MSG_DEFAULT')<>mrOK then 6407 exit; }6408 if (Options and muNoSuicideCheck = 0) and ( result and rUnitRemoved <> 0)6409 and ( result <> eMissionDone) then6407 Exit; } 6408 if (Options and muNoSuicideCheck = 0) and (Result and rUnitRemoved <> 0) 6409 and (Result <> eMissionDone) then 6410 6410 begin // suicide query 6411 6411 with MyUn[UnFocus], BattleDlg.Forecast do 6412 6412 begin 6413 pAtt := me;6413 pAtt := Me; 6414 6414 mixAtt := mix; 6415 6415 HealthAtt := Health; … … 6418 6418 end; 6419 6419 BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement; 6420 Server(sGetBattleForecastEx, me, ToLoc, BattleDlg.Forecast);6420 Server(sGetBattleForecastEx, Me, ToLoc, BattleDlg.Forecast); 6421 6421 BattleDlg.uix := UnFocus; 6422 6422 BattleDlg.ToLoc := ToLoc; 6423 BattleDlg.IsSuicideQuery := true;6423 BattleDlg.IsSuicideQuery := True; 6424 6424 BattleDlg.ShowModal; 6425 6425 if BattleDlg.ModalResult <> mrOK then 6426 exit;6426 Exit; 6427 6427 end; 6428 6428 6429 6429 cixChanged := -1; 6430 if ( result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and6430 if (Result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and 6431 6431 (MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_TownGuard) and 6432 6432 (MyMap[FromLoc] and fCity <> 0) then … … 6434 6434 cixChanged := MyRO.nCity - 1; 6435 6435 while (cixChanged >= 0) and (MyCity[cixChanged].Loc <> FromLoc) do 6436 dec(cixChanged);6437 assert(cixChanged >= 0);6438 end; 6439 6440 for i:= 0 to MyRO.nEnemyModel - 1 do6441 LostArmy[ i] := MyRO.EnemyModel[i].Lost;6436 Dec(cixChanged); 6437 Assert(cixChanged >= 0); 6438 end; 6439 6440 for I := 0 to MyRO.nEnemyModel - 1 do 6441 LostArmy[I] := MyRO.EnemyModel[I].Lost; 6442 6442 OldToTile := MyMap[ToLoc]; 6443 result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);6443 Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^); 6444 6444 nLostArmy := 0; 6445 for i:= 0 to MyRO.nEnemyModel - 1 do6446 begin 6447 LostArmy[ i] := MyRO.EnemyModel[i].Lost - LostArmy[i];6448 inc(nLostArmy, LostArmy[i]);6449 end; 6450 if result and rUnitRemoved <> 0 then6445 for I := 0 to MyRO.nEnemyModel - 1 do 6446 begin 6447 LostArmy[I] := MyRO.EnemyModel[I].Lost - LostArmy[I]; 6448 Inc(nLostArmy, LostArmy[I]); 6449 end; 6450 if Result and rUnitRemoved <> 0 then 6451 6451 begin 6452 6452 UnFocus := -1; … … 6457 6457 begin // city was destroyed, borders have moved, unrest might have changed in any city 6458 6458 CityOptimizer_BeginOfTurn; 6459 NeedEcoUpdate := true;6459 NeedEcoUpdate := True; 6460 6460 end 6461 6461 else … … 6464 6464 begin 6465 6465 CityOptimizer_CityChange(cixChanged); 6466 NeedEcoUpdate := true;6466 NeedEcoUpdate := True; 6467 6467 end; 6468 if ( result = eWon) or (result = eBloody) or (result = eExpelled) then6468 if (Result = eWon) or (Result = eBloody) or (Result = eExpelled) then 6469 6469 begin 6470 6470 CityOptimizer_TileBecomesAvailable(ToLoc); 6471 NeedEcoUpdate := true;6471 NeedEcoUpdate := True; 6472 6472 end; 6473 6473 end; … … 6484 6484 end; 6485 6485 end; 6486 if result and rUnitRemoved <> 0 then6486 if Result and rUnitRemoved <> 0 then 6487 6487 begin 6488 6488 CityOptimizer_AfterRemoveUnit; 6489 6489 ListDlg.RemoveUnit; 6490 NeedEcoUpdate := true;6490 NeedEcoUpdate := True; 6491 6491 end; 6492 6492 if NeedEcoUpdate then 6493 6493 begin 6494 UpdateViews( true);6494 UpdateViews(True); 6495 6495 Update; 6496 6496 end; 6497 6497 end; 6498 6498 6499 if result = eMissionDone then6499 if Result = eMissionDone then 6500 6500 begin 6501 6501 p1 := MyRO.Territory[ToLoc]; … … 6503 6503 smStealMap: 6504 6504 begin 6505 MapValid := false;6505 MapValid := False; 6506 6506 PaintAllMaps 6507 6507 end; … … 6516 6516 CheckToldNoReturn(UnFocus); 6517 6517 6518 NeedRepaintPanel := false;6519 if result >= rExecuted then6518 NeedRepaintPanel := False; 6519 if Result >= rExecuted then 6520 6520 begin 6521 6521 if CityCaptured and (MyMap[ToLoc] and fCity = 0) then 6522 6522 begin // city destroyed 6523 for i:= 0 to nWonder - 1 do { tell about destroyed wonders }6524 if (MyRO.Wonder[ i].CityID = WonderDestroyed) and (MyData.ToldWonders[i].CityID <> WonderDestroyed)6523 for I := 0 to nWonder - 1 do { tell about destroyed wonders } 6524 if (MyRO.Wonder[I].CityID = WonderDestroyed) and (MyData.ToldWonders[I].CityID <> WonderDestroyed) 6525 6525 then 6526 6526 with MessgExDlg do 6527 6527 begin 6528 6528 if WondersDlg.Visible then 6529 WondersDlg.SmartUpdateContent( false);6529 WondersDlg.SmartUpdateContent(False); 6530 6530 OpenSound := 'WONDER_DESTROYED'; 6531 6531 MessgText := Format(Phrases.Lookup('WONDERDEST'), 6532 [Phrases.Lookup('IMPROVEMENTS', i)]);6532 [Phrases.Lookup('IMPROVEMENTS', I)]); 6533 6533 Kind := mkOkHelp; 6534 6534 HelpKind := hkImp; 6535 HelpNo := i;6535 HelpNo := I; 6536 6536 IconKind := mikImp; 6537 IconIndex := i;6537 IconIndex := I; 6538 6538 ShowModal; 6539 MyData.ToldWonders[ i] := MyRO.Wonder[i];6539 MyData.ToldWonders[I] := MyRO.Wonder[I]; 6540 6540 end; 6541 6541 end; … … 6543 6543 begin // city captured 6544 6544 ListDlg.AddCity; 6545 for i:= 0 to nWonder - 1 do { tell about capture of wonders }6546 if MyRO.City[MyRO.nCity - 1].Built[ i] > 0 then6545 for I := 0 to nWonder - 1 do { tell about capture of wonders } 6546 if MyRO.City[MyRO.nCity - 1].Built[I] > 0 then 6547 6547 with MessgExDlg do 6548 6548 begin 6549 6549 if WondersDlg.Visible then 6550 WondersDlg.SmartUpdateContent( false);6550 WondersDlg.SmartUpdateContent(False); 6551 6551 OpenSound := 'WONDER_CAPTURED'; 6552 MessgText := Format(Tribe[ me].TPhrase('WONDERCAPTOWN'),6553 [Phrases.Lookup('IMPROVEMENTS', i)]);6552 MessgText := Format(Tribe[Me].TPhrase('WONDERCAPTOWN'), 6553 [Phrases.Lookup('IMPROVEMENTS', I)]); 6554 6554 Kind := mkOkHelp; 6555 6555 HelpKind := hkImp; 6556 HelpNo := i;6556 HelpNo := I; 6557 6557 IconKind := mikImp; 6558 IconIndex := i;6558 IconIndex := I; 6559 6559 ShowModal; 6560 MyData.ToldWonders[ i] := MyRO.Wonder[i];6560 MyData.ToldWonders[I] := MyRO.Wonder[I]; 6561 6561 end; 6562 6562 … … 6564 6564 begin { Temple of Zeus -- choose advance to steal } 6565 6565 ModalSelectDlg.ShowNewContent(wmModal, kStealTech); 6566 Server(sStealTech, me, ModalSelectDlg.result, nil^);6566 Server(sStealTech, Me, ModalSelectDlg.Result, nil^); 6567 6567 end; 6568 6568 TellNewModels; … … 6570 6570 cix := MyRO.nCity - 1; 6571 6571 while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do 6572 dec(cix);6573 assert(cix >= 0);6572 Dec(cix); 6573 Assert(cix >= 0); 6574 6574 MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or 6575 6575 (3 shl 4); 6576 6576 // captured city, set to maximum growth 6577 6577 NewTiles := 1 shl 13; { exploit central tile only } 6578 Server(sSetCityTiles, me, cix, NewTiles);6578 Server(sSetCityTiles, Me, cix, NewTiles); 6579 6579 end 6580 6580 else 6581 NeedRepaintPanel := true;6581 NeedRepaintPanel := True; 6582 6582 end; 6583 6583 TellNewContacts; … … 6593 6593 if Options and (muAutoNoWait or muAutoNext) <> 0 then 6594 6594 begin 6595 if (UnFocus >= 0) and (( result = eNoTime_Move) or UnitExhausted(UnFocus) or6595 if (UnFocus >= 0) and ((Result = eNoTime_Move) or UnitExhausted(UnFocus) or 6596 6596 (MyUn[UnFocus].Master >= 0) or (MyModel[MyUn[UnFocus].mix].Domain = dAir) 6597 6597 and ((MyMap[MyUn[UnFocus].Loc] and fCity <> 0) … … 6607 6607 end 6608 6608 else 6609 NextUnit(UnStartLoc, true);6609 NextUnit(UnStartLoc, True); 6610 6610 end 6611 6611 else if (UnFocus < 0) and (Options and muAutoNext <> 0) then 6612 NextUnit(UnStartLoc, result <> eMissionDone);6612 NextUnit(UnStartLoc, Result <> eMissionDone); 6613 6613 end; 6614 6614 … … 6618 6618 else 6619 6619 begin 6620 assert(result <> eMissionDone);6620 Assert(Result <> eMissionDone); 6621 6621 CheckTerrainBtnVisible; 6622 6622 FocusOnLoc(ToLoc, flRepaintPanel or flImmUpdate); 6623 6623 end; 6624 6624 6625 if ( result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0)6625 if (Result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0) 6626 6626 then 6627 6627 ZoomToCity(ToLoc, UnFocus < 0, chCaptured); // show captured city … … 6629 6629 6630 6630 procedure TMainScreen.MoveOnScreen(ShowMove: TShowMove; 6631 Step0, Step1, nStep: integer; Restore: boolean = true);6631 Step0, Step1, nStep: Integer; Restore: Boolean = True); 6632 6632 var 6633 6633 ToLoc, xFromLoc, yFromLoc, xToLoc, yToLoc, xFrom, yFrom, xTo, yTo, xMin, yMin, 6634 xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: integer;6634 xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: Integer; 6635 6635 UnitInfo: TUnitInfo; 6636 6636 Ticks0, Ticks: TDateTime; 6637 6637 begin 6638 Timer1.Enabled := false;6638 Timer1.Enabled := False; 6639 6639 Ticks0 := NowPrecise; 6640 6640 with ShowMove do … … 6645 6645 UnitInfo.Job := jNone; 6646 6646 UnitInfo.Flags := Flags; 6647 if Owner <> me then6647 if Owner <> Me then 6648 6648 UnitInfo.emix := emix; 6649 6649 … … 6664 6664 * xxt - MapWidth) < abs(((xFromLoc - xw1) * 2 + yFromLoc and 1 + 1) * xxt 6665 6665 * 2 + dx * xxt - MapWidth) do 6666 dec(xw1, G.lx);6666 Dec(xw1, G.lx); 6667 6667 6668 6668 xTo := (xToLoc - xw1) * (xxt * 2) + yToLoc and 1 * xxt + (xxt - xxu); … … 6684 6684 yRange := yFrom - yTo; 6685 6685 end; 6686 inc(xRange, xxt * 2);6687 inc(yRange, yyt * 3);6686 Inc(xRange, xxt * 2); 6687 Inc(yRange, yyt * 3); 6688 6688 end; 6689 6689 … … 6694 6694 begin 6695 6695 BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, 6696 offscreen.Canvas, xMin, yMin);6696 Offscreen.Canvas, xMin, yMin); 6697 6697 if Step1 <> Step0 then 6698 6698 begin … … 6723 6723 < MoveTime) then 6724 6724 begin 6725 if not idle or (GameMode = cMovie) then6725 if not Idle or (GameMode = cMovie) then 6726 6726 Application.ProcessMessages; 6727 6727 Sleep(1); 6728 inc(SliceCount)6728 Inc(SliceCount) 6729 6729 end; 6730 6730 Ticks := NowPrecise; … … 6735 6735 if Restore then 6736 6736 begin 6737 BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, offscreen.Canvas, xMin, yMin);6737 BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, Offscreen.Canvas, xMin, yMin); 6738 6738 PaintBufferToScreen(xMin, yMin, xRange, yRange); 6739 6739 end; 6740 6740 BlinkTime := -1; 6741 Timer1.Enabled := true;6742 end; 6743 6744 procedure TMainScreen.MoveToLoc(Loc: integer; CheckSuicide: boolean);6741 Timer1.Enabled := True; 6742 end; 6743 6744 procedure TMainScreen.MoveToLoc(Loc: Integer; CheckSuicide: Boolean); 6745 6745 // path finder: move focused unit to loc, start multi-turn goto if too far 6746 6746 var 6747 uix, i, MoveOptions, NextLoc, MoveResult: integer;6747 uix, I, MoveOptions, NextLoc, MoveResult: Integer; 6748 6748 MoveAdviceData: TMoveAdviceData; 6749 6749 StopReason: (None, Arrived, Dead, NoTime, EnemySpotted, MoveError); 6750 6750 begin 6751 6751 if MyUn[UnFocus].Job > jNone then 6752 Server(sStartJob + jNone shl 4, me, UnFocus, nil^);6752 Server(sStartJob + jNone shl 4, Me, UnFocus, nil^); 6753 6753 if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) >= rExecuted then 6754 6754 begin … … 6756 6756 StopReason := None; 6757 6757 repeat 6758 for i:= 0 to MoveAdviceData.nStep - 1 do6759 begin 6760 if i= MoveAdviceData.nStep - 1 then6758 for I := 0 to MoveAdviceData.nStep - 1 do 6759 begin 6760 if I = MoveAdviceData.nStep - 1 then 6761 6761 MoveOptions := muAutoNext 6762 6762 else 6763 6763 MoveOptions := 0; 6764 NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[ i],6765 MoveAdviceData.dy[ i]);6764 NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[I], 6765 MoveAdviceData.dy[I]); 6766 6766 if (NextLoc = Loc) or (Loc = maNextCity) and 6767 6767 (MyMap[NextLoc] and fCity <> 0) then … … 6769 6769 if not CheckSuicide and (NextLoc = Loc) then 6770 6770 MoveOptions := MoveOptions or muNoSuicideCheck; 6771 MoveResult := MoveUnit(MoveAdviceData.dx[ i], MoveAdviceData.dy[i],6771 MoveResult := MoveUnit(MoveAdviceData.dx[I], MoveAdviceData.dy[I], 6772 6772 MoveOptions); 6773 6773 if MoveResult < rExecuted then … … 6781 6781 end; 6782 6782 if (StopReason = None) and ((MoveAdviceData.nStep < 25) or 6783 (MyRO.Wonder[woShinkansen].EffectiveOwner <> me)) then6783 (MyRO.Wonder[woShinkansen].EffectiveOwner <> Me)) then 6784 6784 StopReason := NoTime; 6785 6785 if StopReason <> None then … … 6787 6787 if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) < rExecuted then 6788 6788 begin 6789 assert(false);6789 Assert(False); 6790 6790 Break; 6791 6791 end; 6792 until false;6792 until False; 6793 6793 6794 6794 case StopReason of 6795 6795 None: 6796 assert(false);6796 Assert(False); 6797 6797 Arrived: 6798 6798 MyUn[uix].Status := MyUn[uix].Status and ($FFFF - usGoto); 6799 6799 Dead: 6800 6800 if UnFocus < 0 then 6801 NextUnit(UnStartLoc, false);6801 NextUnit(UnStartLoc, False); 6802 6802 else 6803 6803 begin // multi-turn goto … … 6812 6812 begin 6813 6813 MyUn[uix].Status := MyUn[uix].Status and not usWaiting; 6814 NextUnit(UnStartLoc, true);6814 NextUnit(UnStartLoc, True); 6815 6815 end; 6816 6816 end; … … 6820 6820 6821 6821 procedure TMainScreen.PanelBoxMouseDown(Sender: TObject; Button: TMouseButton; 6822 Shift: TShiftState; x, y: integer);6822 Shift: TShiftState; X, Y: Integer); 6823 6823 var 6824 i, xMouse, MouseLoc, p1: integer;6824 I, xMouse, MouseLoc, p1: Integer; 6825 6825 begin 6826 6826 if GameMode = cMovie then 6827 exit;6827 Exit; 6828 6828 6829 6829 if Button = mbLeft then 6830 6830 begin 6831 if ( x >= xMini + 2) and (y >= yMini + 2) and (x< xMini + 2 + 2 * G.lx) and6832 ( y< yMini + 2 + G.ly) then6831 if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and 6832 (Y < yMini + 2 + G.ly) then 6833 6833 if ssShift in Shift then 6834 6834 begin 6835 6835 with MainMap do 6836 xMouse := (xwMini + ( x- (xMini + 2) + MapWidth div (xxt * 2) + G.lx)6836 xMouse := (xwMini + (X - (xMini + 2) + MapWidth div (xxt * 2) + G.lx) 6837 6837 div 2) mod G.lx; 6838 MouseLoc := xMouse + G.lx * ( y- (yMini + 2));6838 MouseLoc := xMouse + G.lx * (Y - (yMini + 2)); 6839 6839 if MyMap[MouseLoc] and fTerrain <> fUNKNOWN then 6840 6840 begin 6841 6841 p1 := MyRO.Territory[MouseLoc]; 6842 if (p1 = me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then6842 if (p1 = Me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then 6843 6843 NatStatDlg.ShowNewContent(wmPersistent, p1); 6844 6844 end; … … 6850 6850 if UnitStatDlg.Visible then 6851 6851 UnitStatDlg.Close; 6852 Tracking := true;6853 PanelBoxMouseMove(Sender, Shift + [ssLeft], x, y);6852 Tracking := True; 6853 PanelBoxMouseMove(Sender, Shift + [ssLeft], X, Y); 6854 6854 end 6855 else if (ClientMode <> cEditMap) and ( x>= ClientWidth - xPalace) and6856 ( y >= yPalace) and (x< ClientWidth - xPalace + xSizeBig) and6857 ( y< yPalace + ySizeBig) then6855 else if (ClientMode <> cEditMap) and (X >= ClientWidth - xPalace) and 6856 (Y >= yPalace) and (X < ClientWidth - xPalace + xSizeBig) and 6857 (Y < yPalace + ySizeBig) then 6858 6858 begin 6859 6859 InitPopup(StatPopup); … … 6866 6866 GetSystemMetrics(SM_CYCAPTION) + 3) 6867 6867 end 6868 (* else if ( x>=xAdvisor-3) and (y>=yAdvisor-3)6869 and ( x<xAdvisor+16+3) and (y<yAdvisor+16+3) and HaveStrategyAdvice then6868 (* else if (X>=xAdvisor-3) and (Y>=yAdvisor-3) 6869 and (X<xAdvisor+16+3) and (Y<yAdvisor+16+3) and HaveStrategyAdvice then 6870 6870 AdviceBtnClick *) 6871 else if ( x >= xTroop + 1) and (y>= yTroop + 1) and6872 ( x < xTroop + TrRow * TrPitch) and (y<= yTroop + 55) then6873 begin 6874 i := (x- xTroop - 1) div TrPitch;6875 if trix[ i] >= 0 then6871 else if (X >= xTroop + 1) and (Y >= yTroop + 1) and 6872 (X < xTroop + TrRow * TrPitch) and (Y <= yTroop + 55) then 6873 begin 6874 I := (X - xTroop - 1) div TrPitch; 6875 if trix[I] >= 0 then 6876 6876 if ClientMode = cEditMap then 6877 6877 begin 6878 BrushType := trix[ i];6878 BrushType := trix[I]; 6879 6879 PanelPaint 6880 6880 end … … 6884 6884 if ssShift in Shift then 6885 6885 UnitStatDlg.ShowNewContent_OwnModel(wmPersistent, 6886 MyUn[trix[ i]].mix)6887 else if not supervising and (ClientMode < scContact) and6888 ( x - xTroop - 1 - i * TrPitch >= 60 - 20) and (y>= yTroop + 35)6889 and ((MyUn[trix[ i]].Job > jNone) or (MyUn[trix[i]].Status and6886 MyUn[trix[I]].mix) 6887 else if not Supervising and (ClientMode < scContact) and 6888 (X - xTroop - 1 - I * TrPitch >= 60 - 20) and (Y >= yTroop + 35) 6889 and ((MyUn[trix[I]].Job > jNone) or (MyUn[trix[I]].Status and 6890 6890 (usStay or usRecover or usGoto) <> 0)) then 6891 6891 begin // wake up 6892 MyUn[trix[ i]].Status := MyUn[trix[i]].Status and6892 MyUn[trix[I]].Status := MyUn[trix[I]].Status and 6893 6893 ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting; 6894 if MyUn[trix[ i]].Job > jNone then6895 Server(sStartJob + jNone shl 4, me, trix[i], nil^);6894 if MyUn[trix[I]].Job > jNone then 6895 Server(sStartJob + jNone shl 4, Me, trix[I], nil^); 6896 6896 if (UnFocus < 0) and not CityDlg.Visible then 6897 6897 begin 6898 SetUnFocus(trix[ i]);6899 SetTroopLoc(MyUn[trix[ i]].Loc);6898 SetUnFocus(trix[I]); 6899 SetTroopLoc(MyUn[trix[I]].Loc); 6900 6900 FocusOnLoc(TroopLoc, flRepaintPanel) 6901 6901 end … … 6903 6903 begin 6904 6904 if CityDlg.Visible and (CityDlg.RestoreUnFocus < 0) then 6905 CityDlg.RestoreUnFocus := trix[ i];6905 CityDlg.RestoreUnFocus := trix[I]; 6906 6906 PanelPaint; 6907 6907 end … … 6909 6909 else if (ClientMode < scContact) then 6910 6910 begin 6911 if supervising then6912 UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[ i])6911 if Supervising then 6912 UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[I]) 6913 6913 else if CityDlg.Visible then 6914 6914 begin … … 6916 6916 CityDlg.Close; 6917 6917 SumCities(TaxSum, ScienceSum); 6918 SetUnFocus(trix[ i]);6918 SetUnFocus(trix[I]); 6919 6919 end 6920 6920 else 6921 6921 begin 6922 DestinationMarkON := false;6922 DestinationMarkON := False; 6923 6923 PaintDestination; 6924 UnFocus := trix[ i];6924 UnFocus := trix[I]; 6925 6925 UnStartLoc := TroopLoc; 6926 6926 BlinkTime := 0; 6927 BlinkON := false;6927 BlinkON := False; 6928 6928 PaintLoc(TroopLoc); 6929 6929 end; 6930 6930 if UnFocus >= 0 then 6931 6931 begin 6932 UnitInfoBtn.Visible := true;6933 UnitBtn.Visible := true;6934 TurnComplete := false;6932 UnitInfoBtn.Visible := True; 6933 UnitBtn.Visible := True; 6934 TurnComplete := False; 6935 6935 EOT.ButtonIndex := eotGray; 6936 6936 end; … … 6939 6939 end; 6940 6940 end 6941 else if Server(sGetUnits, me, TroopLoc, TrCnt) >= rExecuted then6941 else if Server(sGetUnits, Me, TroopLoc, TrCnt) >= rExecuted then 6942 6942 if ssShift in Shift then 6943 6943 UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent, 6944 MyRO.EnemyUn[MyRO.nEnemyUn + trix[ i]].emix) // model info6944 MyRO.EnemyUn[MyRO.nEnemyUn + trix[I]].emix) // model info 6945 6945 else 6946 6946 UnitStatDlg.ShowNewContent_EnemyUnit(wmPersistent, 6947 MyRO.nEnemyUn + trix[ i]); // unit info6948 end; 6949 end; 6950 end; 6951 6952 procedure TMainScreen.SetTroopLoc(Loc: integer);6947 MyRO.nEnemyUn + trix[I]); // unit info 6948 end; 6949 end; 6950 end; 6951 6952 procedure TMainScreen.SetTroopLoc(Loc: Integer); 6953 6953 var 6954 trixFocus, uix, uixDefender: integer;6955 Prio: boolean;6954 trixFocus, uix, uixDefender: Integer; 6955 Prio: Boolean; 6956 6956 begin 6957 6957 TroopLoc := Loc; … … 6965 6965 if MyMap[Loc] and fOwned <> 0 then 6966 6966 begin // count own units here 6967 Server(sGetDefender, me, TroopLoc, uixDefender);6968 for Prio := true downto false do6967 Server(sGetDefender, Me, TroopLoc, uixDefender); 6968 for Prio := True downto False do 6969 6969 for uix := 0 to MyRO.nUn - 1 do 6970 6970 if ((uix = uixDefender) = Prio) and (MyUn[uix].Loc = Loc) then … … 6972 6972 if uix = UnFocus then 6973 6973 trixFocus := TrCnt; 6974 inc(TrCnt);6974 Inc(TrCnt); 6975 6975 end; 6976 6976 end 6977 6977 else // count enemy units here 6978 Server(sGetUnits, me, Loc, TrCnt);6978 Server(sGetUnits, Me, Loc, TrCnt); 6979 6979 if TrCnt = 0 then 6980 6980 sb.Init(0, 1) … … 6987 6987 end; 6988 6988 6989 (* procedure TMainScreen.ShowMoveHint(ToLoc: integer; Force: boolean = false);6989 (* procedure TMainScreen.ShowMoveHint(ToLoc: Integer; Force: Boolean = False); 6990 6990 var 6991 Step,Loc,x0,y0,xs,ys: integer;6991 Step,Loc,x0,y0,xs,ys: Integer; 6992 6992 Info: string; 6993 6993 InfoSize: TSize; … … 7002 7002 MoveAdvice.MoreTurns:=0; 7003 7003 MoveAdvice.MaxHostile_MovementLeft:=MyUn[UnFocus].Health-50; 7004 if Server(sGetMoveAdvice, me,UnFocus,MoveAdvice)<rExecuted then7004 if Server(sGetMoveAdvice,Me,UnFocus,MoveAdvice)<rExecuted then 7005 7005 ToLoc:=-1 7006 7006 end; 7007 if (ToLoc=MoveHintToLoc) and not Force then exit;7007 if (ToLoc=MoveHintToLoc) and not Force then Exit; 7008 7008 if (ToLoc<>MoveHintToLoc) and (MoveHintToLoc>=0) then 7009 7009 begin invalidate; update end; // clear old hint from screen 7010 7010 MoveHintToLoc:=ToLoc; 7011 if ToLoc<0 then exit;7012 7013 with canvas do7011 if ToLoc<0 then Exit; 7012 7013 with Canvas do 7014 7014 begin 7015 7015 Pen.Color:=$80C0FF; … … 7022 7022 xs:=(x0-xw)*66+y0 and 1*33-G.lx*66; 7023 7023 while abs(2*(xs+G.lx*66)-MapWidth)<abs(2*xs-MapWidth) do 7024 inc(xs,G.lx*66);7024 Inc(xs,G.lx*66); 7025 7025 ys:=(y0-yw)*16; 7026 7026 if Step=0 then moveto(xs+33,ys+16) … … 7030 7030 end; 7031 7031 Brush.Color:=$80C0FF; 7032 Info:=' '+ inttostr(88)+' ';7032 Info:=' '+IntToStr(88)+' '; 7033 7033 InfoSize:=TextExtent(Info); 7034 7034 TextOut(xs+33-InfoSize.cx div 2, ys+16-InfoSize.cy div 2, Info); … … 7037 7037 end; *) 7038 7038 7039 procedure TMainScreen.SetDebugMap( p: integer);7040 begin 7041 MainMap.pDebugMap := p;7039 procedure TMainScreen.SetDebugMap(P: Integer); 7040 begin 7041 MainMap.pDebugMap := P; 7042 7042 MapOptions := MapOptions - [moLocCodes]; 7043 mLocCodes.Checked := false;7044 MapValid := false;7043 mLocCodes.Checked := False; 7044 MapValid := False; 7045 7045 MainOffscreenPaint; 7046 7046 end; 7047 7047 7048 procedure TMainScreen.SetViewpoint( p: integer);7048 procedure TMainScreen.SetViewpoint(P: Integer); 7049 7049 var 7050 i: Integer;7051 begin 7052 if supervising and (G.RO[0].Turn > 0) and7053 (( p = 0) or (1 shl pand G.RO[0].Alive <> 0)) then7050 I: Integer; 7051 begin 7052 if Supervising and (G.RO[0].Turn > 0) and 7053 ((P = 0) or (1 shl P and G.RO[0].Alive <> 0)) then 7054 7054 begin 7055 7055 ApplyToVisibleForms(faClose); 7056 ItsMeAgain( p);7056 ItsMeAgain(P); 7057 7057 SumCities(TaxSum, ScienceSum); 7058 for i:= 0 to MyRO.nModel - 1 do7059 if not Assigned(Tribe[ me].ModelPicture[i].HGr) then7060 InitMyModel( i, True);7058 for I := 0 to MyRO.nModel - 1 do 7059 if not Assigned(Tribe[Me].ModelPicture[I].HGr) then 7060 InitMyModel(I, True); 7061 7061 7062 7062 SetTroopLoc(-1); … … 7146 7146 end; 7147 7147 7148 procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: word;7148 procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: Word; 7149 7149 Shift: TShiftState); 7150 7150 … … 7156 7156 end; 7157 7157 7158 procedure SetViewpointMe( p: Integer);7159 begin 7160 if p = me then SetViewpoint(p)7161 else SetViewpoint( p);7158 procedure SetViewpointMe(P: Integer); 7159 begin 7160 if P = Me then SetViewpoint(P) 7161 else SetViewpoint(P); 7162 7162 end; 7163 7163 … … 7195 7195 'A': 7196 7196 begin // auto symmetry 7197 Server($7F0, me,0,nil^);7198 MapValid:= false;7197 Server($7F0,Me,0,nil^); 7198 MapValid:=False; 7199 7199 PaintAll; 7200 7200 end; … … 7203 7203 dy:=0; 7204 7204 for dx:=G.lx to G.lx*(G.ly-1)-1 do 7205 if MyMap[dx] and fTerrain>=fGrass then inc(dy);7205 if MyMap[dx] and fTerrain>=fGrass then Inc(dy); 7206 7206 dy:=dy 7207 7207 end; … … 7330 7330 function TMainScreen.DoJob(j0: Integer): Integer; 7331 7331 var 7332 Loc0, Movement0: integer;7332 Loc0, Movement0: Integer; 7333 7333 begin 7334 7334 with MyUn[UnFocus] do 7335 7335 begin 7336 DestinationMarkON := false;7336 DestinationMarkON := False; 7337 7337 PaintDestination; 7338 7338 Loc0 := Loc; 7339 7339 Movement0 := Movement; 7340 7340 if j0 < 0 then 7341 result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs)7341 Result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs) 7342 7342 // terrain enhancement 7343 7343 else 7344 result := Server(sStartJob + j0 shl 4, me, UnFocus, nil^);7345 if result >= rExecuted then7346 begin 7347 if result = eDied then7344 Result := Server(sStartJob + j0 shl 4, Me, UnFocus, nil^); 7345 if Result >= rExecuted then 7346 begin 7347 if Result = eDied then 7348 7348 UnFocus := -1; 7349 7349 PaintLoc(Loc0); 7350 7350 if UnFocus >= 0 then 7351 7351 begin 7352 if (j0 < 0) and ( result <> eJobDone) then7352 if (j0 < 0) and (Result <> eJobDone) then 7353 7353 // multi-turn terrain enhancement 7354 7354 Status := Status and ($FFFF - usStay - usRecover - usGoto) or … … 7360 7360 begin 7361 7361 Status := Status and not usWaiting; 7362 NextUnit(UnStartLoc, true);7362 NextUnit(UnStartLoc, True); 7363 7363 end 7364 7364 else … … 7366 7366 end 7367 7367 else 7368 NextUnit(UnStartLoc, true);7369 end; 7370 end; 7371 case result of7368 NextUnit(UnStartLoc, True); 7369 end; 7370 end; 7371 case Result of 7372 7372 eNoBridgeBuilding: 7373 7373 SoundMessage(Phrases.Lookup('NOBB'), 'INVALID'); … … 7378 7378 'NOMOVE_TREATY'); 7379 7379 else 7380 if result < rExecuted then7380 if Result < rExecuted then 7381 7381 Play('INVALID'); 7382 7382 end; … … 7390 7390 with TUn(MyUn[UnFocus]) do begin 7391 7391 if (Sender = mUtilize) and 7392 not(Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized) then7392 not(Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then 7393 7393 begin 7394 7394 SimpleMessage(Phrases2.Lookup('SHIP_UTILIZE')); 7395 7395 // freight for colony ship is the only case in which the command is 7396 7396 // available to player though not valid 7397 exit;7397 Exit; 7398 7398 end; 7399 7399 if (Sender = mUtilize) and (Health < 100) then 7400 7400 if SimpleQuery(mkYesNo, Phrases.Lookup('DAMAGED_UTILIZE'), '') <> mrOK 7401 7401 then 7402 exit;7402 Exit; 7403 7403 Loc0 := Loc; 7404 7404 CityOptimizer_BeforeRemoveUnit(UnFocus); 7405 if Server(sRemoveUnit, me, UnFocus, nil^) = eUtilized then7405 if Server(sRemoveUnit, Me, UnFocus, nil^) = eUtilized then 7406 7406 Play('CITY_UTILIZE') 7407 7407 else … … 7409 7409 CityOptimizer_AfterRemoveUnit; 7410 7410 SetTroopLoc(Loc0); 7411 UpdateViews( true);7412 DestinationMarkON := false;7411 UpdateViews(True); 7412 DestinationMarkON := False; 7413 7413 PaintDestination; 7414 7414 UnFocus := -1; 7415 7415 PaintLoc(Loc0); 7416 NextUnit(UnStartLoc, true);7416 NextUnit(UnStartLoc, True); 7417 7417 end; 7418 7418 end; … … 7420 7420 procedure TMainScreen.InitPopup(Popup: TPopupMenu); 7421 7421 var 7422 i, p1, Tile, Test: integer;7423 NoSuper, extended, Multi, NeedSep, HaveCities: boolean;7424 LastSep, m: TMenuItem;7422 I, p1, Tile, Test: Integer; 7423 NoSuper, Extended, Multi, NeedSep, HaveCities: Boolean; 7424 LastSep, M: TMenuItem; 7425 7425 mox: ^TModel; 7426 7426 begin 7427 NoSuper := not supervising and (1 shl me and MyRO.Alive <> 0);7428 HaveCities := false;7429 for i:= 0 to MyRO.nCity - 1 do7430 if MyCity[ i].Loc >= 0 then7431 begin 7432 HaveCities := true;7427 NoSuper := not Supervising and (1 shl Me and MyRO.Alive <> 0); 7428 HaveCities := False; 7429 for I := 0 to MyRO.nCity - 1 do 7430 if MyCity[I].Loc >= 0 then 7431 begin 7432 HaveCities := True; 7433 7433 Break; 7434 7434 end; … … 7436 7436 begin 7437 7437 mTechTree.Visible := ClientMode <> cEditMap; 7438 mResign.Enabled := supervising or (me = 0) and (ClientMode < scContact);7438 mResign.Enabled := Supervising or (Me = 0) and (ClientMode < scContact); 7439 7439 mRandomMap.Visible := (ClientMode = cEditMap) and 7440 (Server(sMapGeneratorRequest, me, 0, nil^) = eOK);7440 (Server(sMapGeneratorRequest, Me, 0, nil^) = eOK); 7441 7441 mOptions.Visible := ClientMode <> cEditMap; 7442 7442 mManip.Visible := ClientMode <> cEditMap; … … 7452 7452 case SoundMode of 7453 7453 smOff: 7454 mSoundOff.Checked := true;7454 mSoundOff.Checked := True; 7455 7455 smOn: 7456 mSoundOn.Checked := true;7456 mSoundOn.Checked := True; 7457 7457 smOnAlt: 7458 mSoundOnAlt.Checked := true;7459 end; 7460 7461 for i:= 0 to nTestFlags - 1 do7462 mManip[ i].Checked := MyRO.TestFlags and (1 shl i) <> 0;7463 mManip.Enabled := supervising or (me = 0);7464 7465 Multi := false;7458 mSoundOnAlt.Checked := True; 7459 end; 7460 7461 for I := 0 to nTestFlags - 1 do 7462 mManip[I].Checked := MyRO.TestFlags and (1 shl I) <> 0; 7463 mManip.Enabled := Supervising or (Me = 0); 7464 7465 Multi := False; 7466 7466 for p1 := 1 to nPl - 1 do 7467 7467 if G.RO[p1] <> nil then 7468 Multi := true;7468 Multi := True; 7469 7469 mEnemyMovement.Visible := not Multi; 7470 7470 end; … … 7472 7472 if NoSuper and (ClientMode < scContact) then 7473 7473 begin 7474 mCityTypes.Enabled := false;7474 mCityTypes.Enabled := False; 7475 7475 // check if city types already usefull: 7476 7476 if MyRO.nCity > 0 then 7477 for i:= nWonder to nImp - 1 do7478 if ( i <> imTrGoods) and (Imp[i].Kind = ikCommon) and7479 (Imp[ i].Preq <> preNA) and7480 ((Imp[ i].Preq = preNone) or (MyRO.Tech[Imp[i].Preq] >= tsApplicable))7477 for I := nWonder to nImp - 1 do 7478 if (I <> imTrGoods) and (Imp[I].Kind = ikCommon) and 7479 (Imp[I].Preq <> preNA) and 7480 ((Imp[I].Preq = preNone) or (MyRO.Tech[Imp[I].Preq] >= tsApplicable)) 7481 7481 then 7482 7482 begin 7483 mCityTypes.Enabled := true;7483 mCityTypes.Enabled := True; 7484 7484 Break 7485 7485 end; 7486 7486 end; 7487 mViewpoint.Visible := (ClientMode <> cEditMap) and supervising;7487 mViewpoint.Visible := (ClientMode <> cEditMap) and Supervising; 7488 7488 mViewpoint.Enabled := G.RO[0].Turn > 0; 7489 if supervising then7489 if Supervising then 7490 7490 begin 7491 7491 EmptyMenu(mViewpoint); … … 7493 7493 if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then 7494 7494 begin 7495 m:= TMenuItem.Create(mViewpoint);7495 M := TMenuItem.Create(mViewpoint); 7496 7496 if p1 = 0 then 7497 m.Caption := Phrases.Lookup('SUPER')7497 M.Caption := Phrases.Lookup('SUPER') 7498 7498 else 7499 m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));7500 m.Tag := p1;7501 m.OnClick := ViewpointClick;7499 M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG')); 7500 M.Tag := p1; 7501 M.OnClick := ViewpointClick; 7502 7502 if p1 < 10 then 7503 m.ShortCut := ShortCut(48 + p1, [ssCtrl]);7504 m.RadioItem := true;7505 if p1 = me then7506 m.Checked := true;7507 mViewpoint.Add( m);7503 M.ShortCut := ShortCut(48 + p1, [ssCtrl]); 7504 M.RadioItem := True; 7505 if p1 = Me then 7506 M.Checked := True; 7507 mViewpoint.Add(M); 7508 7508 end 7509 7509 end; 7510 mDebugMap.Visible := (ClientMode <> cEditMap) and supervising;7511 if supervising then7510 mDebugMap.Visible := (ClientMode <> cEditMap) and Supervising; 7511 if Supervising then 7512 7512 begin 7513 7513 EmptyMenu(mDebugMap); … … 7515 7515 if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then 7516 7516 begin 7517 m:= TMenuItem.Create(mDebugMap);7517 M := TMenuItem.Create(mDebugMap); 7518 7518 if p1 = 0 then 7519 m.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF')7519 M.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF') 7520 7520 else 7521 m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));7521 M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG')); 7522 7522 if p1 = 0 then 7523 m.Tag := -17523 M.Tag := -1 7524 7524 else 7525 m.Tag := p1;7526 m.OnClick := DebugMapClick;7525 M.Tag := p1; 7526 M.OnClick := DebugMapClick; 7527 7527 if p1 < 10 then 7528 m.ShortCut := ShortCut(48 + p1, [ssAlt]);7529 m.RadioItem := true;7530 if m.Tag = MainMap.pDebugMap then7531 m.Checked := true;7532 mDebugMap.Add( m);7528 M.ShortCut := ShortCut(48 + p1, [ssAlt]); 7529 M.RadioItem := True; 7530 if M.Tag = MainMap.pDebugMap then 7531 M.Checked := True; 7532 mDebugMap.Add(M); 7533 7533 end; 7534 7534 end; … … 7545 7545 (ClientMode < scContact); 7546 7546 mUnitStat.Enabled := NoSuper or (MyRO.Turn > 0); 7547 mCityStat.Visible := 1 shl me and MyRO.Alive <> 0;7547 mCityStat.Visible := 1 shl Me and MyRO.Alive <> 0; 7548 7548 mCityStat.Enabled := HaveCities; 7549 mScienceStat.Visible := true;7549 mScienceStat.Visible := True; 7550 7550 mScienceStat.Enabled := not NoSuper or (MyRO.ResearchTech >= 0) or 7551 7551 (MyRO.Happened and phTech <> 0) or (MyRO.Happened and phGameEnd <> 0) … … 7554 7554 mEUnitStat.Enabled := MyRO.nEnemyModel > 0; 7555 7555 { mWonders.Enabled:= false; 7556 for i:=0 to nWonder - 1 do if MyRO.Wonder[i].CityID <> WonderNotBuiltYet then7557 mWonders.Enabled:= true; }7556 for I:=0 to nWonder - 1 do if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then 7557 mWonders.Enabled:=True; } 7558 7558 mDiagram.Enabled := MyRO.Turn >= 2; 7559 mShips.Enabled := false;7559 mShips.Enabled := False; 7560 7560 for p1 := 0 to nPl - 1 do 7561 7561 if MyRO.Ship[p1].Parts[spComp] + MyRO.Ship[p1].Parts[spPow] + 7562 7562 MyRO.Ship[p1].Parts[spHab] > 0 then 7563 mShips.Enabled := true;7563 mShips.Enabled := True; 7564 7564 end 7565 7565 else if Popup = UnitPopup then … … 7567 7567 mox := @MyModel[MyUn[UnFocus].mix]; 7568 7568 Tile := MyMap[MyUn[UnFocus].Loc]; 7569 extended := Tile and fCity = 0;7570 if extended then7569 Extended := Tile and fCity = 0; 7570 if Extended then 7571 7571 begin 7572 7572 mCity.Caption := Phrases.Lookup('BTN_FOUND'); … … 7579 7579 end; 7580 7580 7581 extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)7581 Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves) 7582 7582 and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and 7583 7583 (MyUn[UnFocus].Master < 0) and (Tile and fDeadLands = 0); 7584 7584 if (mox.Kind = mkFreight) and (Tile and fCity <> 0) and 7585 7585 not Phrases2FallenBackToEnglish or 7586 (Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized) then7587 begin 7588 mDisband.Visible := false;7589 mUtilize.Visible := true;7586 (Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then 7587 begin 7588 mDisband.Visible := False; 7589 mUtilize.Visible := True; 7590 7590 if mox.Kind = mkFreight then 7591 7591 mUtilize.Caption := Phrases.Lookup('UTILIZE') … … 7595 7595 else 7596 7596 begin 7597 mDisband.Visible := true;7598 mUtilize.Visible := false7597 mDisband.Visible := True; 7598 mUtilize.Visible := False 7599 7599 end; 7600 7600 mGoOn.Visible := MyUn[UnFocus].Status and (usGoto or usWaiting) = usGoto or … … 7603 7603 mRecover.Visible := (MyUn[UnFocus].Health < 100) and 7604 7604 (Tile and fTerrain >= fGrass) and 7605 ((MyRO.Wonder[woGardens].EffectiveOwner = me) or7605 ((MyRO.Wonder[woGardens].EffectiveOwner = Me) or 7606 7606 (Tile and fTerrain <> fArctic) and (Tile and fTerrain <> fDesert)) and 7607 7607 not((mox.Domain = dAir) and (Tile and fCity = 0) and … … 7609 7609 mStay.Visible := not((mox.Domain = dAir) and (Tile and fCity = 0) and 7610 7610 (Tile and fTerImp <> tiBase)); 7611 mCity.Visible := extended and (mox.Kind = mkSettler) or7611 mCity.Visible := Extended and (mox.Kind = mkSettler) or 7612 7612 (Tile and fCity <> 0) and ((mox.Kind in [mkSettler, mkSlaves]) or 7613 7613 (MyUn[UnFocus].Flags and unConscripts <> 0)); … … 7617 7617 (MyUn[UnFocus].Status and (usRecover or usGoto) <> 0); 7618 7618 7619 Test := Server(sLoadUnit - sExecute, me, UnFocus, nil^);7619 Test := Server(sLoadUnit - sExecute, Me, UnFocus, nil^); 7620 7620 mLoad.Visible := (Test >= rExecuted) or (Test = eNoTime_Load); 7621 7621 mUnload.Visible := (MyUn[UnFocus].Master >= 0) or 7622 7622 (MyUn[UnFocus].TroopLoad + MyUn[UnFocus].AirLoad > 0); 7623 mSelectTransport.Visible := Server(sSelectTransport - sExecute, me, UnFocus,7623 mSelectTransport.Visible := Server(sSelectTransport - sExecute, Me, UnFocus, 7624 7624 nil^) >= rExecuted; 7625 7625 end … … 7628 7628 mox := @MyModel[MyUn[UnFocus].mix]; 7629 7629 Tile := MyMap[MyUn[UnFocus].Loc]; 7630 extended := Tile and fCity = 0;7630 Extended := Tile and fCity = 0; 7631 7631 7632 7632 if (Tile and fRiver <> 0) and (MyRO.Tech[adBridgeBuilding] >= tsApplicable) … … 7648 7648 mClear.Caption := Phrases.Lookup('BTN_DRAIN'); 7649 7649 7650 extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)7650 Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves) 7651 7651 and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and 7652 7652 (MyUn[UnFocus].Master < 0); 7653 if extended then7653 if Extended then 7654 7654 begin 7655 7655 mRoad.Visible := JobTest(UnFocus, jRoad, [eNoBridgeBuilding, eTreaty]); … … 7671 7671 else 7672 7672 begin 7673 for i:= 0 to Popup.Items.Count - 1 do7674 Popup.Items[ i].Visible := false;7673 for I := 0 to Popup.Items.Count - 1 do 7674 Popup.Items[I].Visible := False; 7675 7675 end; 7676 7676 end; … … 7678 7678 // set menu seperators 7679 7679 LastSep := nil; 7680 NeedSep := false;7681 for i:= 0 to Popup.Items.Count - 1 do7682 if Popup.Items[ i].Caption = '-' then7683 begin 7684 Popup.Items[ i].Visible := NeedSep;7680 NeedSep := False; 7681 for I := 0 to Popup.Items.Count - 1 do 7682 if Popup.Items[I].Caption = '-' then 7683 begin 7684 Popup.Items[I].Visible := NeedSep; 7685 7685 if NeedSep then 7686 LastSep := Popup.Items[ i];7687 NeedSep := false7686 LastSep := Popup.Items[I]; 7687 NeedSep := False 7688 7688 end 7689 else if Popup.Items[ i].Visible then7690 NeedSep := true;7689 else if Popup.Items[I].Visible then 7690 NeedSep := True; 7691 7691 if (LastSep <> nil) and not NeedSep then 7692 LastSep.Visible := false7692 LastSep.Visible := False 7693 7693 end; 7694 7694 … … 7709 7709 end; 7710 7710 7711 procedure TMainScreen.CityClosed(Activateuix: integer; StepFocus: boolean;7712 SelectFocus: boolean);7713 begin 7714 if supervising then7711 procedure TMainScreen.CityClosed(Activateuix: Integer; StepFocus: Boolean; 7712 SelectFocus: Boolean); 7713 begin 7714 if Supervising then 7715 7715 begin 7716 7716 SetTroopLoc(-1); … … 7729 7729 end 7730 7730 else if StepFocus then 7731 NextUnit(TroopLoc, true)7731 NextUnit(TroopLoc, True) 7732 7732 else 7733 7733 begin … … 7744 7744 7745 7745 procedure TMainScreen.PanelBoxMouseMove(Sender: TObject; Shift: TShiftState; 7746 x, y: integer);7746 X, Y: Integer); 7747 7747 var 7748 xCentre, yCentre: integer;7748 xCentre, yCentre: Integer; 7749 7749 begin 7750 7750 if Tracking and (ssLeft in Shift) then 7751 7751 with MainMap do begin 7752 if ( x >= xMini + 2) and (y >= yMini + 2) and (x< xMini + 2 + 2 * G.lx) and7753 ( y< yMini + 2 + G.ly) then7754 begin 7755 xCentre := (xwMini + ( x- xMini - 2) div 2 + G.lx div 2 +7752 if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and 7753 (Y < yMini + 2 + G.ly) then 7754 begin 7755 xCentre := (xwMini + (X - xMini - 2) div 2 + G.lx div 2 + 7756 7756 MapWidth div (xxt * 4)) mod G.lx; 7757 yCentre := ( y- yMini - 2);7757 yCentre := (Y - yMini - 2); 7758 7758 xw := (xCentre - MapWidth div (xxt * 4) + G.lx) mod G.lx; 7759 7759 if ywmax <= 0 then … … 7769 7769 BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0); 7770 7770 if ywmax <= 0 then 7771 Frame(Buffer.Canvas, x- xMini - 2 - MapWidth div (xxt * 2), 0,7772 x- xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1,7771 Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), 0, 7772 X - xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1, 7773 7773 MainTexture.ColorMark, MainTexture.ColorMark) 7774 7774 else 7775 Frame(Buffer.Canvas, x- xMini - 2 - MapWidth div (xxt * 2), yw,7776 x- xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt -7775 Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), yw, 7776 X - xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt - 7777 7777 2, MainTexture.ColorMark, MainTexture.ColorMark); 7778 7778 BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly, … … 7786 7786 end 7787 7787 else 7788 Tracking := false;7788 Tracking := False; 7789 7789 end; 7790 7790 7791 7791 procedure TMainScreen.PanelBoxMouseUp(Sender: TObject; Button: TMouseButton; 7792 Shift: TShiftState; x, y: integer);7792 Shift: TShiftState; X, Y: Integer); 7793 7793 begin 7794 7794 if Tracking then 7795 7795 begin 7796 Tracking := false;7796 Tracking := False; 7797 7797 xwMini := xw; 7798 7798 ywMini := yw; … … 7803 7803 7804 7804 procedure TMainScreen.MapBoxMouseMove(Sender: TObject; Shift: TShiftState; 7805 x, y: integer);7805 X, Y: Integer); 7806 7806 var 7807 MouseLoc: integer;7808 begin 7809 xMouse := x;7810 yMouse := y;7807 MouseLoc: Integer; 7808 begin 7809 xMouse := X; 7810 yMouse := Y; 7811 7811 if (ClientMode = cEditMap) and (ssLeft in Shift) and not Tracking then 7812 7812 begin 7813 MouseLoc := LocationOfScreenPixel( x, y);7813 MouseLoc := LocationOfScreenPixel(X, Y); 7814 7814 if MouseLoc <> BrushLoc then 7815 MapBoxMouseDown(nil, mbLeft, Shift, x, y);7815 MapBoxMouseDown(nil, mbLeft, Shift, X, Y); 7816 7816 end 7817 (* else if idle and (UnFocus>=0) then7817 (* else if Idle and (UnFocus>=0) then 7818 7818 begin 7819 7819 qx:=(xMouse*32+yMouse*66+16*66) div(32*66)-1; … … 7828 7828 TMenuItem(Sender).Checked := not TMenuItem(Sender).Checked; 7829 7829 SetMapOptions; 7830 MapValid := false;7830 MapValid := False; 7831 7831 PaintAllMaps; 7832 7832 end; … … 7834 7834 procedure TMainScreen.mNamesClick(Sender: TObject); 7835 7835 var 7836 p1: integer;7836 p1: Integer; 7837 7837 begin 7838 7838 mNames.Checked := not mNames.Checked; … … 7844 7844 else 7845 7845 Tribe[p1].NumberName := p1; 7846 MapValid := false;7846 MapValid := False; 7847 7847 PaintAll; 7848 7848 end; 7849 7849 7850 function TMainScreen.IsPanelPixel( x, y: integer): boolean;7851 begin 7852 result := (y >= TopBarHeight + MapHeight) or (y>= ClientHeight - PanelHeight)7853 and (( x < xMidPanel) or (x>= xRightPanel));7850 function TMainScreen.IsPanelPixel(X, Y: Integer): Boolean; 7851 begin 7852 Result := (Y >= TopBarHeight + MapHeight) or (Y >= ClientHeight - PanelHeight) 7853 and ((X < xMidPanel) or (X >= xRightPanel)); 7854 7854 end; 7855 7855 7856 7856 procedure TMainScreen.FormMouseDown(Sender: TObject; Button: TMouseButton; 7857 Shift: TShiftState; x, y: integer);7858 begin 7859 if idle then7860 if ( x < 40) and (y< 40) then7857 Shift: TShiftState; X, Y: Integer); 7858 begin 7859 if Idle then 7860 if (X < 40) and (Y < 40) then 7861 7861 begin 7862 7862 if GameMode <> cMovie then … … 7870 7870 end; 7871 7871 end 7872 else if IsPanelPixel( x, y) then7873 PanelBoxMouseDown(Sender, Button, Shift, x,7874 y- (ClientHeight - PanelHeight))7875 else if ( y >= TopBarHeight) and (x>= MapOffset) and7876 ( x< MapOffset + MapWidth) then7877 MapBoxMouseDown(Sender, Button, Shift, x - MapOffset, y- TopBarHeight)7872 else if IsPanelPixel(X, Y) then 7873 PanelBoxMouseDown(Sender, Button, Shift, X, 7874 Y - (ClientHeight - PanelHeight)) 7875 else if (Y >= TopBarHeight) and (X >= MapOffset) and 7876 (X < MapOffset + MapWidth) then 7877 MapBoxMouseDown(Sender, Button, Shift, X - MapOffset, Y - TopBarHeight) 7878 7878 end; 7879 7879 7880 7880 procedure TMainScreen.FormMouseMove(Sender: TObject; Shift: TShiftState; 7881 x, y: integer);7882 begin 7883 if idle then7884 if IsPanelPixel( x, y) then7885 PanelBoxMouseMove(Sender, Shift, x, y- (ClientHeight - PanelHeight))7886 else if ( y >= TopBarHeight) and (x>= MapOffset) and7887 ( x< MapOffset + MapWidth) then7888 MapBoxMouseMove(Sender, Shift, x - MapOffset, y- TopBarHeight);7881 X, Y: Integer); 7882 begin 7883 if Idle then 7884 if IsPanelPixel(X, Y) then 7885 PanelBoxMouseMove(Sender, Shift, X, Y - (ClientHeight - PanelHeight)) 7886 else if (Y >= TopBarHeight) and (X >= MapOffset) and 7887 (X < MapOffset + MapWidth) then 7888 MapBoxMouseMove(Sender, Shift, X - MapOffset, Y - TopBarHeight); 7889 7889 end; 7890 7890 7891 7891 procedure TMainScreen.FormMouseUp(Sender: TObject; Button: TMouseButton; 7892 Shift: TShiftState; x, y: integer);7893 begin 7894 if idle then7895 PanelBoxMouseUp(Sender, Button, Shift, x, y- (ClientHeight - PanelHeight));7892 Shift: TShiftState; X, Y: Integer); 7893 begin 7894 if Idle then 7895 PanelBoxMouseUp(Sender, Button, Shift, X, Y - (ClientHeight - PanelHeight)); 7896 7896 end; 7897 7897 … … 7902 7902 with Canvas do 7903 7903 begin // pillarbox, make left and right border black 7904 if me < 0 then7904 if Me < 0 then 7905 7905 Brush.Color := $000000 7906 7906 else … … 7929 7929 end; 7930 7930 BitBltCanvas(Canvas, MapOffset, TopBarHeight, MapWidth, MapHeight - overlap, 7931 offscreen.Canvas, 0, 0);7931 Offscreen.Canvas, 0, 0); 7932 7932 BitBltCanvas(Canvas, 0, 0, ClientWidth, TopBarHeight, TopBar.Canvas, 7933 7933 0, 0); 7934 7934 if xMidPanel > MapOffset then 7935 7935 BitBltCanvas(Canvas, xMidPanel, TopBarHeight + MapHeight - overlap, 7936 ClientWidth div 2 - xMidPanel, overlap, offscreen.Canvas,7936 ClientWidth div 2 - xMidPanel, overlap, Offscreen.Canvas, 7937 7937 xMidPanel - MapOffset, MapHeight - overlap) 7938 7938 else 7939 7939 BitBltCanvas(Canvas, MapOffset, TopBarHeight + MapHeight - overlap, 7940 ClientWidth div 2 - MapOffset, overlap, offscreen.Canvas, 0,7940 ClientWidth div 2 - MapOffset, overlap, Offscreen.Canvas, 0, 7941 7941 MapHeight - overlap); 7942 7942 if xRightPanel < MapOffset + MapWidth then 7943 7943 BitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap, 7944 xRightPanel - ClientWidth div 2, overlap, offscreen.Canvas,7944 xRightPanel - ClientWidth div 2, overlap, Offscreen.Canvas, 7945 7945 ClientWidth div 2 - MapOffset, MapHeight - overlap) 7946 7946 else 7947 7947 BitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap, 7948 7948 MapOffset + MapWidth - ClientWidth div 2, overlap, 7949 offscreen.Canvas, ClientWidth div 2 - MapOffset,7949 Offscreen.Canvas, ClientWidth div 2 - MapOffset, 7950 7950 MapHeight - overlap); 7951 7951 BitBltCanvas(Canvas, 0, TopBarHeight + MapHeight - overlap, xMidPanel, … … 7960 7960 end; 7961 7961 7962 procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: integer);7962 procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: Integer); 7963 7963 var 7964 7964 r0: HRgn; 7965 7965 begin 7966 7966 r0 := CreateRectRgn(Left, Top, Rigth, Bottom); 7967 InvalidateRgn(Handle, r0, false);7967 InvalidateRgn(Handle, r0, False); 7968 7968 DeleteObject(r0); 7969 7969 end; 7970 7970 7971 procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);7971 procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer); 7972 7972 var 7973 i: integer;7973 I: Integer; 7974 7974 r0, r1: HRgn; 7975 7975 begin 7976 7976 r0 := CreateRectRgn(Left, Top, Rigth, Bottom); 7977 for i:= 0 to ControlCount - 1 do7978 if not(Controls[ i] is TArea) and Controls[i].Visible then7979 begin 7980 with Controls[ i].BoundsRect do7977 for I := 0 to ControlCount - 1 do 7978 if not(Controls[I] is TArea) and Controls[I].Visible then 7979 begin 7980 with Controls[I].BoundsRect do 7981 7981 r1 := CreateRectRgn(Left, Top, Right, Bottom); 7982 7982 CombineRgn(r0, r0, r1, RGN_DIFF); 7983 7983 DeleteObject(r1); 7984 7984 end; 7985 InvalidateRgn(Handle, r0, false);7985 InvalidateRgn(Handle, r0, False); 7986 7986 DeleteObject(r0); 7987 7987 end; … … 8048 8048 procedure TMainScreen.FormClose(Sender: TObject; var Action: TCloseAction); 8049 8049 begin 8050 Timer1.Enabled := false;8050 Timer1.Enabled := False; 8051 8051 end; 8052 8052 8053 8053 procedure TMainScreen.Radio(Sender: TObject); 8054 8054 begin 8055 TMenuItem(Sender).Checked := true;8055 TMenuItem(Sender).Checked := True; 8056 8056 end; 8057 8057 8058 8058 procedure TMainScreen.mManipClick(Sender: TObject); 8059 8059 var 8060 Flag: integer;8060 Flag: Integer; 8061 8061 begin 8062 8062 with TMenuItem(Sender) do … … 8070 8070 Play('CHEAT'); 8071 8071 end; 8072 if not supervising then8072 if not Supervising then 8073 8073 begin 8074 8074 if Flag = tfUncover then 8075 8075 begin 8076 MapValid := false;8076 MapValid := False; 8077 8077 PaintAllMaps; 8078 8078 end … … 8098 8098 else 8099 8099 begin 8100 MapValid := false;8100 MapValid := False; 8101 8101 PaintAllMaps; 8102 8102 end; // update main map … … 8117 8117 end; 8118 8118 SetMapOptions; 8119 MapValid := false;8119 MapValid := False; 8120 8120 PaintAllMaps; 8121 8121 end; … … 8135 8135 end; 8136 8136 SetMapOptions; 8137 MapValid := false;8137 MapValid := False; 8138 8138 PaintAllMaps; 8139 8139 end; 8140 8140 8141 procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: word;8141 procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: Word; 8142 8142 Shift: TShiftState); 8143 8143 begin 8144 if idle and (Key = VK_APPS) then8144 if Idle and (Key = VK_APPS) then 8145 8145 begin 8146 8146 InitPopup(GamePopup); … … 8150 8150 GamePopup.Popup(Left + 4, Top + GetSystemMetrics(SM_CYCAPTION) + 4 + 8151 8151 TopBarHeight - 1); 8152 exit;8152 Exit; 8153 8153 end; // windows menu button calls game menu 8154 8154 end; … … 8156 8156 procedure TMainScreen.CreateUnitClick(Sender: TObject); 8157 8157 var 8158 p1, mix: integer;8158 p1, mix: Integer; 8159 8159 begin 8160 8160 p1 := TComponent(Sender).Tag shr 16; 8161 8161 mix := TComponent(Sender).Tag and $FFFF; 8162 if Server(sCreateUnit + p1 shl 4, me, mix, EditLoc) >= rExecuted then8162 if Server(sCreateUnit + p1 shl 4, Me, mix, EditLoc) >= rExecuted then 8163 8163 PaintLoc(EditLoc); 8164 8164 end; … … 8181 8181 { procedure TMainScreen.AdviceBtnClick; 8182 8182 var 8183 OldAdviceLoc: integer;8184 begin 8185 DestinationMarkON:= false;8183 OldAdviceLoc: Integer; 8184 begin 8185 DestinationMarkON:=False; 8186 8186 PaintDestination; 8187 8187 AdvisorDlg.GiveStrategyAdvice; … … 8193 8193 { procedure TMainScreen.SetAdviceLoc(Loc: integer; AvoidRect: TRect); 8194 8194 var 8195 OldAdviceLoc, x,y: integer;8195 OldAdviceLoc,X,Y: Integer; 8196 8196 begin 8197 8197 if Loc<>MainMap.AdviceLoc then … … 8199 8199 if Loc>=0 then 8200 8200 begin // center 8201 y:=Loc div G.lx;8202 x:=(Loc+G.lx - AvoidRect.Right div (2*66)) mod G.lx;8203 Centre( y*G.lx+x);8201 Y:=Loc div G.lx; 8202 X:=(Loc+G.lx - AvoidRect.Right div (2*66)) mod G.lx; 8203 Centre(Y*G.lx+X); 8204 8204 PaintAllMaps; 8205 8205 end; … … 8259 8259 procedure TMainScreen.SaveMenuItemsState; 8260 8260 var 8261 i, j: integer;8261 I, J: Integer; 8262 8262 begin 8263 8263 if soTellAI in OptionChecked then OptionChecked := [soTellAI] 8264 8264 else OptionChecked := []; 8265 for i:= 0 to ComponentCount - 1 do8266 if Components[ i] is TMenuItem then8267 for j:= 0 to Length(SaveOption) - 1 do8268 if TMenuItem(Components[ i]).Checked and8269 (TMenuItem(Components[ i]).Tag = SaveOption[j]) then8270 OptionChecked := OptionChecked + [TSaveOption( j)];8265 for I := 0 to ComponentCount - 1 do 8266 if Components[I] is TMenuItem then 8267 for J := 0 to Length(SaveOption) - 1 do 8268 if TMenuItem(Components[I]).Checked and 8269 (TMenuItem(Components[I]).Tag = SaveOption[J]) then 8270 OptionChecked := OptionChecked + [TSaveOption(J)]; 8271 8271 end; 8272 8272 … … 8280 8280 with Reg do 8281 8281 try 8282 OpenKey(AppRegistryKey, true);8282 OpenKey(AppRegistryKey, True); 8283 8283 WriteInteger('TileSize', Integer(MainMap.TileSize)); 8284 8284 WriteInteger('OptionChecked', Integer(OptionChecked)); 8285 8285 WriteInteger('MapOptionChecked', Integer(MapOptionChecked)); 8286 WriteInteger('CityReport', integer(CityRepMask));8286 WriteInteger('CityReport', Integer(CityRepMask)); 8287 8287 finally 8288 8288 Free; -
trunk/LocalPlayer/Tribes.pas
r438 r447 49 49 constructor Create(FileName: string); 50 50 destructor Destroy; override; 51 function GetCityName( i: Integer): string;52 {$IFNDEF SCR} procedure SetCityName( i: Integer; NewName: string); {$ENDIF}51 function GetCityName(I: Integer): string; 52 {$IFNDEF SCR} procedure SetCityName(I: Integer; NewName: string); {$ENDIF} 53 53 {$IFNDEF SCR} function TString(Template: string): string; 54 54 function TPhrase(Item: string): string; {$ENDIF} … … 74 74 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string); 75 75 function GetTribeInfo(FileName: string; var Name: string; var Color: TColor): Boolean; 76 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;76 procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor; 77 77 var xp, yp: Integer); 78 78 … … 215 215 function Get: string; 216 216 var 217 p: Integer;217 P: Integer; 218 218 begin 219 219 while (Input <> '') and ((Input[1] = ' ') or (Input[1] = #9)) do 220 220 Delete(Input, 1, 1); 221 p:= Pos(',', Input);222 if p= 0 then223 p:= Length(Input) + 1;224 Result := Copy(Input, 1, p- 1);225 Delete(Input, 1, p);221 P := Pos(',', Input); 222 if P = 0 then 223 P := Length(Input) + 1; 224 Result := Copy(Input, 1, P - 1); 225 Delete(Input, 1, P); 226 226 end; 227 227 228 228 function GetNum: Integer; 229 229 var 230 i: Integer;231 begin 232 Val(Get, Result, i);233 if i<> 0 then230 I: Integer; 231 begin 232 Val(Get, Result, I); 233 if I <> 0 then 234 234 Result := 0; 235 235 end; … … 237 237 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string); 238 238 var 239 i: Integer;240 begin 241 for i:= 0 to StdUnitScript.Count - 1 do239 I: Integer; 240 begin 241 for I := 0 to StdUnitScript.Count - 1 do 242 242 begin // look through StdUnits 243 Input := StdUnitScript[ i];243 Input := StdUnitScript[I]; 244 244 pix := GetNum; 245 245 if Code = GetNum then … … 340 340 end; 341 341 342 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;342 procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor; 343 343 var xp, yp: Integer); 344 344 begin 345 345 xp := 0; 346 while (xp < xmax) and (HGr.Data.Canvas.Pixels[ x + 1 + xp, y] <> Mark) do346 while (xp < xmax) and (HGr.Data.Canvas.Pixels[X + 1 + xp, Y] <> Mark) do 347 347 Inc(xp); 348 348 yp := 0; 349 while (yp < ymax) and (HGr.Data.Canvas.Pixels[ x, y+ 1 + yp] <> Mark) do349 while (yp < ymax) and (HGr.Data.Canvas.Pixels[X, Y + 1 + yp] <> Mark) do 350 350 Inc(yp); 351 351 end; 352 352 353 function TTribe.GetCityName( i: Integer): string;353 function TTribe.GetCityName(I: Integer): string; 354 354 begin 355 355 Result := ''; 356 if nCityLines > ithen357 begin 358 Result := Script[CityLine0 + i];356 if nCityLines > I then 357 begin 358 Result := Script[CityLine0 + I]; 359 359 while (Result <> '') and ((Result[1] = ' ') or (Result[1] = #9)) do 360 360 Delete(Result, 1, 1); … … 362 362 {$IFNDEF SCR} 363 363 else 364 Result := Format(TPhrase('GENCITY'), [ i+ 1]);364 Result := Format(TPhrase('GENCITY'), [I + 1]); 365 365 {$ENDIF} 366 366 end; 367 367 368 368 {$IFNDEF SCR} 369 procedure TTribe.SetCityName( i: Integer; NewName: string);370 begin 371 while nCityLines <= ido369 procedure TTribe.SetCityName(I: Integer; NewName: string); 370 begin 371 while nCityLines <= I do 372 372 begin 373 373 Script.Insert(CityLine0 + nCityLines, Format(TPhrase('GENCITY'), … … 375 375 Inc(nCityLines); 376 376 end; 377 Script[CityLine0 + i] := NewName;377 Script[CityLine0 + I] := NewName; 378 378 end; 379 379 380 380 function TTribe.TString(Template: string): string; 381 381 var 382 p: Integer;382 P: Integer; 383 383 Variant: Char; 384 384 CaseUp: Boolean; 385 385 begin 386 386 repeat 387 p := pos('#', Template);388 if ( p = 0) or (p= Length(Template)) then387 P := Pos('#', Template); 388 if (P = 0) or (P = Length(Template)) then 389 389 Break; 390 Variant := Template[ p+ 1];390 Variant := Template[P + 1]; 391 391 CaseUp := Variant in ['A' .. 'Z']; 392 392 if CaseUp then 393 393 Inc(Variant, 32); 394 Delete(Template, p, 2);394 Delete(Template, P, 2); 395 395 if Variant in ['a' .. 'z'] then 396 396 begin 397 397 if NumberName < 0 then 398 Insert(Name[Variant], Template, p)398 Insert(Name[Variant], Template, P) 399 399 else 400 Insert(Format('P%d', [NumberName]), Template, p);401 if CaseUp and (Length(Template) >= p) and402 (Template[ p] in ['a' .. 'z', #$E0 .. #$FF]) then403 Dec(Template[ p], 32);400 Insert(Format('P%d', [NumberName]), Template, P); 401 if CaseUp and (Length(Template) >= P) and 402 (Template[P] in ['a' .. 'z', #$E0 .. #$FF]) then 403 Dec(Template[P], 32); 404 404 end 405 405 until False; … … 418 418 TLine = array [0 .. 649, 0 .. 2] of Byte; 419 419 var 420 i, x, Gray: Integer;420 I, X, Gray: Integer; 421 421 Item: string; 422 422 begin … … 426 426 with Script do 427 427 begin 428 i:= 0;429 while ( i < Count) and (Copy(Strings[i], 1, 6) <>428 I := 0; 429 while (I < Count) and (Copy(Strings[I], 1, 6) <> 430 430 '#AGE' + char(48 + Age) + ' ') do 431 Inc( i);432 if i< Count then433 begin 434 Input := Strings[ i];431 Inc(I); 432 if I < Count then 433 begin 434 Input := Strings[I]; 435 435 system.Delete(Input, 1, 6); 436 436 Item := Get; … … 448 448 end; 449 449 cHGr := LoadGraphicSet(Item + '.png'); 450 for x:= 0 to 3 do451 with CityPicture[ x] do begin452 FindPosition(cHGr, x* 65, cpix * 49, 63, 47, $00FFFF,450 for X := 0 to 3 do 451 with CityPicture[X] do begin 452 FindPosition(cHGr, X * 65, cpix * 49, 63, 47, $00FFFF, 453 453 xShield, yShield); 454 454 // FindPosition(cHGr,x*65,cpix*49,$FFFFFF,xf,yf); … … 486 486 procedure TTribe.SetModelPicture(const Info: TModelPictureInfo; IsNew: Boolean); 487 487 var 488 i: Integer;488 I: Integer; 489 489 ok: Boolean; 490 490 begin … … 493 493 if not IsNew then 494 494 begin 495 i:= nPictureList - 1;496 while ( i >= 0) and (PictureList[i].Hash <> Info.Hash) do497 Dec( i);498 assert(i>= 0);499 assert(PictureList[i].HGr = LoadGraphicSet(GrName));500 assert(PictureList[i].pix = pix);501 ModelPicture[mix].HGr := PictureList[ i].HGr;502 ModelPicture[mix].pix := PictureList[ i].pix;503 ModelName[mix] := PictureList[ i].ModelName;495 I := nPictureList - 1; 496 while (I >= 0) and (PictureList[I].Hash <> Info.Hash) do 497 Dec(I); 498 Assert(I >= 0); 499 Assert(PictureList[I].HGr = LoadGraphicSet(GrName)); 500 Assert(PictureList[I].pix = pix); 501 ModelPicture[mix].HGr := PictureList[I].HGr; 502 ModelPicture[mix].pix := PictureList[I].pix; 503 ModelName[mix] := PictureList[I].ModelName; 504 504 end 505 505 else … … 515 515 // read model name from tribe script 516 516 ok := False; 517 for i:= 0 to Script.Count - 1 do518 begin 519 Input := Script[ i];517 for I := 0 to Script.Count - 1 do 518 begin 519 Input := Script[I]; 520 520 if Input = '#UNITS ' + ExtractFileNameOnly(GrName) then 521 521 ok := True … … 531 531 if ModelName[mix] = '' then 532 532 begin // read model name from StdUnits.txt 533 for i:= 0 to StdUnitScript.Count - 1 do533 for I := 0 to StdUnitScript.Count - 1 do 534 534 begin 535 Input := StdUnitScript[ i];535 Input := StdUnitScript[I]; 536 536 if GetNum = pix then 537 537 begin … … 567 567 Code, Turn: Integer; ForceNew: Boolean): Boolean; 568 568 var 569 i: Integer;569 I: Integer; 570 570 Cnt: Integer; 571 571 HGr: TGraphicSet; … … 606 606 if not ForceNew and (Picture.Hash > 0) then 607 607 begin 608 for i:= 0 to nPictureList - 1 do609 if PictureList[ i].Hash = Picture.Hash then610 begin 611 Picture.GrName := PictureList[ i].HGr.Name;612 Picture.pix := PictureList[ i].pix;608 for I := 0 to nPictureList - 1 do 609 if PictureList[I].Hash = Picture.Hash then 610 begin 611 Picture.GrName := PictureList[I].HGr.Name; 612 Picture.pix := PictureList[I].pix; 613 613 Result := False; 614 614 Exit; … … 622 622 TestPic.GrName := 'StdUnits.png'; 623 623 HGr := HGrStdUnits; 624 for i:= 0 to StdUnitScript.Count - 1 do624 for I := 0 to StdUnitScript.Count - 1 do 625 625 begin // look through StdUnits 626 Input := StdUnitScript[ i];626 Input := StdUnitScript[I]; 627 627 Check; 628 628 end; 629 629 630 630 ok := False; 631 for i:= 0 to Script.Count - 1 do631 for I := 0 to Script.Count - 1 do 632 632 begin // look through units defined in tribe script 633 Input := Script[ i];633 Input := Script[I]; 634 634 if Copy(Input, 1, 6) = '#UNITS' then 635 635 begin -
trunk/LocalPlayer/UKeyBindings.pas
r424 r447 397 397 end. 398 398 399 -
trunk/LocalPlayer/UnitStat.pas
r442 r447 28 28 public 29 29 procedure CheckAge; 30 procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);31 procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);32 procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);33 procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);34 procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);35 procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);30 procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer); 31 procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer); 32 procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer); 33 procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer); 34 procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer); 35 procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer); 36 36 37 37 protected 38 38 mixShow, // for dkOwnModel 39 uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: integer;39 uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: Integer; 40 40 // for dkEnemyUnit, euixShow=-1 -> 41 41 mox: ^TModelInfo; // for dkEnemyModel … … 121 121 procedure TUnitStatDlg.FormShow(Sender: TObject); 122 122 var 123 owner, mix: integer;124 IsSpecialUnit: boolean;123 owner, mix: Integer; 124 IsSpecialUnit: Boolean; 125 125 begin 126 126 if Kind in [dkEnemyUnit, dkEnemyCityDefense, dkEnemyCity] then … … 132 132 euixShow := MyRO.nEnemyUn - 1; 133 133 while (euixShow >= 0) and (MyRO.EnemyUn[euixShow].Loc <> UnitLoc) do 134 dec(euixShow);135 assert(euixShow >= 0);134 Dec(euixShow); 135 Assert(euixShow >= 0); 136 136 end; 137 137 with MyRO.EnemyUn[euixShow] do … … 148 148 ecixShow := MyRO.nEnemyCity - 1; 149 149 while (ecixShow >= 0) and (MyRO.EnemyCity[ecixShow].Loc <> UnitLoc) do 150 dec(ecixShow);151 assert(ecixShow >= 0);150 Dec(ecixShow); 151 Assert(ecixShow >= 0); 152 152 end; 153 153 end; … … 178 178 end; 179 179 180 SwitchBtn.Visible := not supervising and (Kind = dkOwnModel);181 ConscriptsBtn.Visible := not supervising and (Kind = dkOwnModel) and180 SwitchBtn.Visible := not Supervising and (Kind = dkOwnModel); 181 ConscriptsBtn.Visible := not Supervising and (Kind = dkOwnModel) and 182 182 (MyRO.Tech[adConscription] >= tsApplicable) and 183 183 (MyModel[mixShow].Domain = dGround) and (MyModel[mixShow].Kind < mkScout); 184 IsSpecialUnit := false;184 IsSpecialUnit := False; 185 185 if Kind in [dkEnemyCity, dkEnemyCityDefense] then 186 186 Caption := CityName(MyRO.EnemyCity[ecixShow].ID) … … 190 190 dkOwnModel: 191 191 begin 192 owner := me;192 owner := Me; 193 193 mix := mixShow; 194 194 IsSpecialUnit := MyModel[mix].Kind >= $10; … … 196 196 dkOwnUnit: 197 197 begin 198 owner := me;198 owner := Me; 199 199 mix := MyUn[uixShow].mix; 200 200 IsSpecialUnit := MyModel[mix].Kind >= $10; … … 218 218 end; 219 219 220 procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);220 procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer); 221 221 begin 222 222 Kind := dkOwnModel; … … 225 225 end; 226 226 227 procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);227 procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer); 228 228 begin 229 229 Kind := dkOwnUnit; … … 232 232 end; 233 233 234 procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);234 procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer); 235 235 begin 236 236 Kind := dkEnemyUnit; … … 240 240 end; 241 241 242 procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);242 procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer); 243 243 begin 244 244 Kind := dkEnemyUnit; … … 248 248 end; 249 249 250 procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);250 procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer); 251 251 begin 252 252 Kind := dkEnemyModel; … … 255 255 end; 256 256 257 procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);257 procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer); 258 258 begin 259 259 if MyMap[Loc] and fUnit <> 0 then … … 286 286 PPicture: ^TModelPicture; 287 287 288 function IsToCount(emix: integer): boolean;288 function IsToCount(emix: Integer): Boolean; 289 289 var 290 290 PTestPicture: ^TModelPicture; … … 294 294 PTestPicture := @Tribe[MyRO.EnemyModel[emix].owner].ModelPicture 295 295 [MyRO.EnemyModel[emix].mix]; 296 result := (PPicture.HGr = PTestPicture.HGr) and296 Result := (PPicture.HGr = PTestPicture.HGr) and 297 297 (PPicture.pix = PTestPicture.pix) and 298 298 (ModelHash(mox^) = ModelHash(MyRO.EnemyModel[emix])); 299 299 end 300 300 else 301 result := (MyRO.EnemyModel[emix].owner = mox.owner) and301 Result := (MyRO.EnemyModel[emix].owner = mox.owner) and 302 302 (MyRO.EnemyModel[emix].mix = mox.mix); 303 303 end; 304 304 305 procedure FeatureBar(dst: TBitmap; x, y: integer; const mi: TModelInfo;305 procedure FeatureBar(dst: TBitmap; X, Y: Integer; const mi: TModelInfo; 306 306 T: TTexture); 307 307 var 308 i, w, dx, num: integer;309 s: string;310 begin 311 DarkGradient(dst.Canvas, x - 6, y+ 1, 180, 1);308 I, W, dx, num: Integer; 309 S: string; 310 begin 311 DarkGradient(dst.Canvas, X - 6, Y + 1, 180, 1); 312 312 with dst.Canvas do 313 313 if mi.Kind >= $10 then 314 314 begin 315 s:= Phrases.Lookup('UNITSPECIAL');315 S := Phrases.Lookup('UNITSPECIAL'); 316 316 Font.Color := $000000; 317 Textout( x - 1, y + 1, s);317 Textout(X - 1, Y + 1, S); 318 318 Font.Color := $B0B0B0; 319 Textout( x - 2, y, s);319 Textout(X - 2, Y, S); 320 320 end 321 321 else … … 323 323 Font.Color := $000000; 324 324 dx := 2; 325 for i:= 3 to nFeature - 1 do325 for I := 3 to nFeature - 1 do 326 326 begin 327 327 num := 0; 328 case iof328 case I of 329 329 mcSeaTrans: 330 330 if mi.Domain = dSea then … … 342 342 num := mi.TTrans; 343 343 mcFirstNonCap .. nFeature - 1: 344 if mi.Cap and (1 shl ( i- mcFirstNonCap)) <> 0 then344 if mi.Cap and (1 shl (I - mcFirstNonCap)) <> 0 then 345 345 num := 1 346 346 end; 347 347 if (num > 0) and 348 (( i<> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))348 ((I <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0)) 349 349 then 350 350 begin 351 351 if num > 1 then 352 352 begin 353 s:= IntToStr(num);354 w := TextWidth(s);353 S := IntToStr(num); 354 W := TextWidth(S); 355 355 Brush.Color := $FFFFFF; 356 FillRect(Rect( x - 3 + dx, y + 2, x + w - 1 + dx, y+ 16));356 FillRect(Rect(X - 3 + dx, Y + 2, X + W - 1 + dx, Y + 16)); 357 357 Brush.Style := bsClear; 358 Textout( x - 3 + dx + 1, y, s);359 inc(dx, w+ 1)358 Textout(X - 3 + dx + 1, Y, S); 359 Inc(dx, W + 1) 360 360 end; 361 361 Brush.Color := $C0C0C0; 362 FrameRect(Rect( x - 3 + dx, y + 2, x + 11 + dx, y+ 16));362 FrameRect(Rect(X - 3 + dx, Y + 2, X + 11 + dx, Y + 16)); 363 363 Brush.Style := bsClear; 364 Sprite(dst, HGrSystem, x - 1 + dx, y+ 4, 10, 10,365 66 + i mod 11 * 11, 137 + idiv 11 * 11);366 inc(dx, 15)364 Sprite(dst, HGrSystem, X - 1 + dx, Y + 4, 10, 10, 365 66 + I mod 11 * 11, 137 + I div 11 * 11); 366 Inc(dx, 15) 367 367 end; 368 368 end; … … 370 370 end; { featurebar } 371 371 372 procedure NumberBarS(dst: TBitmap; x, y: integer; Cap, s: string; T: TTexture);373 begin 374 DLine(dst.Canvas, x - 2, x + 170, y+ 16, T.ColorBevelShade, T.ColorBevelLight);375 LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);376 RisedTextout(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas, s), y, s);372 procedure NumberBarS(dst: TBitmap; X, Y: Integer; Cap, S: string; T: TTexture); 373 begin 374 DLine(dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade, T.ColorBevelLight); 375 LoweredTextOut(dst.Canvas, -1, T, X - 2, Y, Cap); 376 RisedTextout(dst.Canvas, X + 170 - BiColorTextWidth(dst.Canvas, S), Y, S); 377 377 end; 378 378 379 379 var 380 i, j, x, y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,381 yTotal, yCaption: integer;382 s: string;380 I, J, X, Y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView, 381 yTotal, yCaption: Integer; 382 S: string; 383 383 ui: TUnitInfo; 384 384 mi: TModelInfo; … … 389 389 dkOwnModel: 390 390 begin 391 BitBltCanvas( offscreen.Canvas, 0, 0, wCommon, hOwnModel,391 BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hOwnModel, 392 392 Back.Canvas, 0, 0); 393 393 yView := 13; … … 396 396 dkEnemyModel: 397 397 begin 398 BitBltCanvas( offscreen.Canvas, 0, 0, wCommon, hEnemyModel,398 BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyModel, 399 399 Back.Canvas, wCommon, 0); 400 400 yView := 13; … … 403 403 dkEnemyUnit, dkOwnUnit: 404 404 begin 405 BitBltCanvas( offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,405 BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyUnit, 406 406 Back.Canvas, 2 * wCommon, 0); 407 407 yView := 13; … … 410 410 dkEnemyCityDefense: 411 411 begin 412 BitBltCanvas( offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,412 BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense, 413 413 Back.Canvas, 3 * wCommon, 0); 414 414 yView := 171; … … 417 417 dkEnemyCity: 418 418 begin 419 BitBltCanvas( offscreen.Canvas, 0, 0, wCommon, hEnemyCity,419 BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCity, 420 420 Back.Canvas, 4 * wCommon, 0); 421 421 end; … … 427 427 begin // show city defense facilities 428 428 Cnt := 0; 429 for i:= 0 to 3 do430 if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then431 inc(Cnt);432 x:= (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;433 for i:= 0 to 3 do434 if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then435 begin 436 case iof437 0: j:= imWalls;438 1: j:= imCoastalFort;439 2: j:= imMissileBat;440 3: j:= imBunker429 for I := 0 to 3 do 430 if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then 431 Inc(Cnt); 432 X := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2; 433 for I := 0 to 3 do 434 if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then 435 begin 436 case I of 437 0: J := imWalls; 438 1: J := imCoastalFort; 439 2: J := imMissileBat; 440 3: J := imBunker 441 441 end; 442 Frame( offscreen.Canvas, x - 1, yImp - 1, x+ xSizeSmall,442 Frame(Offscreen.Canvas, X - 1, yImp - 1, X + xSizeSmall, 443 443 yImp + ySizeSmall, MainTexture.ColorBevelLight, 444 444 MainTexture.ColorBevelShade); 445 BitBltCanvas( offscreen.Canvas, x, yImp, xSizeSmall, ySizeSmall,446 SmallImp.Canvas, jmod 7 * xSizeSmall,447 ( j+ SystemIconLines * 7) div 7 * ySizeSmall);448 inc(x, xSizeSmall + 4);445 BitBltCanvas(Offscreen.Canvas, X, yImp, xSizeSmall, ySizeSmall, 446 SmallImp.Canvas, J mod 7 * xSizeSmall, 447 (J + SystemIconLines * 7) div 7 * ySizeSmall); 448 Inc(X, xSizeSmall + 4); 449 449 end; 450 450 end; … … 454 454 PPicture := @Tribe[mox.owner].ModelPicture[mox.mix]; 455 455 Available := 0; 456 if G.Difficulty[ me] = 0 then // supervisor -- count stacked units too456 if G.Difficulty[Me] = 0 then // supervisor -- count stacked units too 457 457 for Loc := 0 to G.lx * G.ly - 1 do 458 458 begin 459 459 if MyMap[Loc] and fUnit <> 0 then 460 460 begin 461 Server(sGetUnits, me, Loc, Cnt);461 Server(sGetUnits, Me, Loc, Cnt); 462 462 for uix := 0 to Cnt - 1 do 463 463 if IsToCount(MyRO.EnemyUn[MyRO.nEnemyUn + uix].emix) then 464 inc(Available);464 Inc(Available); 465 465 end; 466 466 end … … 469 469 if (MyRO.EnemyUn[uix].Loc >= 0) and IsToCount(MyRO.EnemyUn[uix].emix) 470 470 then 471 inc(Available);471 Inc(Available); 472 472 Destroyed := 0; 473 473 for emix := 0 to MyRO.nEnemyModel - 1 do 474 474 if IsToCount(emix) then 475 inc(Destroyed, MyRO.EnemyModel[emix].Lost);475 Inc(Destroyed, MyRO.EnemyModel[emix].Lost); 476 476 end 477 477 else … … 480 480 for uix := 0 to MyRO.nUn - 1 do 481 481 if (MyUn[uix].Loc >= 0) and (MyUn[uix].mix = mixShow) then 482 inc(Available);482 Inc(Available); 483 483 InProd := 0; 484 484 for cix := 0 to MyRO.nCity - 1 do 485 485 if (MyCity[cix].Loc >= 0) and 486 486 (MyCity[cix].Project and (cpImp + cpIndex) = mixShow) then 487 inc(InProd);488 end; 489 490 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);487 Inc(InProd); 488 end; 489 490 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 491 491 if Kind in [dkEnemyCityDefense, dkEnemyCity] then 492 492 begin 493 NoMap.SetOutput( offscreen);494 NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], false);495 496 s:= Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');497 LoweredTextOut( offscreen.Canvas, -1, MainTexture,498 (ClientWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2, 105, s);493 NoMap.SetOutput(Offscreen); 494 NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], False); 495 496 S := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER'); 497 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 498 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 105, S); 499 499 end; 500 500 … … 502 502 begin // show unit stats 503 503 if Kind = dkOwnModel then 504 MakeModelInfo( me, mixShow, MyModel[mixShow], mi)504 MakeModelInfo(Me, mixShow, MyModel[mixShow], mi) 505 505 else if Kind = dkOwnUnit then 506 506 begin 507 MakeUnitInfo( me, MyUn[uixShow], ui);508 MakeModelInfo( me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);507 MakeUnitInfo(Me, MyUn[uixShow], ui); 508 MakeModelInfo(Me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi); 509 509 end 510 510 else … … 522 522 { Frame(offscreen.canvas,xView-1,yView-1,xView+64,yView+48, 523 523 MainTexture.ColorBevelShade,MainTexture.ColorBevelLight); 524 RFrame( offscreen.canvas,xView-2,yView-2,xView+65,yView+49,524 RFrame(Offscreen.Canvas,xView-2,yView-2,xView+65,yView+49, 525 525 MainTexture.ColorBevelShade,MainTexture.ColorBevelLight); } 526 with offscreen.Canvas do526 with Offscreen.Canvas do 527 527 begin 528 528 Brush.Color := HGrSystem.Data.Canvas.Pixels[98, 67]; 529 offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,529 Offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64, 530 530 yView + 16)); 531 531 Brush.Style := bsClear; … … 534 534 if MyMap[Loc] and fTerrain >= fForest then 535 535 begin 536 x:= 1 + 2 * (xxt * 2 + 1);537 y:= 1 + yyt + 2 * (yyt * 3 + 1);536 X := 1 + 2 * (xxt * 2 + 1); 537 Y := 1 + yyt + 2 * (yyt * 3 + 1); 538 538 end 539 539 else 540 540 begin 541 x := integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;542 y:= 1 + yyt;541 X := Integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1; 542 Y := 1 + yyt; 543 543 end; 544 for j:= -1 to 1 do545 for i:= -1 to 1 do546 if ( i + j) and 1 = 0 then544 for J := -1 to 1 do 545 for I := -1 to 1 do 546 if (I + J) and 1 = 0 then 547 547 begin 548 Sprite(Buffer, HGrTerrain, i * xxt, j* yyt, xxt * 2,549 yyt * 2, x, y);548 Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, 549 yyt * 2, X, Y); 550 550 if MyMap[Loc] and (fTerrain or fSpecial) = fGrass or fSpecial1 551 551 then 552 Sprite(Buffer, HGrTerrain, i * xxt, j* yyt, xxt * 2, yyt * 2,552 Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2, 553 553 1 + 2 * (xxt * 2 + 1), 1 + yyt + 1 * (yyt * 3 + 1)) 554 554 else if (MyMap[Loc] and fTerrain = fForest) and 555 555 IsJungle(Loc div G.lx) then 556 Sprite(Buffer, HGrTerrain, i * xxt, j* yyt, xxt * 2, yyt * 2,556 Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2, 557 557 1 + 7 * (xxt * 2 + 1), 1 + yyt + 19 * (yyt * 3 + 1)) 558 558 else if MyMap[Loc] and fTerrain >= fForest then 559 Sprite(Buffer, HGrTerrain, i * xxt, j* yyt, xxt * 2, yyt * 2,559 Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2, 560 560 1 + 7 * (xxt * 2 + 1), 561 1 + yyt + 2 * integer(2 + MyMap[Loc] and fTerrain - fForest)561 1 + yyt + 2 * Integer(2 + MyMap[Loc] and fTerrain - fForest) 562 562 * (yyt * 3 + 1)); 563 563 end; 564 BitBltCanvas( offscreen.Canvas, xView, yView + 16, 64, 32,564 BitBltCanvas(Offscreen.Canvas, xView, yView + 16, 64, 32, 565 565 Buffer.Canvas, 1, 0); 566 566 567 567 // show unit, experience and health 568 Sprite( offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,568 Sprite(Offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1, 569 569 pix div 10 * 49 + 1); 570 570 if Flags and unFortified <> 0 then 571 Sprite( offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,571 Sprite(Offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2, 572 572 1 + 6 * (xxu * 2 + 1), 1); 573 FrameImage( offscreen.Canvas, HGrSystem.Data, xView - 20,573 FrameImage(Offscreen.Canvas, HGrSystem.Data, xView - 20, 574 574 yView + 5, 12, 14, 121 + Exp div ExpCost * 13, 28); 575 575 if Health < 100 then 576 576 begin 577 s:= IntToStr(Health) + '%';578 LightGradient( offscreen.Canvas, xView - 45, yView + 24, 38,577 S := IntToStr(Health) + '%'; 578 LightGradient(Offscreen.Canvas, xView - 45, yView + 24, 38, 579 579 (ColorOfHealth(Health) and $FEFEFE shr 2) * 3); 580 RisedTextout( offscreen.Canvas, xView - 45 + 20 -581 BiColorTextWidth( offscreen.Canvas, s) div 2, yView + 23, s);580 RisedTextout(Offscreen.Canvas, xView - 45 + 20 - 581 BiColorTextWidth(Offscreen.Canvas, S) div 2, yView + 23, S); 582 582 end; 583 583 584 584 if Kind = dkEnemyUnit then 585 585 begin 586 s:= Tribe[mox.owner].TPhrase('UNITOWNER');587 LoweredTextOut( offscreen.Canvas, -1, MainTexture,588 (ClientWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2,589 yView + 80, s);586 S := Tribe[mox.owner].TPhrase('UNITOWNER'); 587 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 588 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 589 yView + 80, S); 590 590 end; 591 591 end 592 592 else 593 593 begin 594 FrameImage( offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);595 Sprite( offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,594 FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0); 595 Sprite(Offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1, 596 596 pix div 10 * 49 + 1); 597 597 end; 598 598 599 DarkGradient( offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);600 RisedTextout( offscreen.Canvas, xTotal - 2, yTotal,599 DarkGradient(Offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2); 600 RisedTextout(Offscreen.Canvas, xTotal - 2, yTotal, 601 601 Phrases.Lookup('UNITSTRENGTH')); 602 s:= IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);603 RisedTextout( offscreen.Canvas,604 xTotal + 170 - BiColorTextWidth( offscreen.Canvas, s), yTotal, s);605 FeatureBar( offscreen, xTotal, yTotal + 19, mi, MainTexture);606 NumberBarS( offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),602 S := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense); 603 RisedTextout(Offscreen.Canvas, 604 xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S), yTotal, S); 605 FeatureBar(Offscreen, xTotal, yTotal + 19, mi, MainTexture); 606 NumberBarS(Offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'), 607 607 MovementToString(mi.Speed), MainTexture); 608 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,608 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57, 609 609 Phrases.Lookup('UNITCOST')); 610 DLine( offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,610 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16, 611 611 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 612 if G.Difficulty[ me] = 0 then613 s:= IntToStr(mi.cost)612 if G.Difficulty[Me] = 0 then 613 S := IntToStr(mi.cost) 614 614 else 615 s := IntToStr(mi.cost * BuildCostMod[G.Difficulty[me]] div 12);616 RisedTextout( offscreen.Canvas,617 xTotal + 159 - BiColorTextWidth( offscreen.Canvas, s), yTotal + 57, s);618 Sprite( offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,615 S := IntToStr(mi.cost * BuildCostMod[G.Difficulty[Me]] div 12); 616 RisedTextout(Offscreen.Canvas, 617 xTotal + 159 - BiColorTextWidth(Offscreen.Canvas, S), yTotal + 57, S); 618 Sprite(Offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10, 619 619 10, 88, 115); 620 620 … … 624 624 begin 625 625 if MyModel[mixShow].Kind = mkEnemyDeveloped then 626 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2,626 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, 627 627 (yTotal + StatDown - 19), Phrases.Lookup('UNITADOPT')) 628 628 else 629 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2,629 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, 630 630 (yTotal + StatDown - 19), Phrases.Lookup('UNITINTRO')); 631 DLine( offscreen.Canvas, xTotal - 2, xTotal + 170,631 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170, 632 632 (yTotal + StatDown - 19) + 16, MainTexture.ColorTextShade, 633 633 MainTexture.ColorTextLight); 634 s:= TurnToString(MyModel[mixShow].IntroTurn);635 RisedTextout( offscreen.Canvas,636 xTotal + 170 - BiColorTextWidth( offscreen.Canvas, s),637 (yTotal + StatDown - 19), s);634 S := TurnToString(MyModel[mixShow].IntroTurn); 635 RisedTextout(Offscreen.Canvas, 636 xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S), 637 (yTotal + StatDown - 19), S); 638 638 end; 639 639 640 NumberBar( offscreen, xTotal, yTotal + StatDown,640 NumberBar(Offscreen, xTotal, yTotal + StatDown, 641 641 Phrases.Lookup('UNITBUILT'), MyModel[mixShow].Built, MainTexture); 642 642 if MyModel[mixShow].Lost > 0 then 643 NumberBar( offscreen, xTotal, yTotal + StatDown + 19,643 NumberBar(Offscreen, xTotal, yTotal + StatDown + 19, 644 644 Phrases.Lookup('UNITLOST'), MyModel[mixShow].Lost, MainTexture); 645 645 if InProd > 0 then 646 NumberBar( offscreen, xTotal, yTotal + StatDown + 57,646 NumberBar(Offscreen, xTotal, yTotal + StatDown + 57, 647 647 Phrases.Lookup('UNITINPROD'), InProd, MainTexture); 648 648 if Available > 0 then 649 NumberBar( offscreen, xTotal, yTotal + StatDown + 38,649 NumberBar(Offscreen, xTotal, yTotal + StatDown + 38, 650 650 Phrases.Lookup('UNITAVAILABLE'), Available, MainTexture); 651 651 … … 674 674 begin 675 675 if Destroyed > 0 then 676 NumberBar( offscreen, xTotal, yTotal + StatDown - 19,676 NumberBar(Offscreen, xTotal, yTotal + StatDown - 19, 677 677 Phrases.Lookup('UNITDESTROYED'), Destroyed, MainTexture); 678 678 if Available > 0 then 679 NumberBar( offscreen, xTotal, yTotal + StatDown,679 NumberBar(Offscreen, xTotal, yTotal + StatDown, 680 680 Phrases.Lookup('UNITKNOWN'), Available, MainTexture); 681 681 end; … … 683 683 end; 684 684 685 offscreen.Canvas.Font.Assign(UniFont[ftNormal]);685 Offscreen.Canvas.Font.Assign(UniFont[ftNormal]); 686 686 case Kind of 687 687 dkOwnModel, dkEnemyModel: … … 692 692 yCaption := 79; 693 693 end; 694 RisedTextout( offscreen.Canvas,695 (ClientWidth - BiColorTextWidth( offscreen.Canvas, Caption)) div 2,694 RisedTextout(Offscreen.Canvas, 695 (ClientWidth - BiColorTextWidth(Offscreen.Canvas, Caption)) div 2, 696 696 yCaption, Caption); 697 697 end; -
trunk/LocalPlayer/Wonders.pas
r442 r447 23 23 Selection: Integer; 24 24 Center: TPoint; 25 procedure DarkIcon( i: Integer);26 procedure Glow( i, GlowColor: Integer);25 procedure DarkIcon(I: Integer); 26 procedure Glow(I, GlowColor: Integer); 27 27 procedure PaintBackgroundShape; 28 28 public … … 116 116 for Y := 0 to Height - 1 do begin 117 117 for X := 0 to Width - 1 do begin 118 r:= X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));118 R := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4)); 119 119 ax := ((1 shl 16 div (Height div 4)) * (Width div 4)) * Y; 120 if ( r< ScaleToNative(8) * Height * Width * Width) and121 (( r>= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and120 if (R < ScaleToNative(8) * Height * Width * Width) and 121 ((R >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and 122 122 ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and 123 123 ((ax < amax1 * X) or (ax > amin3 * X))) then begin 124 124 for ch := 0 to 2 do begin 125 c:= Line[0].Pixel^.Planes[ch] - Darken;126 if c< 0 then Line[0].Pixel^.Planes[ch] := 0127 else Line[0].Pixel^.Planes[ch] := c;128 c:= Line[1].Pixel^.Planes[ch] - Darken;129 if c< 0 then Line[1].Pixel^.Planes[ch] := 0130 else Line[1].Pixel^.Planes[ch] := c;131 c:= Line[2].Pixel^.Planes[ch] - Darken;132 if c< 0 then Line[2].Pixel^.Planes[ch] := 0133 else Line[2].Pixel^.Planes[ch] := c;134 c:= Line[3].Pixel^.Planes[ch] - Darken;135 if c< 0 then Line[3].Pixel^.Planes[ch] := 0136 else Line[3].Pixel^.Planes[ch] := c;125 C := Line[0].Pixel^.Planes[ch] - Darken; 126 if C < 0 then Line[0].Pixel^.Planes[ch] := 0 127 else Line[0].Pixel^.Planes[ch] := C; 128 C := Line[1].Pixel^.Planes[ch] - Darken; 129 if C < 0 then Line[1].Pixel^.Planes[ch] := 0 130 else Line[1].Pixel^.Planes[ch] := C; 131 C := Line[2].Pixel^.Planes[ch] - Darken; 132 if C < 0 then Line[2].Pixel^.Planes[ch] := 0 133 else Line[2].Pixel^.Planes[ch] := C; 134 C := Line[3].Pixel^.Planes[ch] - Darken; 135 if C < 0 then Line[3].Pixel^.Planes[ch] := 0 136 else Line[3].Pixel^.Planes[ch] := C; 137 137 end; 138 138 end; … … 150 150 end; 151 151 152 procedure TWondersDlg.DarkIcon( i: Integer);153 var 154 X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;152 procedure TWondersDlg.DarkIcon(I: Integer); 153 var 154 X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, C: Integer; 155 155 Src, Dst: TPixelPointer; 156 156 begin 157 157 Offscreen.BeginUpdate; 158 x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[ i].X;159 y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[ i].Y;160 x0Src := ( imod 7) * xSizeBig;161 y0Src := ( idiv 7 + SystemIconLines) * ySizeBig;158 x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X; 159 y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y; 160 x0Src := (I mod 7) * xSizeBig; 161 y0Src := (I div 7 + SystemIconLines) * ySizeBig; 162 162 Src := PixelPointer(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src)); 163 163 Dst := PixelPointer(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst)); … … 167 167 15 + (255 - Src.Pixel^.R) * 9) div 128; 168 168 for ch := 0 to 2 do begin 169 c:= Dst.Pixel^.Planes[ch] - Darken;170 if c< 0 then Dst.Pixel^.Planes[ch] := 0171 else Dst.Pixel^.Planes[ch] := c;169 C := Dst.Pixel^.Planes[ch] - Darken; 170 if C < 0 then Dst.Pixel^.Planes[ch] := 0 171 else Dst.Pixel^.Planes[ch] := C; 172 172 end; 173 173 Src.NextPixel; … … 180 180 end; 181 181 182 procedure TWondersDlg.Glow( i, GlowColor: Integer);182 procedure TWondersDlg.Glow(I, GlowColor: Integer); 183 183 begin 184 184 GlowFrame(Offscreen, 185 ClientWidth div 2 - xSizeBig div 2 + RingPosition[ i].X,186 ClientHeight div 2 - ySizeBig div 2 + RingPosition[ i].Y,185 ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X, 186 ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y, 187 187 xSizeBig, ySizeBig, GlowColor); 188 188 end; -
trunk/Log.pas
r442 r447 27 27 procedure mClearClick(Sender: TObject); 28 28 procedure mSlotClick(Sender: TObject); 29 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);29 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 30 30 procedure Toggle(Sender: TObject); 31 31 procedure ListMouseDown(Sender: TObject; Button: TMouseButton; 32 32 Shift: TShiftState; X, Y: Integer); 33 procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);33 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 34 34 public 35 35 Host: TForm; 36 procedure Add(Level, Turn: Integer; Text: pchar);36 procedure Add(Level, Turn: Integer; Text: PChar); 37 37 private 38 38 MaxLevel: Integer; … … 61 61 begin 62 62 MaxLevel := TMenuItem(Sender).Tag; 63 TMenuItem(Sender).Checked := true;63 TMenuItem(Sender).Checked := True; 64 64 end; 65 65 66 procedure TLogDlg.Add(Level, Turn: Integer; Text: pchar);66 procedure TLogDlg.Add(Level, Turn: Integer; Text: PChar); 67 67 begin 68 68 if (MaxLevel > 0) and (Level <= MaxLevel) or (Level = 1 shl 16 + 1) and … … 89 89 var 90 90 X, Y: Integer; 91 s: string;91 S: string; 92 92 begin 93 93 for Y := 0 to 2 do 94 94 begin 95 s:= '| ';95 S := '| '; 96 96 for X := 0 to 2 do 97 97 if G.Difficulty[SlotNo[Y, X]] = 0 then 98 s := s+ 'SUP |'98 S := S + 'SUP |' 99 99 else if G.Difficulty[SlotNo[Y, X]] < 0 then 100 s := s+ '--- |'100 S := S + '--- |' 101 101 else 102 102 begin … … 104 104 begin // check multi control 105 105 if G.Difficulty[SlotNo[Y, X] + 3] >= 0 then 106 s := s+ Tribe[SlotNo[Y, X] + 3].TPhrase('SHORTNAME') + '+';106 S := S + Tribe[SlotNo[Y, X] + 3].TPhrase('SHORTNAME') + '+'; 107 107 if G.Difficulty[SlotNo[Y, X] + 6] >= 0 then 108 s := s+ Tribe[SlotNo[Y, X] + 6].TPhrase('SHORTNAME') + '+';108 S := S + Tribe[SlotNo[Y, X] + 6].TPhrase('SHORTNAME') + '+'; 109 109 end; 110 s := s+ Tribe[SlotNo[Y, X]].TPhrase('SHORTNAME') + ' | ';110 S := S + Tribe[SlotNo[Y, X]].TPhrase('SHORTNAME') + ' | '; 111 111 end; 112 List.Lines.Add( s);112 List.Lines.Add(S); 113 113 end; 114 114 PostMessage(List.Handle, WM_VSCROLL, SB_BOTTOM, 0); 115 115 end; 116 116 117 procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: word;117 procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: Word; 118 118 Shift: TShiftState); 119 119 begin … … 134 134 end; 135 135 136 procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);136 procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 137 137 begin 138 138 if Host <> nil then -
trunk/Messg.pas
r358 r447 53 53 procedure TMessgDlg.FormShow(Sender: TObject); 54 54 begin 55 Button1.Visible := true;55 Button1.Visible := True; 56 56 Button2.Visible := not(Kind in [mkOK]); 57 57 if Button2.Visible then … … 70 70 end; 71 71 72 SplitText( true);72 SplitText(True); 73 73 CorrectHeight; 74 74 end; -
trunk/Network/UNetworkClient.pas
r423 r447 176 176 end. 177 177 178 -
trunk/Network/UNetworkCommon.pas
r423 r447 44 44 end. 45 45 46 -
trunk/Network/UNetworkServer.pas
r424 r447 69 69 ServerEventLoop: TEventLoop; 70 70 procedure ConnectExecute(Sender: TConnectionBasedSocket; AStream: TSocketStream); 71 procedure Client(Command: TCommand; Player: integer; var Data);71 procedure Client(Command: TCommand; Player: Integer; var Data); 72 72 public 73 73 TCPServer: TTCPServer; … … 81 81 {$ENDIF} 82 82 83 procedure Client(Command, Player: integer; var Data); stdcall;83 procedure Client(Command, Player: Integer; var Data); stdcall; 84 84 85 85 … … 91 91 {$ENDIF} 92 92 93 procedure Client(Command, Player: integer; var Data);93 procedure Client(Command, Player: Integer; var Data); 94 94 begin 95 95 {$IFDEF UNIX} … … 338 338 end. 339 339 340 -
trunk/NoTerm.pas
r442 r447 18 18 procedure FormPaint(Sender: TObject); 19 19 procedure FormCreate(Sender: TObject); 20 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);20 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 21 21 public 22 procedure Client(Command, Player: integer; var Data);22 procedure Client(Command, Player: Integer; var Data); 23 23 private 24 24 Me: Integer; … … 43 43 procedure NewStat; 44 44 procedure EndPlaying; 45 procedure ShowActive( p: integer; Active: boolean);45 procedure ShowActive(P: Integer; Active: Boolean); 46 46 procedure ShowYear; 47 47 end; … … 50 50 NoTermDlg: TNoTermDlg; 51 51 52 procedure Client(Command, Player: integer; var Data); stdcall;52 procedure Client(Command, Player: Integer; var Data); stdcall; 53 53 54 54 … … 69 69 dxBrain = 128; 70 70 dyBrain = 128; 71 xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,71 xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain, 72 72 x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain, 73 73 x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain); 74 yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,74 yBrain: array [0 .. nPlOffered - 1] of Integer = (y0Brain, y0Brain - dyBrain, 75 75 y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain, 76 76 y0Brain + dyBrain, y0Brain, y0Brain - dyBrain); 77 xActive: array [0 .. nPlOffered - 1] of integer = (0, 0, 36, 51, 36, 0,77 xActive: array [0 .. nPlOffered - 1] of Integer = (0, 0, 36, 51, 36, 0, 78 78 -36, -51, -36); 79 yActive: array [0 .. nPlOffered - 1] of integer = (0, -51, -36, 0, 36, 51,79 yActive: array [0 .. nPlOffered - 1] of Integer = (0, -51, -36, 0, 36, 51, 80 80 36, 0, -36); 81 81 82 82 var 83 FormsCreated: boolean;83 FormsCreated: Boolean; 84 84 85 85 procedure TNoTermDlg.FormCreate(Sender: TObject); … … 108 108 procedure TNoTermDlg.EndPlaying; 109 109 var 110 EndCommand: integer;110 EndCommand: Integer; 111 111 begin 112 112 NewStat; 113 if G.RO[ me].Turn > 0 then113 if G.RO[Me].Turn > 0 then 114 114 with MessgDlg do 115 115 begin … … 127 127 end; 128 128 129 procedure TNoTermDlg.ShowActive( p: integer; Active: boolean);130 begin 131 if p< nPlOffered then132 Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[ p],133 y0Brain + 28 + yActive[ p], 8, 8, 81 + 9 * Byte(Active), 16);129 procedure TNoTermDlg.ShowActive(P: Integer; Active: Boolean); 130 begin 131 if P < nPlOffered then 132 Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[P], 133 y0Brain + 28 + yActive[P], 8, 8, 81 + 9 * Byte(Active), 16); 134 134 end; 135 135 … … 138 138 Fill(State.Canvas, 0, 0, 192, 20, 64, 287 + 138); 139 139 RisedTextOut(State.Canvas, 0, 0, Format(Phrases.Lookup('AIT_ROUND'), [Round]) 140 + ' ' + TurnToString(G.RO[ me].Turn));140 + ' ' + TurnToString(G.RO[Me].Turn)); 141 141 BitBltCanvas(Canvas, 64, 287 + 138, 192, 20, State.Canvas, 0, 0); 142 142 end; 143 143 144 procedure TNoTermDlg.Client(Command, Player: integer; var Data);145 var 146 i, x, y, p: integer;147 ActiveDuration: extended;148 ShipComplete: boolean;149 r: TRect;144 procedure TNoTermDlg.Client(Command, Player: Integer; var Data); 145 var 146 I, X, Y, P: Integer; 147 ActiveDuration: Extended; 148 ShipComplete: Boolean; 149 R: TRect; 150 150 nowt: TDateTime; 151 151 begin 152 152 case Command of 153 153 cDebugMessage: 154 LogDlg.Add(Player, G.RO[0].Turn, pchar(@Data));154 LogDlg.Add(Player, G.RO[0].Turn, PChar(@Data)); 155 155 156 156 cInitModule: … … 160 160 Shade := TBitmap.Create; 161 161 Shade.SetSize(64, 64); 162 for x:= 0 to 63 do163 for y:= 0 to 63 do164 if Odd( x + y) then165 Shade.Canvas.Pixels[ x, y] := $FFFFFF162 for X := 0 to 63 do 163 for Y := 0 to 63 do 164 if Odd(X + Y) then 165 Shade.Canvas.Pixels[X, Y] := $FFFFFF 166 166 else 167 Shade.Canvas.Pixels[ x, y] := $000000;167 Shade.Canvas.Pixels[X, Y] := $000000; 168 168 State := TBitmap.Create; 169 169 State.SetSize(192, 20); … … 181 181 cNewGame, cLoadGame: 182 182 begin 183 inc(Round);183 Inc(Round); 184 184 if Mode = rmRunning then 185 185 begin … … 190 190 Show; 191 191 G := TNewGameData(Data); 192 LogDlg.mSlot.Visible := false;192 LogDlg.mSlot.Visible := False; 193 193 LogDlg.Host := nil; 194 ToldAlive := G.RO[ me].Alive;194 ToldAlive := G.RO[Me].Alive; 195 195 Active := -1; 196 196 FillChar(DisallowShowActive, SizeOf(DisallowShowActive), 0); // false … … 213 213 cTurn, cResume, cContinue: 214 214 begin 215 me := Player;215 Me := Player; 216 216 if Active >= 0 then 217 217 begin 218 ShowActive(Active, false);218 ShowActive(Active, False); 219 219 Active := -1; 220 220 end; // should not happen … … 228 228 TurnTime := SecondOf(nowt - LastNewTurn); 229 229 LastNewTurn := nowt; 230 if (G.RO[ me].Alive <> ToldAlive) then231 begin 232 for p:= 1 to nPlOffered - 1 do233 if 1 shl p and (G.RO[me].Alive xor ToldAlive) <> 0 then230 if (G.RO[Me].Alive <> ToldAlive) then 231 begin 232 for P := 1 to nPlOffered - 1 do 233 if 1 shl P and (G.RO[Me].Alive xor ToldAlive) <> 0 then 234 234 begin 235 r := Rect(xBrain[p], yBrain[p] - 16, xBrain[p] + 64,236 yBrain[ p] - 16 + 64);237 InvalidateRect(Handle, @ r, false);235 R := Rect(xBrain[P], yBrain[P] - 16, xBrain[P] + 64, 236 yBrain[P] - 16 + 64); 237 InvalidateRect(Handle, @R, False); 238 238 end; 239 ToldAlive := G.RO[ me].Alive;239 ToldAlive := G.RO[Me].Alive; 240 240 end; 241 241 Application.ProcessMessages; 242 242 if Mode = rmQuit then 243 243 EndPlaying 244 else if G.RO[ me].Happened and phGameEnd <> 0 then244 else if G.RO[Me].Happened and phGameEnd <> 0 then 245 245 begin // game ended, update statistics 246 for p:= 1 to nPlOffered - 1 do247 if Assigned(PlayersBrain[ p]) then248 if 1 shl p and G.RO[me].Alive = 0 then249 inc(ExtStat[p]) // extinct250 else if G.RO[ me].Alive = 1 shl pthen251 inc(AloneStat[p]) // only player alive246 for P := 1 to nPlOffered - 1 do 247 if Assigned(PlayersBrain[P]) then 248 if 1 shl P and G.RO[Me].Alive = 0 then 249 Inc(ExtStat[P]) // extinct 250 else if G.RO[Me].Alive = 1 shl P then 251 Inc(AloneStat[P]) // only player alive 252 252 else 253 253 begin // alive but not alone -- check colony ship 254 ShipComplete := true;255 for i:= 0 to nShipPart - 1 do256 if G.RO[ me].Ship[p].Parts[i] < ShipNeed[i] then257 ShipComplete := false;254 ShipComplete := True; 255 for I := 0 to nShipPart - 1 do 256 if G.RO[Me].Ship[P].Parts[I] < ShipNeed[I] then 257 ShipComplete := False; 258 258 if ShipComplete then 259 inc(WinStat[p]);259 Inc(WinStat[P]); 260 260 end; 261 261 if Mode = rmRunning then 262 Server(sNextRound, me, 0, nil^);262 Server(sNextRound, Me, 0, nil^); 263 263 end 264 264 else if Mode = rmRunning then 265 Server(sTurn, me, 0, nil^);265 Server(sTurn, Me, 0, nil^); 266 266 if Mode = rmStop then 267 267 begin … … 280 280 TotalStatTime := TotalStatTime + ActiveDuration; 281 281 if not DisallowShowActive[Active] then 282 ShowActive(Active, false);282 ShowActive(Active, False); 283 283 DisallowShowActive[Active] := (ActiveDuration < TurnTime * 0.25) and 284 284 (ActiveDuration < ShowActiveThreshold); … … 286 286 LastShowTurnChange := nowt; 287 287 288 Active := integer(Data);288 Active := Integer(Data); 289 289 if (Active >= 0) and not DisallowShowActive[Active] then 290 ShowActive(Active, true);290 ShowActive(Active, True); 291 291 end; 292 292 end; … … 302 302 GoBtn.ButtonIndex := 23; 303 303 GoBtn.Update; 304 Server(sTurn, me, 0, nil^);304 Server(sTurn, Me, 0, nil^); 305 305 end; 306 306 end; … … 314 314 procedure TNoTermDlg.FormPaint(Sender: TObject); 315 315 var 316 i, TimeShare: integer;316 I, TimeShare: Integer; 317 317 begin 318 318 Fill(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6, 0, 0); … … 330 330 7, Caption); 331 331 Canvas.Font.Assign(UniFont[ftSmall]); 332 for i:= 1 to nPlOffered - 1 do333 if Assigned(PlayersBrain[ i]) then332 for I := 1 to nPlOffered - 1 do 333 if Assigned(PlayersBrain[I]) then 334 334 begin 335 Frame(Canvas, xBrain[ i] - 24, yBrain[i] - 8 - 16, xBrain[i] - 24 + 111,336 yBrain[ i] - 8 - 16 + 111, MainTexture.ColorBevelShade,335 Frame(Canvas, xBrain[I] - 24, yBrain[I] - 8 - 16, xBrain[I] - 24 + 111, 336 yBrain[I] - 8 - 16 + 111, MainTexture.ColorBevelShade, 337 337 MainTexture.ColorBevelShade); 338 FrameImage(Canvas, PlayersBrain[ i].Picture, xBrain[i],339 yBrain[ i] - 16, 64, 64, 0, 0);340 if 1 shl i and G.RO[me].Alive = 0 then341 BitBltCanvas(Canvas, xBrain[ i], yBrain[i] - 16, 64, 64,338 FrameImage(Canvas, PlayersBrain[I].Picture, xBrain[I], 339 yBrain[I] - 16, 64, 64, 0, 0); 340 if 1 shl I and G.RO[Me].Alive = 0 then 341 BitBltCanvas(Canvas, xBrain[I], yBrain[I] - 16, 64, 64, 342 342 Shade.Canvas, 0, 0, SRCAND); 343 Sprite(Canvas, HGrSystem, xBrain[ i] + 30 - 14, yBrain[i] + 53, 14,343 Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53, 14, 344 344 14, 1, 316); 345 RisedTextOut(Canvas, xBrain[ i] + 30 - 16 - BiColorTextWidth(Canvas,346 IntToStr(WinStat[ i])), yBrain[i] + 51, IntToStr(WinStat[i]));347 Sprite(Canvas, HGrSystem, xBrain[ i] + 34, yBrain[i] + 53, 14, 14,345 RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas, 346 IntToStr(WinStat[I])), yBrain[I] + 51, IntToStr(WinStat[I])); 347 Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53, 14, 14, 348 348 1 + 15, 316); 349 RisedTextOut(Canvas, xBrain[ i] + 34 + 16, yBrain[i] + 51,350 IntToStr(AloneStat[ i]));351 Sprite(Canvas, HGrSystem, xBrain[ i] + 30 - 14, yBrain[i] + 53 + 16, 14,349 RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51, 350 IntToStr(AloneStat[I])); 351 Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53 + 16, 14, 352 352 14, 1 + 30, 316); 353 RisedTextOut(Canvas, xBrain[ i] + 30 - 16 - BiColorTextWidth(Canvas,354 IntToStr(ExtStat[ i])), yBrain[i] + 51 + 16, IntToStr(ExtStat[i]));355 Sprite(Canvas, HGrSystem, xBrain[ i] + 34, yBrain[i] + 53 + 16, 14, 14,353 RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas, 354 IntToStr(ExtStat[I])), yBrain[I] + 51 + 16, IntToStr(ExtStat[I])); 355 Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53 + 16, 14, 14, 356 356 1 + 45, 316); 357 357 if TotalStatTime > 0 then 358 358 begin 359 TimeShare := trunc(TimeStat[ i] / TotalStatTime * 100 + 0.5);360 RisedTextOut(Canvas, xBrain[ i] + 34 + 16, yBrain[i] + 51 + 16,359 TimeShare := trunc(TimeStat[I] / TotalStatTime * 100 + 0.5); 360 RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51 + 16, 361 361 IntToStr(TimeShare) + '%'); 362 362 end; 363 ShowActive( i, i= Active);363 ShowActive(I, I = Active); 364 364 end; 365 365 Sprite(Canvas, HGrSystem2, x0Brain + 32 - 20, y0Brain + 32 - 20, 40, … … 381 381 end; 382 382 383 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: word;383 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: Word; 384 384 Shift: TShiftState); 385 385 begin -
trunk/Packages/CevoComponents/AsyncProcess2.pas
r290 r447 122 122 123 123 end. 124 -
trunk/Packages/CevoComponents/BaseWin.pas
r442 r447 23 23 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 24 24 procedure FormDeactivate(Sender: TObject); 25 procedure SmartUpdateContent(ImmUpdate: Boolean = false);25 procedure SmartUpdateContent(ImmUpdate: Boolean = False); 26 26 procedure StayOnTop_Workaround; 27 27 protected … … 50 50 CaptionRight: Integer; 51 51 InnerWidth: Integer; 52 InnerHeight: integer;52 InnerHeight: Integer; 53 53 WideBottom: Boolean; 54 54 FullCaption: Boolean; … … 180 180 UserLeft := Left; 181 181 UserTop := Top; 182 Visible := false;182 Visible := False; 183 183 FWindowMode := NewMode; 184 184 ShowModal; … … 186 186 else if forceclose then 187 187 begin // make modal 188 Visible := false;188 Visible := False; 189 189 FWindowMode := NewMode; 190 190 Left := UserLeft; … … 272 272 procedure TFramedDlg.SmartInvalidate; 273 273 var 274 i, BottomFrame: integer;274 I, BottomFrame: Integer; 275 275 r0, r1: HRgn; 276 276 begin … … 281 281 r0 := CreateRectRgn(SideFrame, TitleHeight, ClientWidth - SideFrame, 282 282 ClientHeight - BottomFrame); 283 for i:= 0 to ControlCount - 1 do284 if not(Controls[ i] is TArea) and Controls[i].Visible then283 for I := 0 to ControlCount - 1 do 284 if not(Controls[I] is TArea) and Controls[I].Visible then 285 285 begin 286 with Controls[ i].BoundsRect do286 with Controls[I].BoundsRect do 287 287 r1 := CreateRectRgn(Left, Top, Right, Bottom); 288 288 CombineRgn(r0, r0, r1, RGN_DIFF); … … 295 295 procedure TFramedDlg.VPaint; 296 296 297 procedure CornerFrame(x0, y0, x1, y1: integer);297 procedure CornerFrame(x0, y0, x1, y1: Integer); 298 298 begin 299 299 Frame(Canvas, x0 + 1, y0 + 1, x1 - 2, y1 - 2, MainTexture.ColorBevelLight, … … 308 308 309 309 var 310 i, l, FrameTop, FrameBottom, InnerBottom, Cut, xTexOffset,311 yTexOffset: integer;310 I, L, FrameTop, FrameBottom, InnerBottom, Cut, xTexOffset, 311 yTexOffset: Integer; 312 312 R: TRect; 313 313 begin … … 321 321 end; 322 322 Canvas.Font.Assign(UniFont[ftCaption]); 323 l:= BiColorTextWidth(Canvas, Caption);324 Cut := (ClientWidth - l) div 2;323 L := BiColorTextWidth(Canvas, Caption); 324 Cut := (ClientWidth - L) div 2; 325 325 xTexOffset := (Maintexture.Width - ClientWidth) div 2; 326 326 yTexOffset := (Maintexture.Height - ClientHeight) div 2; … … 446 446 RisedTextOut(Canvas, Cut - 1, 7, Caption); 447 447 448 for i:= 0 to ControlCount - 1 do449 if Controls[ i].Visible and (Controls[i] is TButtonBase) then448 for I := 0 to ControlCount - 1 do 449 if Controls[I].Visible and (Controls[I] is TButtonBase) then 450 450 begin 451 R := Controls[ i].BoundsRect;451 R := Controls[I].BoundsRect; 452 452 if (R.Bottom <= TitleHeight) or (R.Top >= InnerBottom) then 453 453 BtnFrame(Canvas, R, MainTexture); … … 463 463 begin 464 464 if FullCaption then 465 exit;465 Exit; 466 466 r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight); 467 467 r1 := CreateRectRgn(0, 0, CaptionLeft, TitleHeight - NarrowFrame); -
trunk/Packages/CevoComponents/ButtonB.pas
r290 r447 11 11 private 12 12 FMask: TBitmap; 13 FIndex: integer;14 procedure SetIndex(Text: integer);13 FIndex: Integer; 14 procedure SetIndex(Text: Integer); 15 15 public 16 16 property Mask: TBitmap read FMask write FMask; 17 17 published 18 18 property Visible; 19 property ButtonIndex: integer read FIndex write SetIndex;19 property ButtonIndex: Integer read FIndex write SetIndex; 20 20 property OnClick; 21 21 protected … … 61 61 end; 62 62 63 procedure TButtonB.SetIndex(Text: integer);63 procedure TButtonB.SetIndex(Text: Integer); 64 64 begin 65 65 if Text <> FIndex then begin -
trunk/Packages/CevoComponents/ButtonBase.pas
r431 r447 15 15 ClickProc: TNotifyEvent; 16 16 DownChangedProc: TNotifyEvent; 17 procedure SetDown( x: boolean);17 procedure SetDown(X: Boolean); 18 18 // procedure PlayDownSound; 19 19 // procedure PlayUpSound; 20 20 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; 21 x, y: integer); override;21 X, Y: Integer); override; 22 22 procedure MouseUp(Button: TMouseButton; Shift: TShiftState; 23 x, y: integer); override;24 procedure MouseMove(Shift: TShiftState; x, y: integer); override;23 X, Y: Integer); override; 24 procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; 25 25 private 26 Active: boolean;26 Active: Boolean; 27 27 public 28 28 constructor Create(aOwner: TComponent); override; … … 32 32 published 33 33 property Visible; 34 property Down: boolean read FDown write SetDown;35 property Permanent: boolean read FPermanent write FPermanent;34 property Down: Boolean read FDown write SetDown; 35 property Permanent: Boolean read FPermanent write FPermanent; 36 36 property OnClick: TNotifyEvent read ClickProc write ClickProc; 37 37 property OnDownChanged: TNotifyEvent read DownChangedProc … … 50 50 // FUpSound:=''; 51 51 FGraphic := nil; 52 Active := false;53 FDown := false;54 FPermanent := false;52 Active := False; 53 FDown := False; 54 FPermanent := False; 55 55 ClickProc := nil; 56 56 end; 57 57 58 58 procedure TButtonBase.MouseDown(Button: TMouseButton; Shift: TShiftState; 59 x, y: integer);59 X, Y: Integer); 60 60 begin 61 Active := true;62 MouseMove(Shift, x, y);61 Active := True; 62 MouseMove(Shift, X, Y); 63 63 end; 64 64 65 65 procedure TButtonBase.MouseUp(Button: TMouseButton; Shift: TShiftState; 66 x, y: integer);66 X, Y: Integer); 67 67 begin 68 68 if ssLeft in Shift then 69 exit;70 MouseMove(Shift, x, y);69 Exit; 70 MouseMove(Shift, X, Y); 71 71 if Active and FDown then 72 72 begin 73 73 // PlayUpSound; 74 Active := false;74 Active := False; 75 75 if FDown <> FPermanent then 76 76 begin … … 86 86 begin 87 87 // if FDown then PlayUpSound; 88 Active := false;88 Active := False; 89 89 if FDown then 90 90 begin 91 FDown := false;91 FDown := False; 92 92 Invalidate; 93 93 if @DownChangedProc <> nil then … … 97 97 end; 98 98 99 procedure TButtonBase.MouseMove(Shift: TShiftState; x, y: integer);99 procedure TButtonBase.MouseMove(Shift: TShiftState; X, Y: Integer); 100 100 begin 101 101 if Active then 102 if ( x >= 0) and (x < Width) and (y >= 0) and (y< Height) then102 if (X >= 0) and (X < Width) and (Y >= 0) and (Y < Height) then 103 103 if (ssLeft in Shift) and not FDown then 104 104 begin 105 105 { PlayDownSound; } 106 FDown := true;106 FDown := True; 107 107 Paint; 108 108 if @DownChangedProc <> nil then … … 113 113 begin 114 114 { PlayUpSound; } 115 FDown := false;115 FDown := False; 116 116 Paint; 117 117 if @DownChangedProc <> nil then … … 120 120 end; 121 121 122 procedure TButtonBase.SetDown( x: boolean);122 procedure TButtonBase.SetDown(X: Boolean); 123 123 begin 124 FDown := x;124 FDown := X; 125 125 Invalidate; 126 126 end; -
trunk/Packages/CevoComponents/ButtonC.pas
r431 r447 14 14 published 15 15 property Visible; 16 property ButtonIndex: integer read FIndex write SetIndex;16 property ButtonIndex: Integer read FIndex write SetIndex; 17 17 property OnClick; 18 18 protected … … 50 50 end; 51 51 52 procedure TButtonC.SetIndex(Text: integer);52 procedure TButtonC.SetIndex(Text: Integer); 53 53 begin 54 54 if Text <> FIndex then -
trunk/Packages/CevoComponents/ButtonN.pas
r290 r447 10 10 constructor Create(aOwner: TComponent); override; 11 11 private 12 FPossible, FLit: boolean;12 FPossible, FLit: Boolean; 13 13 FGraphic, FMask, FBackGraphic: TBitmap; 14 FIndex, BackIndex: integer;14 FIndex, BackIndex: Integer; 15 15 FSmartHint: string; 16 16 ChangeProc: TNotifyEvent; 17 procedure SetPossible( x: boolean);18 procedure SetLit( x: boolean);19 procedure SetIndex( x: integer);20 procedure SetSmartHint( x: string);17 procedure SetPossible(X: Boolean); 18 procedure SetLit(X: Boolean); 19 procedure SetIndex(X: Integer); 20 procedure SetSmartHint(X: string); 21 21 published 22 property Possible: boolean read FPossible write SetPossible;23 property Lit: boolean read FLit write SetLit;22 property Possible: Boolean read FPossible write SetPossible; 23 property Lit: Boolean read FLit write SetLit; 24 24 property SmartHint: string read FSmartHint write SetSmartHint; 25 25 property Graphic: TBitmap read FGraphic write FGraphic; 26 26 property Mask: TBitmap read FMask write FMask; 27 27 property BackGraphic: TBitmap read FBackGraphic write FBackGraphic; 28 property ButtonIndex: integer read FIndex write SetIndex;28 property ButtonIndex: Integer read FIndex write SetIndex; 29 29 property OnClick: TNotifyEvent read ChangeProc write ChangeProc; 30 30 protected 31 31 procedure Paint; override; 32 32 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; 33 x, y: integer); override;33 X, Y: Integer); override; 34 34 end; 35 35 … … 46 46 begin 47 47 inherited; 48 ShowHint := true;48 ShowHint := True; 49 49 FGraphic := nil; 50 50 FBackGraphic := nil; 51 FPossible := true;52 FLit := false;51 FPossible := True; 52 FLit := False; 53 53 FIndex := -1; 54 54 ChangeProc := nil; … … 63 63 begin 64 64 BitBltCanvas(Canvas, 1, 1, 40, 40, FBackGraphic.Canvas, 65 1 + 80 * BackIndex + 40 * byte(FPossible and FLit), 176);65 1 + 80 * BackIndex + 40 * Byte(FPossible and FLit), 176); 66 66 if FPossible then 67 67 begin … … 83 83 84 84 procedure TButtonN.MouseDown(Button: TMouseButton; Shift: TShiftState; 85 x, y: integer);85 X, Y: Integer); 86 86 begin 87 87 if FPossible and (Button = mbLeft) and (@ChangeProc <> nil) then … … 89 89 end; 90 90 91 procedure TButtonN.SetPossible( x: boolean);91 procedure TButtonN.SetPossible(X: Boolean); 92 92 begin 93 if x<> FPossible then93 if X <> FPossible then 94 94 begin 95 FPossible := x;96 if xthen95 FPossible := X; 96 if X then 97 97 Hint := FSmartHint 98 98 else … … 102 102 end; 103 103 104 procedure TButtonN.SetLit( x: boolean);104 procedure TButtonN.SetLit(X: Boolean); 105 105 begin 106 if x<> FLit then106 if X <> FLit then 107 107 begin 108 FLit := x;108 FLit := X; 109 109 Invalidate; 110 110 end; 111 111 end; 112 112 113 procedure TButtonN.SetIndex( x: integer);113 procedure TButtonN.SetIndex(X: Integer); 114 114 begin 115 if x<> FIndex then115 if X <> FIndex then 116 116 begin 117 FIndex := x;118 if x< 6 then117 FIndex := X; 118 if X < 6 then 119 119 BackIndex := 1 120 120 else … … 124 124 end; 125 125 126 procedure TButtonN.SetSmartHint( x: string);126 procedure TButtonN.SetSmartHint(X: string); 127 127 begin 128 if x<> FSmartHint then128 if X <> FSmartHint then 129 129 begin 130 FSmartHint := x;130 FSmartHint := X; 131 131 if FPossible then 132 Hint := x;132 Hint := X; 133 133 end; 134 134 end; -
trunk/Packages/CevoComponents/CevoComponents.pas
r396 r447 29 29 RegisterPackage('CevoComponents', @Register); 30 30 end. 31 -
trunk/Packages/CevoComponents/Directories.pas
r381 r447 33 33 34 34 if Lang = '' then begin 35 for i:= 1 to Paramcount - 1 do36 if (ParamStrUTF8( i) = '--LANG') or (ParamStrUTF8(i) = '-l') or37 (ParamStrUTF8( i) = '--lang') then38 Lang := ParamStrUTF8( i+ 1);35 for I := 1 to Paramcount - 1 do 36 if (ParamStrUTF8(I) = '--LANG') or (ParamStrUTF8(I) = '-l') or 37 (ParamStrUTF8(I) = '--lang') then 38 Lang := ParamStrUTF8(I + 1); 39 39 end; 40 40 if Lang = '' then begin … … 73 73 (Dst.Time < Src.Time) then 74 74 CopyFile(SourceDir + DirectorySeparator + Src.Name, 75 DestinationDir + DirectorySeparator + Src.Name, false);75 DestinationDir + DirectorySeparator + Src.Name, False); 76 76 FindClose(Dst); 77 77 until FindNext(Src) <> 0; -
trunk/Packages/CevoComponents/DrawDlg.pas
r423 r447 331 331 end. 332 332 333 -
trunk/Packages/CevoComponents/EOTButton.pas
r330 r447 19 19 constructor Create(aOwner: TComponent); override; 20 20 destructor Destroy; override; 21 procedure SetButtonIndexFast( x: integer);22 procedure SetBack(ca: TCanvas; x, y: integer);21 procedure SetButtonIndexFast(X: Integer); 22 procedure SetBack(ca: TCanvas; X, Y: Integer); 23 23 private 24 24 FTemplate: TBitmap; 25 FIndex: integer;26 procedure SetIndex( x: integer);25 FIndex: Integer; 26 procedure SetIndex(X: Integer); 27 27 public 28 28 property Template: TBitmap read FTemplate write FTemplate; 29 29 published 30 30 property Visible; 31 property ButtonIndex: integer read FIndex write SetIndex;31 property ButtonIndex: Integer read FIndex write SetIndex; 32 32 property OnClick; 33 33 protected … … 60 60 Back.SetSize(48, 48); 61 61 Back.Canvas.FillRect(0, 0, Back.Width, Back.Height); 62 ShowHint := true;62 ShowHint := True; 63 63 SetBounds(0, 0, 48, 48); 64 64 end; … … 89 89 end; 90 90 91 procedure TEOTButton.SetIndex( x: integer);91 procedure TEOTButton.SetIndex(X: Integer); 92 92 begin 93 if x<> FIndex then begin94 FIndex := x;93 if X <> FIndex then begin 94 FIndex := X; 95 95 Invalidate; 96 96 end; 97 97 end; 98 98 99 procedure TEOTButton.SetButtonIndexFast( x: integer);99 procedure TEOTButton.SetButtonIndexFast(X: Integer); 100 100 begin 101 if Visible and ( x<> FIndex) then begin102 FIndex := x;101 if Visible and (X <> FIndex) then begin 102 FIndex := X; 103 103 try 104 104 Paint; … … 108 108 end; 109 109 110 procedure TEOTButton.SetBack(ca: TCanvas; x, y: integer);110 procedure TEOTButton.SetBack(ca: TCanvas; X, Y: Integer); 111 111 begin 112 BitBltCanvas(Back.Canvas, 0, 0, 48, 48, ca, x, y);112 BitBltCanvas(Back.Canvas, 0, 0, 48, 48, ca, X, Y); 113 113 end; 114 114 -
trunk/Packages/CevoComponents/ScreenTools.pas
r442 r447 17 17 18 18 {$IFDEF WINDOWS} 19 function ChangeResolution( x, y, bpp, freq: integer): boolean;19 function ChangeResolution(X, Y, bpp, freq: Integer): Boolean; 20 20 {$ENDIF} 21 21 procedure RestoreResolution; 22 22 procedure EmptyMenu(MenuItems: TMenuItem; Keep: Integer = 0); 23 function TurnToYear(Turn: integer): integer;24 function TurnToString(Turn: integer): string;25 function MovementToString(Movement: integer): string;26 procedure BtnFrame(ca: TCanvas; p: TRect; T: TTexture);27 procedure EditFrame(ca: TCanvas; p: TRect; T: TTexture);28 function HexStringToColor(S: string): integer;23 function TurnToYear(Turn: Integer): Integer; 24 function TurnToString(Turn: Integer): string; 25 function MovementToString(Movement: Integer): string; 26 procedure BtnFrame(ca: TCanvas; P: TRect; T: TTexture); 27 procedure EditFrame(ca: TCanvas; P: TRect; T: TTexture); 28 function HexStringToColor(S: string): Integer; 29 29 function ExtractFileNameWithoutExt(const Filename: string): string; 30 function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): boolean;30 function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): Boolean; 31 31 function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet; 32 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);32 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 33 33 procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor); 34 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);34 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 35 35 overload; 36 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);36 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 37 37 overload; 38 38 procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer); … … 45 45 procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height, 46 46 Color0, Color2: Integer); 47 procedure ImageOp_CCC(bmp: TBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer);47 procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer); 48 48 function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer; 49 49 SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload; … … 54 54 function BitBltBitmap(Dest: TBitmap; DestRect: TRect; 55 55 Src: TBitmap; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload; 56 procedure SLine(ca: TCanvas; x0, x1, y: integer; cl: TColor);57 procedure DLine(ca: TCanvas; x0, x1, y: integer; cl0, cl1: TColor);58 procedure Frame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);59 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);60 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: integer; cl: TColor);56 procedure SLine(ca: TCanvas; x0, x1, Y: Integer; cl: TColor); 57 procedure DLine(ca: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor); 58 procedure Frame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor); 59 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor); 60 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor); 61 61 procedure FrameImage(ca: TCanvas; Src: TBitmap; 62 x, y, Width, Height, xSrc, ySrc: integer; IsControl: boolean = False);63 procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: integer; cl: TColor);62 X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False); 63 procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor); 64 64 procedure InitOrnament; 65 65 procedure InitCityMark(T: TTexture); 66 procedure Fill(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: integer); overload;66 procedure Fill(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer); overload; 67 67 procedure Fill(Canvas: TCanvas; Rect: TRect; Offset: TPoint); overload; 68 procedure FillLarge(ca: TCanvas; x0, y0, x1, y1, xm: integer);69 procedure FillSeamless(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: integer;68 procedure FillLarge(ca: TCanvas; x0, y0, x1, y1, xm: Integer); 69 procedure FillSeamless(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer; 70 70 const Texture: TBitmap); 71 procedure FillRectSeamless(ca: TCanvas; x0, y0, x1, y1, xOffset, yOffset: integer;71 procedure FillRectSeamless(ca: TCanvas; x0, y0, x1, y1, xOffset, yOffset: Integer; 72 72 const Texture: TBitmap); 73 procedure PaintBackground(Form: TForm; Left, Top, Width, Height: integer);74 procedure Corner(ca: TCanvas; x, y, Kind: integer; T: TTexture);75 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; x, y: integer; s: string);73 procedure PaintBackground(Form: TForm; Left, Top, Width, Height: Integer); 74 procedure Corner(ca: TCanvas; X, Y, Kind: Integer; T: TTexture); 75 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string); 76 76 procedure LoweredTextOut(ca: TCanvas; cl: TColor; T: TTexture; 77 x, y: integer; s: string);78 function BiColorTextWidth(ca: TCanvas; s: string): integer;79 procedure RisedTextOut(ca: TCanvas; x, y: integer; s: string);80 procedure LightGradient(ca: TCanvas; x, y, Width, Color: integer);81 procedure DarkGradient(ca: TCanvas; x, y, Width, Kind: integer);82 procedure VLightGradient(ca: TCanvas; x, y, Height, Color: integer);83 procedure VDarkGradient(ca: TCanvas; x, y, Height, Kind: integer);77 X, Y: Integer; S: string); 78 function BiColorTextWidth(ca: TCanvas; S: string): Integer; 79 procedure RisedTextOut(ca: TCanvas; X, Y: Integer; S: string); 80 procedure LightGradient(ca: TCanvas; X, Y, Width, Color: Integer); 81 procedure DarkGradient(ca: TCanvas; X, Y, Width, Kind: Integer); 82 procedure VLightGradient(ca: TCanvas; X, Y, Height, Color: Integer); 83 procedure VDarkGradient(ca: TCanvas; X, Y, Height, Kind: Integer); 84 84 procedure UnderlinedTitleValue(Canvas: TCanvas; Title, Value: string; X, Y, Width: Integer); 85 procedure NumberBar(dst: TBitmap; x, y: integer; Cap: string; val: integer;85 procedure NumberBar(dst: TBitmap; X, Y: Integer; Cap: string; val: Integer; 86 86 T: TTexture); 87 procedure CountBar(dst: TBitmap; x, y, w: integer; Kind: integer;88 Cap: string; val: integer; T: TTexture);89 procedure PaintProgressBar(ca: TCanvas; Kind, x, y, pos, Growth, max: integer;87 procedure CountBar(dst: TBitmap; X, Y, W: Integer; Kind: Integer; 88 Cap: string; val: Integer; T: TTexture); 89 procedure PaintProgressBar(ca: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer; 90 90 T: TTexture); 91 91 procedure PaintRelativeProgressBar(ca: TCanvas; 92 Kind, x, y, size, pos, Growth, max: integer; IndicateComplete: boolean;92 Kind, X, Y, size, Pos, Growth, Max: Integer; IndicateComplete: Boolean; 93 93 T: TTexture); 94 procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: integer);94 procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: Integer); 95 95 procedure LoadPhrases; 96 96 procedure Texturize(Dest, Texture: TBitmap; TransparentColor: Cardinal); … … 204 204 {$IFDEF WINDOWS} 205 205 StartResolution: TDeviceMode; 206 ResolutionChanged: boolean;206 ResolutionChanged: Boolean; 207 207 {$ENDIF} 208 208 … … 210 210 211 211 {$IFDEF WINDOWS} 212 function ChangeResolution( x, y, bpp, freq: integer): boolean;212 function ChangeResolution(X, Y, bpp, freq: Integer): Boolean; 213 213 var 214 214 DevMode: TDeviceMode; … … 217 217 DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL or 218 218 DM_DISPLAYFREQUENCY; 219 DevMode.dmPelsWidth := x;220 DevMode.dmPelsHeight := y;219 DevMode.dmPelsWidth := X; 220 DevMode.dmPelsHeight := Y; 221 221 DevMode.dmBitsPerPel := bpp; 222 222 DevMode.dmDisplayFrequency := freq; … … 318 318 end; 319 319 320 procedure BtnFrame(ca: TCanvas; p: TRect; T: TTexture);321 begin 322 RFrame(ca, p.Left - 1, p.Top - 1, p.Right, p.Bottom, T.ColorBevelShade,320 procedure BtnFrame(ca: TCanvas; P: TRect; T: TTexture); 321 begin 322 RFrame(ca, P.Left - 1, P.Top - 1, P.Right, P.Bottom, T.ColorBevelShade, 323 323 T.ColorBevelLight); 324 324 end; 325 325 326 procedure EditFrame(ca: TCanvas; p: TRect; T: TTexture);327 begin 328 Frame(ca, p.Left - 1, p.Top - 1, p.Right, p.Bottom, $000000, $000000);329 Frame(ca, p.Left - 2, p.Top - 2, p.Right + 1, p.Bottom + 1, $000000, $000000);330 Frame(ca, p.Left - 3, p.Top - 3, p.Right + 2, p.Bottom + 1, $000000, $000000);331 RFrame(ca, p.Left - 4, p.Top - 4, p.Right + 3, p.Bottom + 2, T.ColorBevelShade,326 procedure EditFrame(ca: TCanvas; P: TRect; T: TTexture); 327 begin 328 Frame(ca, P.Left - 1, P.Top - 1, P.Right, P.Bottom, $000000, $000000); 329 Frame(ca, P.Left - 2, P.Top - 2, P.Right + 1, P.Bottom + 1, $000000, $000000); 330 Frame(ca, P.Left - 3, P.Top - 3, P.Right + 2, P.Bottom + 1, $000000, $000000); 331 RFrame(ca, P.Left - 4, P.Top - 4, P.Right + 3, P.Bottom + 2, T.ColorBevelShade, 332 332 T.ColorBevelLight); 333 333 end; … … 335 335 function HexCharToInt(X: Char): Integer; 336 336 begin 337 case xof337 case X of 338 338 '0' .. '9': Result := Ord(X) - Ord('0'); 339 339 'A' .. 'F': Result := Ord(X) - Ord('A') + 10; … … 492 492 function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet; 493 493 var 494 x: Integer;495 y: Integer;494 X: Integer; 495 Y: Integer; 496 496 OriginalColor: Integer; 497 497 FileName: string; … … 522 522 DataPixel := PixelPointer(Result.Data); 523 523 MaskPixel := PixelPointer(Result.Mask); 524 for y:= 0 to ScaleToNative(Result.Data.Height) - 1 do begin525 for x:= 0 to ScaleToNative(Result.Data.Width) - 1 do begin524 for Y := 0 to ScaleToNative(Result.Data.Height) - 1 do begin 525 for X := 0 to ScaleToNative(Result.Data.Width) - 1 do begin 526 526 OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF; 527 527 if (OriginalColor = TransparentColor1) or (OriginalColor = TransparentColor2) then begin … … 552 552 end; 553 553 554 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);554 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 555 555 begin 556 556 BitBltCanvas(dst.Canvas, xDst, yDst, Width, Height, … … 650 650 Height := ScaleToNative(dst.Height) - yDst; 651 651 if (Width < 0) or (Height < 0) then 652 exit;652 Exit; 653 653 654 654 dst.BeginUpdate; … … 659 659 for X := 0 to Width - 1 do begin 660 660 Brightness := PixelSrc.Pixel^.B; // One byte for 8-bit color 661 test := (PixelDst.Pixel^.R * Brightness) shr 7;662 if test >= 256 then661 Test := (PixelDst.Pixel^.R * Brightness) shr 7; 662 if Test >= 256 then 663 663 PixelDst.Pixel^.R := 255 664 664 else 665 PixelDst.Pixel^.R := test; // Red666 test := (PixelDst.Pixel^.G * Brightness) shr 7;667 if test >= 256 then665 PixelDst.Pixel^.R := Test; // Red 666 Test := (PixelDst.Pixel^.G * Brightness) shr 7; 667 if Test >= 256 then 668 668 PixelDst.Pixel^.G := 255 669 669 else 670 PixelDst.Pixel^.G := test; // Green671 test := (PixelDst.Pixel^.B * Brightness) shr 7;672 if test >= 256 then670 PixelDst.Pixel^.G := Test; // Green 671 Test := (PixelDst.Pixel^.B * Brightness) shr 7; 672 if Test >= 256 then 673 673 PixelDst.Pixel^.R := 255 674 674 else … … 716 716 Height := ScaleToNative(dst.Height) - yDst; 717 717 if (Width < 0) or (Height < 0) then 718 exit;718 Exit; 719 719 720 720 Src.BeginUpdate; … … 765 765 // R channel = Color2 amp 766 766 var 767 ix, iy, amp0, amp1, trans, Value: integer;767 ix, iy, amp0, amp1, trans, Value: Integer; 768 768 SrcPixel: TPixelPointer; 769 769 DstPixel: TPixelPointer; … … 807 807 end; 808 808 809 procedure ImageOp_CCC(bmp: TBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer);809 procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer); 810 810 // Bmp is template 811 811 // B channel = Color0 amp, 128=original brightness … … 813 813 // R channel = Color2 amp, 128=original brightness 814 814 var 815 i, Red, Green: Integer;815 I, Red, Green: Integer; 816 816 PixelPtr: TPixelPointer; 817 817 begin … … 821 821 Height := ScaleToNative(Height); 822 822 bmp.BeginUpdate; 823 assert(bmp.PixelFormat = pf24bit);824 Height := y+ Height;825 PixelPtr := PixelPointer(Bmp, x, y);826 while y< Height do begin827 for i:= 0 to Width - 1 do begin823 Assert(bmp.PixelFormat = pf24bit); 824 Height := Y + Height; 825 PixelPtr := PixelPointer(Bmp, X, Y); 826 while Y < Height do begin 827 for I := 0 to Width - 1 do begin 828 828 Red := ((PixelPtr.Pixel^.B * (Color0 and $0000FF) + PixelPtr.Pixel^.G * 829 829 (Color1 and $0000FF) + PixelPtr.Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff; … … 838 838 PixelPtr.NextPixel; 839 839 end; 840 Inc( y);840 Inc(Y); 841 841 PixelPtr.NextLine; 842 842 end; … … 844 844 end; 845 845 846 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);846 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 847 847 begin 848 848 BitBltCanvas(Canvas, xDst, yDst, Width, Height, … … 852 852 end; 853 853 854 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);854 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer); 855 855 begin 856 856 BitBltCanvas(dst.Canvas, xDst, yDst, Width, Height, … … 890 890 end; 891 891 892 procedure SLine(ca: TCanvas; x0, x1, y: integer; cl: TColor);892 procedure SLine(ca: TCanvas; x0, x1, Y: Integer; cl: TColor); 893 893 begin 894 894 with ca do begin 895 895 Pen.Color := cl; 896 MoveTo(x0, y);897 LineTo(x1 + 1, y);898 end; 899 end; 900 901 procedure DLine(ca: TCanvas; x0, x1, y: integer; cl0, cl1: TColor);896 MoveTo(x0, Y); 897 LineTo(x1 + 1, Y); 898 end; 899 end; 900 901 procedure DLine(ca: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor); 902 902 begin 903 903 with ca do begin 904 904 Pen.Color := cl0; 905 MoveTo(x0, y);906 LineTo(x1, y);905 MoveTo(x0, Y); 906 LineTo(x1, Y); 907 907 Pen.Color := cl1; 908 MoveTo(x0 + 1, y+ 1);909 LineTo(x1 + 1, y+ 1);910 Pixels[x0, y+ 1] := cl0;911 Pixels[x1, y] := cl1;912 end; 913 end; 914 915 procedure Frame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);908 MoveTo(x0 + 1, Y + 1); 909 LineTo(x1 + 1, Y + 1); 910 Pixels[x0, Y + 1] := cl0; 911 Pixels[x1, Y] := cl1; 912 end; 913 end; 914 915 procedure Frame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor); 916 916 begin 917 917 with ca do begin … … 926 926 end; 927 927 928 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);928 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor); 929 929 begin 930 930 with ca do begin … … 942 942 end; 943 943 944 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: integer; cl: TColor);944 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor); 945 945 begin 946 946 with ca do begin … … 962 962 963 963 procedure FrameImage(ca: TCanvas; Src: TBitmap; 964 x, y, Width, Height, xSrc, ySrc: integer; IsControl: boolean = False);964 X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False); 965 965 begin 966 966 if IsControl then begin 967 Frame(ca, x - 1, y - 1, x + Width, y+ Height, $B0B0B0, $FFFFFF);968 RFrame(ca, x - 2, y - 2, x + Width + 1, y+ Height + 1, $FFFFFF, $B0B0B0);967 Frame(ca, X - 1, Y - 1, X + Width, Y + Height, $B0B0B0, $FFFFFF); 968 RFrame(ca, X - 2, Y - 2, X + Width + 1, Y + Height + 1, $FFFFFF, $B0B0B0); 969 969 end else 970 Frame(ca, x - 1, y - 1, x + Width, y+ Height, $000000, $000000);971 BitBltCanvas(ca, x, y, Width, Height, Src.Canvas, xSrc, ySrc);970 Frame(ca, X - 1, Y - 1, X + Width, Y + Height, $000000, $000000); 971 BitBltCanvas(ca, X, Y, Width, Height, Src.Canvas, xSrc, ySrc); 972 972 end; 973 973 974 974 procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor); 975 975 var 976 x, y, ch, r: Integer;976 X, Y, ch, R: Integer; 977 977 DstPtr: TPixelPointer; 978 978 DpiGlowRange: Integer; … … 985 985 Dst.BeginUpdate; 986 986 DstPtr := PixelPointer(Dst, x0 - DpiGlowRange + 1, y0 - DpiGlowRange + 1); 987 for y:= -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin988 for x:= -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin989 if x< 0 then990 if y< 0 then991 r := round(sqrt(sqr(x) + sqr(y)))992 else if y>= Height then993 r := round(sqrt(sqr(x) + sqr(y- (Height - 1))))987 for Y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin 988 for X := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin 989 if X < 0 then 990 if Y < 0 then 991 R := round(sqrt(sqr(X) + sqr(Y))) 992 else if Y >= Height then 993 R := round(sqrt(sqr(X) + sqr(Y - (Height - 1)))) 994 994 else 995 r := -x996 else if x>= Width then997 if y< 0 then998 r := round(sqrt(sqr(x - (Width - 1)) + sqr(y)))999 else if y>= Height then1000 r := round(sqrt(sqr(x - (Width - 1)) + sqr(y- (Height - 1))))995 R := -X 996 else if X >= Width then 997 if Y < 0 then 998 R := round(sqrt(sqr(X - (Width - 1)) + sqr(Y))) 999 else if Y >= Height then 1000 R := round(sqrt(sqr(X - (Width - 1)) + sqr(Y - (Height - 1)))) 1001 1001 else 1002 r := x- (Width - 1)1003 else if y< 0 then1004 r := -y1005 else if y>= Height then1006 r := y- (Height - 1)1002 R := X - (Width - 1) 1003 else if Y < 0 then 1004 R := -Y 1005 else if Y >= Height then 1006 R := Y - (Height - 1) 1007 1007 else begin 1008 1008 DstPtr.NextPixel; 1009 1009 continue; 1010 1010 end; 1011 if r= 0 then1012 r:= 1;1013 if r< DpiGlowRange then1011 if R = 0 then 1012 R := 1; 1013 if R < DpiGlowRange then 1014 1014 for ch := 0 to 2 do 1015 1015 DstPtr.Pixel^.Planes[2 - ch] := 1016 (DstPtr.Pixel^.Planes[2 - ch] * ( r- 1) + (cl shr (8 * ch) and $FF) *1017 (DpiGlowRange - r)) div (DpiGlowRange - 1);1016 (DstPtr.Pixel^.Planes[2 - ch] * (R - 1) + (cl shr (8 * ch) and $FF) * 1017 (DpiGlowRange - R)) div (DpiGlowRange - 1); 1018 1018 DstPtr.NextPixel; 1019 1019 end; … … 1065 1065 procedure InitCityMark(T: TTexture); 1066 1066 var 1067 x: Integer;1068 y: Integer;1067 X: Integer; 1068 Y: Integer; 1069 1069 Intensity: Integer; 1070 1070 begin 1071 for x:= 0 to CityMark1.Width - 1 do begin1072 for y:= 0 to CityMark1.Height - 1 do begin1073 if HGrSystem.Mask.Canvas.Pixels[CityMark1.Left + x, CityMark1.Top + y] = 0 then1071 for X := 0 to CityMark1.Width - 1 do begin 1072 for Y := 0 to CityMark1.Height - 1 do begin 1073 if HGrSystem.Mask.Canvas.Pixels[CityMark1.Left + X, CityMark1.Top + Y] = 0 then 1074 1074 begin 1075 1075 Intensity := HGrSystem.Data.Canvas.Pixels[CityMark1.Left + 1076 x, CityMark1.Top + y] and $FF;1077 HGrSystem.Data.Canvas.Pixels[CityMark2.Left + x, CityMark2.Top + y] :=1076 X, CityMark1.Top + Y] and $FF; 1077 HGrSystem.Data.Canvas.Pixels[CityMark2.Left + X, CityMark2.Top + Y] := 1078 1078 T.ColorMark and $FF * Intensity div $FF + T.ColorMark shr 8 and 1079 1079 $FF * Intensity div $FF shl 8 + T.ColorMark shr 16 and … … 1103 1103 function Band(I: Integer): Integer; 1104 1104 var 1105 n: integer;1105 N: Integer; 1106 1106 begin 1107 n:= ((MainTexture.Height div 2) div (y1 - y0)) * 2;1107 N := ((MainTexture.Height div 2) div (y1 - y0)) * 2; 1108 1108 while MainTexture.Height div 2 + (I + 1) * (y1 - y0) > MainTexture.Height do 1109 Dec(I, n);1109 Dec(I, N); 1110 1110 while MainTexture.Height div 2 + I * (y1 - y0) < 0 do 1111 Inc(I, n);1111 Inc(I, N); 1112 1112 Result := I; 1113 1113 end; … … 1137 1137 const Texture: TBitmap); 1138 1138 var 1139 x, y, x0cut, y0cut, x1cut, y1cut: Integer;1139 X, Y, x0cut, y0cut, x1cut, y1cut: Integer; 1140 1140 begin 1141 1141 while xOffset < 0 do … … 1143 1143 while yOffset < 0 do 1144 1144 Inc(yOffset, Texture.Height); 1145 for y:= (Top + yOffset) div Texture.Height to (Top + yOffset + Height - 1) div1145 for Y := (Top + yOffset) div Texture.Height to (Top + yOffset + Height - 1) div 1146 1146 Texture.Height do 1147 1147 begin 1148 y0cut := Top + yOffset - y* Texture.Height;1148 y0cut := Top + yOffset - Y * Texture.Height; 1149 1149 if y0cut < 0 then 1150 1150 y0cut := 0; 1151 y1cut := ( y+ 1) * Texture.Height - (Top + yOffset + Height);1151 y1cut := (Y + 1) * Texture.Height - (Top + yOffset + Height); 1152 1152 if y1cut < 0 then 1153 1153 y1cut := 0; 1154 for x:= (Left + xOffset) div Texture.Width to (Left + xOffset + Width - 1) div1154 for X := (Left + xOffset) div Texture.Width to (Left + xOffset + Width - 1) div 1155 1155 Texture.Width do 1156 1156 begin 1157 x0cut := Left + xOffset - x* Texture.Width;1157 x0cut := Left + xOffset - X * Texture.Width; 1158 1158 if x0cut < 0 then 1159 1159 x0cut := 0; 1160 x1cut := ( x+ 1) * Texture.Width - (Left + xOffset + Width);1160 x1cut := (X + 1) * Texture.Width - (Left + xOffset + Width); 1161 1161 if x1cut < 0 then 1162 1162 x1cut := 0; 1163 BitBltCanvas(ca, x* Texture.Width + x0cut - xOffset,1164 y* Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut,1163 BitBltCanvas(ca, X * Texture.Width + x0cut - xOffset, 1164 Y * Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut, 1165 1165 Texture.Height - y0cut - y1cut, Texture.Canvas, x0cut, y0cut); 1166 1166 end; … … 1180 1180 end; 1181 1181 1182 procedure Corner(ca: TCanvas; x, y, Kind: Integer; T: TTexture);1182 procedure Corner(ca: TCanvas; X, Y, Kind: Integer; T: TTexture); 1183 1183 begin 1184 1184 { BitBltCanvas(ca,x,y,8,8,T.HGr.Mask.Canvas, 1185 1185 T.xGr+29+Kind*9,T.yGr+89,SRCAND); 1186 BitBltCanvas(ca, x,y,8,8,T.HGr.Data.Canvas,1186 BitBltCanvas(ca,X,Y,8,8,T.HGr.Data.Canvas, 1187 1187 T.xGr+29+Kind*9,T.yGr+89,SRCPAINT); } 1188 1188 end; 1189 1189 1190 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; x, y: Integer; s: string);1191 1192 procedure PaintIcon( x, y, Kind: Integer);1190 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string); 1191 1192 procedure PaintIcon(X, Y, Kind: Integer); 1193 1193 begin 1194 BitBltCanvas(ca, x, y+ 6, 10, 10, HGrSystem.Mask.Canvas,1194 BitBltCanvas(ca, X, Y + 6, 10, 10, HGrSystem.Mask.Canvas, 1195 1195 66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCAND); 1196 BitBltCanvas(ca, x, y+ 6, 10, 10, HGrSystem.Data.Canvas,1196 BitBltCanvas(ca, X, Y + 6, 10, 10, HGrSystem.Data.Canvas, 1197 1197 66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCPAINT); 1198 1198 end; 1199 1199 1200 1200 var 1201 p, xp: Integer;1201 P, xp: Integer; 1202 1202 sp: string; 1203 1203 shadow: Boolean; 1204 1204 Text: string; 1205 1205 begin 1206 Inc( x);1207 Inc( y);1206 Inc(X); 1207 Inc(Y); 1208 1208 for shadow := True downto False do 1209 1209 with ca do … … 1214 1214 else 1215 1215 Font.Color := clMain; 1216 sp := s;1217 xp := x;1216 sp := S; 1217 xp := X; 1218 1218 repeat 1219 p := pos('%', sp);1220 if ( p = 0) or (p+ 1 > Length(sp)) or not1221 (sp[ p+ 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) then1219 P := Pos('%', sp); 1220 if (P = 0) or (P + 1 > Length(sp)) or not 1221 (sp[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) then 1222 1222 begin 1223 ca.Textout(xp, y, sp);1223 ca.Textout(xp, Y, sp); 1224 1224 Break; 1225 1225 end 1226 1226 else 1227 1227 begin 1228 Text := Copy(sp, 1, p- 1);1229 Textout(xp, y, Text);1228 Text := Copy(sp, 1, P - 1); 1229 Textout(xp, Y, Text); 1230 1230 Inc(xp, ca.TextWidth(Text)); 1231 1231 if not shadow then 1232 case sp[ p+ 1] of1233 'c': PaintIcon(xp + 1, y, 6);1234 'f': PaintIcon(xp + 1, y, 0);1235 'l': PaintIcon(xp + 1, y, 8);1236 'm': PaintIcon(xp + 1, y, 17);1237 'n': PaintIcon(xp + 1, y, 7);1238 'o': PaintIcon(xp + 1, y, 16);1239 'p': PaintIcon(xp + 1, y, 2);1240 'r': PaintIcon(xp + 1, y, 12);1241 't': PaintIcon(xp + 1, y, 4);1242 'w': PaintIcon(xp + 1, y, 13);1232 case sp[P + 1] of 1233 'c': PaintIcon(xp + 1, Y, 6); 1234 'f': PaintIcon(xp + 1, Y, 0); 1235 'l': PaintIcon(xp + 1, Y, 8); 1236 'm': PaintIcon(xp + 1, Y, 17); 1237 'n': PaintIcon(xp + 1, Y, 7); 1238 'o': PaintIcon(xp + 1, Y, 16); 1239 'p': PaintIcon(xp + 1, Y, 2); 1240 'r': PaintIcon(xp + 1, Y, 12); 1241 't': PaintIcon(xp + 1, Y, 4); 1242 'w': PaintIcon(xp + 1, Y, 13); 1243 1243 end; 1244 1244 Inc(xp, 10); 1245 Delete(sp, 1, p+ 1);1245 Delete(sp, 1, P + 1); 1246 1246 end; 1247 1247 until False; 1248 Dec( x);1249 Dec( y);1248 Dec(X); 1249 Dec(Y); 1250 1250 end; 1251 1251 end; 1252 1252 1253 function BiColorTextWidth(ca: TCanvas; s: string): Integer;1253 function BiColorTextWidth(ca: TCanvas; S: string): Integer; 1254 1254 var 1255 1255 P: Integer; … … 1257 1257 Result := 1; 1258 1258 repeat 1259 P := Pos('%', s);1260 if (P = 0) or (P = Length( s)) then1259 P := Pos('%', S); 1260 if (P = 0) or (P = Length(S)) then 1261 1261 begin 1262 Inc(Result, ca.TextWidth( s));1262 Inc(Result, ca.TextWidth(S)); 1263 1263 Break; 1264 1264 end 1265 1265 else 1266 1266 begin 1267 if not ( s[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w'])1267 if not (S[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) 1268 1268 then 1269 Inc(Result, ca.TextWidth( copy(s, 1, P + 1)))1269 Inc(Result, ca.TextWidth(Copy(S, 1, P + 1))) 1270 1270 else 1271 Inc(Result, ca.TextWidth( copy(s, 1, P - 1)) + 10);1272 Delete( s, 1, P + 1);1271 Inc(Result, ca.TextWidth(Copy(S, 1, P - 1)) + 10); 1272 Delete(S, 1, P + 1); 1273 1273 end; 1274 1274 until False; … … 1276 1276 1277 1277 procedure LoweredTextOut(ca: TCanvas; cl: TColor; T: TTexture; 1278 x, y: Integer; s: string);1278 X, Y: Integer; S: string); 1279 1279 begin 1280 1280 if cl = -2 then 1281 1281 BiColorTextOut(ca, (T.ColorBevelShade and $FEFEFE) shr 1, 1282 T.ColorBevelLight, x, y, s)1282 T.ColorBevelLight, X, Y, S) 1283 1283 else if cl < 0 then 1284 BiColorTextOut(ca, T.ColorTextShade, T.ColorTextLight, x, y, s)1284 BiColorTextOut(ca, T.ColorTextShade, T.ColorTextLight, X, Y, S) 1285 1285 else 1286 BiColorTextOut(ca, cl, T.ColorTextLight, x, y, s);1287 end; 1288 1289 procedure RisedTextOut(ca: TCanvas; x, y: integer; s: string);1290 begin 1291 BiColorTextOut(ca, $FFFFFF, $000000, x, y, s);1292 end; 1293 1294 procedure Gradient(ca: TCanvas; x, y, dx, dy, Width, Height, Color: Integer;1295 Brightness: array of integer);1296 var 1297 i, r, g, b: Integer;1298 begin 1299 for i:= 0 to Length(Brightness) - 1 do begin // gradient1300 r := Color and $FF + Brightness[i];1301 if r< 0 then1302 r:= 01303 else if r>= 256 then1304 r:= 255;1305 g := Color shr 8 and $FF + Brightness[i];1306 if g< 0 then1307 g:= 01308 else if g>= 256 then1309 g:= 255;1310 b := Color shr 16 and $FF + Brightness[i];1311 if b< 0 then1312 b:= 01313 else if b>= 256 then1314 b:= 255;1315 ca.Pen.Color := r + g shl 8 + bshl 16;1316 ca.MoveTo( x + dx * i, y + dy * i);1317 ca.LineTo( x + dx * i + Width, y + dy * i+ Height);1286 BiColorTextOut(ca, cl, T.ColorTextLight, X, Y, S); 1287 end; 1288 1289 procedure RisedTextOut(ca: TCanvas; X, Y: Integer; S: string); 1290 begin 1291 BiColorTextOut(ca, $FFFFFF, $000000, X, Y, S); 1292 end; 1293 1294 procedure Gradient(ca: TCanvas; X, Y, dx, dy, Width, Height, Color: Integer; 1295 Brightness: array of Integer); 1296 var 1297 I, R, G, B: Integer; 1298 begin 1299 for I := 0 to Length(Brightness) - 1 do begin // gradient 1300 R := Color and $FF + Brightness[I]; 1301 if R < 0 then 1302 R := 0 1303 else if R >= 256 then 1304 R := 255; 1305 G := Color shr 8 and $FF + Brightness[I]; 1306 if G < 0 then 1307 G := 0 1308 else if G >= 256 then 1309 G := 255; 1310 B := Color shr 16 and $FF + Brightness[I]; 1311 if B < 0 then 1312 B := 0 1313 else if B >= 256 then 1314 B := 255; 1315 ca.Pen.Color := R + G shl 8 + B shl 16; 1316 ca.MoveTo(X + dx * I, Y + dy * I); 1317 ca.LineTo(X + dx * I + Width, Y + dy * I + Height); 1318 1318 end; 1319 1319 ca.Pen.Color := $000000; 1320 ca.MoveTo( x + 1, y+ 16 * dy + Height);1321 ca.LineTo( x + 16 * dx + Width, y+ 16 * dy + Height);1322 ca.LineTo( x + 16 * dx + Width, y);1323 end; 1324 1325 procedure LightGradient(ca: TCanvas; x, y, Width, Color: Integer);1320 ca.MoveTo(X + 1, Y + 16 * dy + Height); 1321 ca.LineTo(X + 16 * dx + Width, Y + 16 * dy + Height); 1322 ca.LineTo(X + 16 * dx + Width, Y); 1323 end; 1324 1325 procedure LightGradient(ca: TCanvas; X, Y, Width, Color: Integer); 1326 1326 const 1327 Brightness: array [0 .. 15] of integer =1327 Brightness: array [0 .. 15] of Integer = 1328 1328 (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44); 1329 1329 begin 1330 Gradient(ca, x, y, 0, 1, Width, 0, Color, Brightness);1331 end; 1332 1333 procedure DarkGradient(ca: TCanvas; x, y, Width, Kind: Integer);1330 Gradient(ca, X, Y, 0, 1, Width, 0, Color, Brightness); 1331 end; 1332 1333 procedure DarkGradient(ca: TCanvas; X, Y, Width, Kind: Integer); 1334 1334 const 1335 Brightness: array [0 .. 15] of integer =1335 Brightness: array [0 .. 15] of Integer = 1336 1336 (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44); 1337 1337 begin 1338 Gradient(ca, x, y, 0, 1, Width, 0, HGrSystem.Data.Canvas.Pixels1338 Gradient(ca, X, Y, 0, 1, Width, 0, HGrSystem.Data.Canvas.Pixels 1339 1339 [187, 137 + Kind], Brightness); 1340 1340 end; 1341 1341 1342 procedure VLightGradient(ca: TCanvas; x, y, Height, Color: Integer);1342 procedure VLightGradient(ca: TCanvas; X, Y, Height, Color: Integer); 1343 1343 const 1344 Brightness: array [0 .. 15] of integer =1344 Brightness: array [0 .. 15] of Integer = 1345 1345 (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44); 1346 1346 begin 1347 Gradient(ca, x, y, 1, 0, 0, Height, Color, Brightness);1348 end; 1349 1350 procedure VDarkGradient(ca: TCanvas; x, y, Height, Kind: Integer);1347 Gradient(ca, X, Y, 1, 0, 0, Height, Color, Brightness); 1348 end; 1349 1350 procedure VDarkGradient(ca: TCanvas; X, Y, Height, Kind: Integer); 1351 1351 const 1352 Brightness: array [0 .. 15] of integer =1352 Brightness: array [0 .. 15] of Integer = 1353 1353 (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44); 1354 1354 begin 1355 Gradient(ca, x, y, 1, 0, 0, Height,1355 Gradient(ca, X, Y, 1, 0, 0, Height, 1356 1356 HGrSystem.Data.Canvas.Pixels[187, 137 + Kind], Brightness); 1357 1357 end; … … 1364 1364 end; 1365 1365 1366 procedure NumberBar(dst: TBitmap; x, y: integer; Cap: string;1366 procedure NumberBar(dst: TBitmap; X, Y: Integer; Cap: string; 1367 1367 val: Integer; T: TTexture); 1368 1368 var 1369 s: string;1369 S: string; 1370 1370 begin 1371 1371 if val > 0 then 1372 1372 begin 1373 DLine(dst.Canvas, x - 2, x + 170, y+ 16, T.ColorBevelShade,1373 DLine(dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade, 1374 1374 T.ColorBevelLight); 1375 LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);1376 s:= IntToStr(val);1377 RisedTextOut(dst.Canvas, x+ 170 - BiColorTextWidth(dst.Canvas,1378 s), y, s);1379 end; 1380 end; 1381 1382 procedure CountBar(dst: TBitmap; x, y, w: Integer; Kind: Integer;1375 LoweredTextOut(dst.Canvas, -1, T, X - 2, Y, Cap); 1376 S := IntToStr(val); 1377 RisedTextOut(dst.Canvas, X + 170 - BiColorTextWidth(dst.Canvas, 1378 S), Y, S); 1379 end; 1380 end; 1381 1382 procedure CountBar(dst: TBitmap; X, Y, W: Integer; Kind: Integer; 1383 1383 Cap: string; val: Integer; T: TTexture); 1384 1384 var 1385 i, sd, ld, cl, xIcon, yIcon: Integer;1386 s: string;1385 I, sd, ld, cl, xIcon, yIcon: Integer; 1386 S: string; 1387 1387 begin 1388 1388 // val:=random(40); //!!! … … 1396 1396 // DLine(dst.Canvas,x-2,x+170+32,y+16,T.ColorBevelShade,T.ColorBevelLight); 1397 1397 1398 xIcon := x- 5;1399 yIcon := y+ 15;1400 DLine(dst.Canvas, x - 2, xIcon + w+ 2, yIcon + 16, T.ColorBevelShade,1398 xIcon := X - 5; 1399 yIcon := Y + 15; 1400 DLine(dst.Canvas, X - 2, xIcon + W + 2, yIcon + 16, T.ColorBevelShade, 1401 1401 T.ColorBevelLight); 1402 1402 1403 s:= IntToStr(val);1403 S := IntToStr(val); 1404 1404 if val < 0 then 1405 1405 cl := $0000FF 1406 1406 else 1407 1407 cl := -1; 1408 LoweredTextOut(dst.Canvas, cl, T, x - 2, y, Cap);1408 LoweredTextOut(dst.Canvas, cl, T, X - 2, Y, Cap); 1409 1409 LoweredTextOut(dst.Canvas, cl, T, 1410 xIcon + w + 2 - BiColorTextWidth(dst.Canvas, s), yIcon, s);1410 xIcon + W + 2 - BiColorTextWidth(dst.Canvas, S), yIcon, S); 1411 1411 1412 1412 if (Kind = 12) and (val >= 100) then … … 1416 1416 if sd = 0 then 1417 1417 sd := 1; 1418 if sd < w- 44 then1418 if sd < W - 44 then 1419 1419 ld := sd 1420 1420 else 1421 ld := w- 44;1422 for i:= 0 to val mod 10 - 1 do1421 ld := W - 44; 1422 for I := 0 to val mod 10 - 1 do 1423 1423 begin 1424 BitBltCanvas(dst.Canvas, xIcon + 4 + i* (14 * ld div sd), yIcon + 2 + 1, 14,1424 BitBltCanvas(dst.Canvas, xIcon + 4 + I * (14 * ld div sd), yIcon + 2 + 1, 14, 1425 1425 14, HGrSystem.Mask.Canvas, 67 + Kind mod 8 * 15, 1426 1426 70 + Kind div 8 * 15, SRCAND); 1427 Sprite(dst, HGrSystem, xIcon + 3 + i* (14 * ld div sd), yIcon + 2,1427 Sprite(dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2, 1428 1428 14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15); 1429 1429 end; 1430 for i:= 0 to val div 10 - 1 do1430 for I := 0 to val div 10 - 1 do 1431 1431 begin 1432 1432 BitBltCanvas(dst.Canvas, xIcon + 4 + (val mod 10) * 1433 (14 * ld div sd) + i* (14 * ld div sd), yIcon + 3, 14, 14,1433 (14 * ld div sd) + I * (14 * ld div sd), yIcon + 3, 14, 14, 1434 1434 HGrSystem.Mask.Canvas, 67 + 7 mod 8 * 15, 1435 1435 70 + 7 div 8 * 15, SRCAND); 1436 1436 Sprite(dst, HGrSystem, xIcon + 3 + (val mod 10) * 1437 (14 * ld div sd) + i* (14 * ld div sd), yIcon + 2, 14,1437 (14 * ld div sd) + I * (14 * ld div sd), yIcon + 2, 14, 1438 1438 14, 67 + 7 mod 8 * 15, 1439 1439 70 + 7 div 8 * 15); … … 1449 1449 if sd = 0 then 1450 1450 sd := 1; 1451 if sd < w- 44 then1451 if sd < W - 44 then 1452 1452 ld := sd 1453 1453 else 1454 ld := w- 44;1455 for i:= 0 to val div 10 - 1 do1454 ld := W - 44; 1455 for I := 0 to val div 10 - 1 do 1456 1456 begin 1457 BitBltCanvas(dst.Canvas, xIcon + 4 + i* (14 * ld div sd), yIcon + 3, 14, 14,1457 BitBltCanvas(dst.Canvas, xIcon + 4 + I * (14 * ld div sd), yIcon + 3, 14, 14, 1458 1458 HGrSystem.Mask.Canvas, 67 + Kind mod 8 * 15, 1459 1459 70 + Kind div 8 * 15, SRCAND); 1460 Sprite(dst, HGrSystem, xIcon + 3 + i* (14 * ld div sd), yIcon + 2,1460 Sprite(dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2, 1461 1461 14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15); 1462 1462 end; 1463 for i:= 0 to val mod 10 - 1 do1463 for I := 0 to val mod 10 - 1 do 1464 1464 begin 1465 1465 BitBltCanvas(dst.Canvas, xIcon + 4 + (val div 10) * 1466 (14 * ld div sd) + i* (10 * ld div sd), yIcon + 7, 10, 10,1466 (14 * ld div sd) + I * (10 * ld div sd), yIcon + 7, 10, 10, 1467 1467 HGrSystem.Mask.Canvas, 66 + Kind mod 11 * 11, 1468 1468 115 + Kind div 11 * 11, SRCAND); 1469 1469 Sprite(dst, HGrSystem, xIcon + 3 + (val div 10) * 1470 (14 * ld div sd) + i* (10 * ld div sd), yIcon + 6, 10,1470 (14 * ld div sd) + I * (10 * ld div sd), yIcon + 6, 10, 1471 1471 10, 66 + Kind mod 11 * 11, 1472 1472 115 + Kind div 11 * 11); … … 1476 1476 end; 1477 1477 1478 procedure PaintProgressBar(ca: TCanvas; Kind, x, y, pos, Growth, max: Integer;1478 procedure PaintProgressBar(ca: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer; 1479 1479 T: TTexture); 1480 1480 var 1481 i: Integer;1482 begin 1483 if pos > max then1484 pos := max;1481 I: Integer; 1482 begin 1483 if Pos > Max then 1484 Pos := Max; 1485 1485 if Growth < 0 then 1486 1486 begin 1487 pos := pos + Growth;1488 if pos < 0 then1487 Pos := Pos + Growth; 1488 if Pos < 0 then 1489 1489 begin 1490 Growth := Growth - pos;1491 pos := 0;1490 Growth := Growth - Pos; 1491 Pos := 0; 1492 1492 end; 1493 1493 end 1494 else if pos + Growth > max then1495 Growth := max - pos;1496 Frame(ca, x - 1, y - 1, x + max, y+ 7, $000000, $000000);1497 RFrame(ca, x - 2, y - 2, x + max + 1, y+ 8, T.ColorBevelShade,1494 else if Pos + Growth > Max then 1495 Growth := Max - Pos; 1496 Frame(ca, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000); 1497 RFrame(ca, X - 2, Y - 2, X + Max + 1, Y + 8, T.ColorBevelShade, 1498 1498 T.ColorBevelLight); 1499 1499 with ca do 1500 1500 begin 1501 for i := 0 to pos div 8 - 1 do1502 BitBltCanvas(ca, x + i * 8, y, 8, 7,1501 for I := 0 to Pos div 8 - 1 do 1502 BitBltCanvas(ca, X + I * 8, Y, 8, 7, 1503 1503 HGrSystem.Data.Canvas, 104, 9 + 8 * Kind); 1504 BitBltCanvas(ca, x + 8 * (pos div 8), y, pos - 8 * (pos div 8), 7,1504 BitBltCanvas(ca, X + 8 * (Pos div 8), Y, Pos - 8 * (Pos div 8), 7, 1505 1505 HGrSystem.Data.Canvas, 104, 9 + 8 * Kind); 1506 1506 if Growth > 0 then 1507 1507 begin 1508 for i:= 0 to Growth div 8 - 1 do1509 BitBltCanvas(ca, x + pos + i * 8, y, 8, 7,1508 for I := 0 to Growth div 8 - 1 do 1509 BitBltCanvas(ca, X + Pos + I * 8, Y, 8, 7, 1510 1510 HGrSystem.Data.Canvas, 112, 9 + 8 * Kind); 1511 BitBltCanvas(ca, x + pos + 8 * (Growth div 8), y,1511 BitBltCanvas(ca, X + Pos + 8 * (Growth div 8), Y, 1512 1512 Growth - 8 * (Growth div 8), 7, HGrSystem.Data.Canvas, 1513 1513 112, 9 + 8 * Kind); … … 1515 1515 else if Growth < 0 then 1516 1516 begin 1517 for i:= 0 to -Growth div 8 - 1 do1518 BitBltCanvas(ca, x + pos + i * 8, y, 8, 7,1517 for I := 0 to -Growth div 8 - 1 do 1518 BitBltCanvas(ca, X + Pos + I * 8, Y, 8, 7, 1519 1519 HGrSystem.Data.Canvas, 104, 1); 1520 BitBltCanvas(ca, x + pos + 8 * (-Growth div 8), y, -Growth -1520 BitBltCanvas(ca, X + Pos + 8 * (-Growth div 8), Y, -Growth - 1521 1521 8 * (-Growth div 8), 7, 1522 1522 HGrSystem.Data.Canvas, 104, 1); 1523 1523 end; 1524 1524 Brush.Color := $000000; 1525 FillRect(Rect( x + pos + abs(Growth), y, x + max, y+ 7));1525 FillRect(Rect(X + Pos + abs(Growth), Y, X + Max, Y + 7)); 1526 1526 Brush.Style := bsClear; 1527 1527 end; … … 1530 1530 // pos and growth are relative to max, set size independent 1531 1531 procedure PaintRelativeProgressBar(ca: TCanvas; 1532 Kind, x, y, size, pos, Growth, max: Integer; IndicateComplete: Boolean;1532 Kind, X, Y, size, Pos, Growth, Max: Integer; IndicateComplete: Boolean; 1533 1533 T: TTexture); 1534 1534 begin 1535 1535 if Growth > 0 then 1536 PaintProgressBar(ca, Kind, x, y, pos * size div max,1537 (Growth * size + max div 2) div max, size, T)1536 PaintProgressBar(ca, Kind, X, Y, Pos * size div Max, 1537 (Growth * size + Max div 2) div Max, size, T) 1538 1538 else 1539 PaintProgressBar(ca, Kind, x, y, pos * size div max,1540 (Growth * size - max div 2) div max, size, T);1541 if IndicateComplete and ( pos + Growth >= max) then1542 Sprite(ca, HGrSystem, x + size - 10, y- 7, 23, 16, 1, 129);1539 PaintProgressBar(ca, Kind, X, Y, Pos * size div Max, 1540 (Growth * size - Max div 2) div Max, size, T); 1541 if IndicateComplete and (Pos + Growth >= Max) then 1542 Sprite(ca, HGrSystem, X + size - 10, Y - 7, 23, 16, 1, 129); 1543 1543 end; 1544 1544 … … 1610 1610 procedure DarkenImage(Bitmap: TBitmap; Change: Integer); 1611 1611 var 1612 x, y: integer;1612 X, Y: Integer; 1613 1613 PicturePixel: TPixelPointer; 1614 1614 begin 1615 1615 Bitmap.BeginUpdate; 1616 1616 PicturePixel := PixelPointer(Bitmap); 1617 for y:= 0 to ScaleToNative(Bitmap.Height) - 1 do begin1618 for x:= 0 to ScaleToNative(Bitmap.Width) - 1 do begin1617 for Y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin 1618 for X := 0 to ScaleToNative(Bitmap.Width) - 1 do begin 1619 1619 PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - Change, 0); 1620 1620 PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - Change, 0); … … 1662 1662 Section: TFontType; 1663 1663 FontScript: TextFile; 1664 Size: integer;1664 Size: Integer; 1665 1665 S: string; 1666 I: integer;1667 P: integer;1666 I: Integer; 1667 P: Integer; 1668 1668 begin 1669 1669 Section := ftNormal; … … 1672 1672 Reset(FontScript); 1673 1673 while not Eof(FontScript) do begin 1674 ReadLn(FontScript, s);1675 if s<> '' then1676 if s[1] = '#' then begin1677 s := TrimRight(s);1678 if s= '#SMALL' then Section := ftSmall1679 else if s= '#TINY' then Section := ftTiny1680 else if s= '#CAPTION' then Section := ftCaption1681 else if s= '#BUTTON' then Section := ftButton1674 ReadLn(FontScript, S); 1675 if S <> '' then 1676 if S[1] = '#' then begin 1677 S := TrimRight(S); 1678 if S = '#SMALL' then Section := ftSmall 1679 else if S = '#TINY' then Section := ftTiny 1680 else if S = '#CAPTION' then Section := ftCaption 1681 else if S = '#BUTTON' then Section := ftButton 1682 1682 else Section := ftNormal; 1683 1683 end else begin 1684 p := Pos(',', s);1685 if p> 0 then begin1686 UniFont[section].Name := Trim(Copy( s, 1, p- 1));1684 P := Pos(',', S); 1685 if P > 0 then begin 1686 UniFont[section].Name := Trim(Copy(S, 1, P - 1)); 1687 1687 Size := 0; 1688 for i := p + 1 to Length(s) do1689 case s[i] of1688 for I := P + 1 to Length(S) do 1689 case S[I] of 1690 1690 '0' .. '9': 1691 Size := Size * 10 + Byte( s[i]) - 48;1691 Size := Size * 10 + Byte(S[I]) - 48; 1692 1692 'B', 'b': 1693 1693 UniFont[section].Style := UniFont[section].Style + [fsBold]; -
trunk/Packages/CevoComponents/Sound.pas
r424 r447 280 280 begin 281 281 Result := 0; 282 while (Result < SoundList.Count) and (SoundList[ result].FFileName <> FileName) do282 while (Result < SoundList.Count) and (SoundList[Result].FFileName <> FileName) do 283 283 Inc(Result); 284 284 if Result = SoundList.Count then begin -
trunk/Packages/CevoComponents/StringTables.pas
r300 r447 16 16 constructor Create; 17 17 destructor Destroy; override; 18 function LoadFromFile(const FileName: String): boolean;19 function GetHandle(const Item: string): integer;20 function LookupByHandle(Handle: integer; Index: integer = -1): string;18 function LoadFromFile(const FileName: String): Boolean; 19 function GetHandle(const Item: string): Integer; 20 function LookupByHandle(Handle: Integer; Index: Integer = -1): string; 21 21 function Lookup(const Item: string; Index: Integer = -1): string; 22 function Search(const Content: string; var Handle, Index: integer): boolean;22 function Search(const Content: string; var Handle, Index: Integer): Boolean; 23 23 end; 24 24 … … 45 45 end; 46 46 47 function TStringTable.LoadFromFile(const FileName: String): boolean;47 function TStringTable.LoadFromFile(const FileName: String): Boolean; 48 48 begin 49 49 Result := True; … … 56 56 end; 57 57 58 function TStringTable.GetHandle(const Item: string): integer;58 function TStringTable.GetHandle(const Item: string): Integer; 59 59 var 60 60 I: Integer; … … 67 67 end; 68 68 69 function TStringTable.LookupByHandle(Handle: integer; Index: integer): string;69 function TStringTable.LookupByHandle(Handle: Integer; Index: Integer): string; 70 70 var 71 s: string;71 S: string; 72 72 begin 73 73 if Index < 0 then begin … … 77 77 end else begin 78 78 if Pos(' ', Lines[Handle]) = 0 then S := '' 79 else s:= Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt);79 else S := Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt); 80 80 while ((Handle + 1) < Lines.Count) and (Copy(Lines[Handle + 1], 1, 1) <> '#') do begin 81 81 Inc(Handle); 82 82 if (Length(Lines[Handle]) > 0) and (Lines[Handle][1] <> '''') then begin 83 if ( s <> '') and (s[Length(s)] <> '\') then84 s := s+ ' ';85 s := s+ Lines[Handle];83 if (S <> '') and (S[Length(S)] <> '\') then 84 S := S + ' '; 85 S := S + Lines[Handle]; 86 86 end; 87 87 end; … … 116 116 { might become necessary for 1.3 117 117 118 function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: integer): string;118 function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: Integer): string; 119 119 var 120 Handle: integer;120 Handle: Integer; 121 121 begin 122 122 Handle:=Gethandle(Item); 123 if Handle>=0 then result:=LookupByHandle(Handle, Index)124 else result:='';125 if result='' then126 result:=Fallback.Lookup(Item, Index);123 if Handle>=0 then Result:=LookupByHandle(Handle, Index) 124 else Result:=''; 125 if Result='' then 126 Result:=Fallback.Lookup(Item, Index); 127 127 end; 128 128 129 function TStringTable.TryLookup(const Item: string; Index: integer): string;129 function TStringTable.TryLookup(const Item: string; Index: Integer): string; 130 130 var 131 Handle: integer;131 Handle: Integer; 132 132 begin 133 133 Handle:=Gethandle(Item); 134 if Handle>=0 then result:=LookupByHandle(Handle, Index)135 else result:='';134 if Handle>=0 then Result:=LookupByHandle(Handle, Index) 135 else Result:=''; 136 136 end; } 137 137 138 138 function TStringTable.Search(const Content: string; 139 var Handle, Index: integer): boolean;139 var Handle, Index: Integer): Boolean; 140 140 var 141 h, i: integer;141 H, I: Integer; 142 142 UContent: string; 143 143 begin 144 144 UContent := UpperCase(Content); 145 h:= Handle;146 if h< 0 then147 i:= 0145 H := Handle; 146 if H < 0 then 147 I := 0 148 148 else 149 i:= Index + 1;149 I := Index + 1; 150 150 repeat 151 if h + i+ 1 >= Lines.Count then151 if H + I + 1 >= Lines.Count then 152 152 begin 153 result := false;154 exit;153 Result := False; 154 Exit; 155 155 end; 156 if Copy(Lines[ h + i+ 1], 1, 1) = '#' then156 if Copy(Lines[H + I + 1], 1, 1) = '#' then 157 157 begin 158 h := h + i+ 1;159 i:= -1;158 H := H + I + 1; 159 I := -1; 160 160 end; 161 if ( h >= 0) and not ((Length(Lines[h + i + 1]) > 0) and (Lines[h + i+ 1][1] in ['#', ':', ';'])) and162 (Pos(UContent, UpperCase(Lines[ h + i+ 1])) > 0) then161 if (H >= 0) and not ((Length(Lines[H + I + 1]) > 0) and (Lines[H + I + 1][1] in ['#', ':', ';'])) and 162 (Pos(UContent, UpperCase(Lines[H + I + 1])) > 0) then 163 163 begin 164 Index := i;165 Handle := h;164 Index := I; 165 Handle := H; 166 166 Result := True; 167 167 Exit; -
trunk/Packages/CevoComponents/UGraphicSet.pas
r424 r447 272 272 end. 273 273 274 -
trunk/Packages/CevoComponents/UTexture.pas
r380 r447 97 97 end. 98 98 99 -
trunk/Packages/Common/Common.pas
r396 r447 37 37 RegisterPackage('Common', @Register); 38 38 end. 39 -
trunk/Packages/Common/StopWatch.pas
r424 r447 35 35 implementation 36 36 37 constructor TStopWatch.Create(const startOnCreate : boolean = false) ;37 constructor TStopWatch.Create(const startOnCreate : Boolean = False) ; 38 38 begin 39 39 inherited Create; … … 72 72 begin 73 73 dt := ElapsedMiliseconds / MSecsPerSec / SecsPerDay; 74 result := Format('%d days, %s', [Trunc(dt), FormatDateTime('hh:nn:ss.z', Frac(dt))]) ;74 Result := Format('%d days, %s', [Trunc(dt), FormatDateTime('hh:nn:ss.z', Frac(dt))]) ; 75 75 end; 76 76 … … 93 93 94 94 end. 95 -
trunk/Packages/Common/UAboutDialog.pas
r424 r447 51 51 end. 52 52 53 -
trunk/Packages/Common/UCommon.pas
r424 r447 42 42 clLightRed = TColor($8080FF); 43 43 44 function AddLeadingZeroes(const aNumber, Length : integer) : string;44 function AddLeadingZeroes(const aNumber, Length : Integer) : string; 45 45 function BinToInt(BinStr: string): Int64; 46 46 function BinToHexString(Source: AnsiString): string; … … 96 96 function BinToInt(BinStr : string) : Int64; 97 97 var 98 i : byte;98 I : Byte; 99 99 RetVar : Int64; 100 100 begin 101 101 BinStr := UpperCase(BinStr); 102 if BinStr[ length(BinStr)] = 'B' then Delete(BinStr,length(BinStr),1);102 if BinStr[Length(BinStr)] = 'B' then Delete(BinStr,Length(BinStr),1); 103 103 RetVar := 0; 104 for i := 1 to length(BinStr) do begin105 if not (BinStr[ i] in ['0','1']) then begin104 for I := 1 to Length(BinStr) do begin 105 if not (BinStr[I] in ['0','1']) then begin 106 106 RetVar := 0; 107 107 Break; 108 108 end; 109 RetVar := (RetVar shl 1) + ( byte(BinStr[i]) and 1) ;109 RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1) ; 110 110 end; 111 111 … … 435 435 end; 436 436 437 function AddLeadingZeroes(const aNumber, Length : integer) : string;437 function AddLeadingZeroes(const aNumber, Length : Integer) : string; 438 438 begin 439 439 Result := SysUtils.Format('%.*d', [Length, aNumber]) ; … … 614 614 begin 615 615 for J := ReadFrom to Len do 616 if (S[ j] = C) then616 if (S[J] = C) then 617 617 begin 618 618 Result := J; … … 631 631 Inc(I); 632 632 APos := ReadUntil(I, '<'); 633 Result := Result + Copy(S, I, APos - i);633 Result := Result + Copy(S, I, APos - I); 634 634 I := ReadUntil(APos + 1, '>'); 635 635 end; -
trunk/Packages/Common/UFindFile.pas
r424 r447 6 6 Tired of using FindFirst, Next and Close? 7 7 Come see how to encapsulate all those functions 8 in a single "find-files-recursively" component.8 in A Single "find-files-recursively" component. 9 9 It's easy to use, free and with code. 10 10 … … 34 34 TFindFile = class(TComponent) 35 35 private 36 s: TStringList;37 fSubFolder : boolean;36 S : TStringList; 37 fSubFolder : Boolean; 38 38 fAttr: TFileAttrib; 39 39 fPath : string; … … 47 47 published 48 48 property FileAttr: TFileAttrib read fAttr write fAttr; 49 property InSubFolders : boolean read fSubFolder write fSubFolder;49 property InSubFolders : Boolean read fSubFolder write fSubFolder; 50 50 property Path : string read fPath write SetPath; 51 51 property FileMask : string read fFileMask write fFileMask ; … … 79 79 FileMask := FilterAll; 80 80 FileAttr := [ffaAnyFile]; 81 s:= TStringList.Create;81 S := TStringList.Create; 82 82 end; 83 83 84 84 destructor TFindFile.Destroy; 85 85 begin 86 s.Free;86 S.Free; 87 87 inherited Destroy; 88 88 end; … … 101 101 function TFindFile.SearchForFiles: TStringList; 102 102 begin 103 s.Clear;103 S.Clear; 104 104 try 105 105 FileSearch(Path); 106 106 finally 107 Result := s;107 Result := S; 108 108 end; 109 109 end; … … 111 111 procedure TFindFile.FileSearch(const InPath : string); 112 112 var Rec : TSearchRec; 113 Attr : integer;113 Attr : Integer; 114 114 begin 115 115 Attr := 0; … … 125 125 try 126 126 repeat 127 s.Add(inPath + Rec.Name);127 S.Add(inPath + Rec.Name); 128 128 until SysUtils.FindNext(Rec) <> 0; 129 129 finally -
trunk/Packages/Common/UFormAbout.pas
r423 r447 83 83 end. 84 84 85 -
trunk/Packages/Common/UGeometric.pas
r424 r447 52 52 function PointToLineDistance(const P, V, W: TPoint): Integer; 53 53 var 54 l2, t: Double;54 l2, T: Double; 55 55 tt: TPoint; 56 56 begin … … 165 165 end. 166 166 167 -
trunk/Packages/Common/UJobProgressView.pas
r424 r447 221 221 for I := 0 to ListViewJobs.Items.Count - 1 do 222 222 begin 223 ItemRect := ListViewJobs.Items[ i].DisplayRect(drBounds);223 ItemRect := ListViewJobs.Items[I].DisplayRect(drBounds); 224 224 Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top)); 225 225 end; -
trunk/Packages/Common/UMetaCanvas.pas
r424 r447 124 124 procedure SetWidth(AValue: Integer); override; 125 125 function GetWidth: Integer; override; 126 procedure DoLine (x1,y1,x2,y2: integer); override;126 procedure DoLine (x1,y1,x2,y2:Integer); override; 127 127 procedure DoTextOut(X, Y: Integer; Text: string); override; 128 128 procedure DoRectangle(const Bounds: TRect); override; … … 451 451 end; 452 452 453 procedure TMetaCanvas.DoLine(x1, y1, x2, y2: integer);453 procedure TMetaCanvas.DoLine(x1, y1, x2, y2: Integer); 454 454 var 455 455 NewObj: TCanvasLine; … … 665 665 end. 666 666 667 -
trunk/Packages/Common/UPrefixMultiplier.pas
r423 r447 30 30 BasePrefixMultipliers: TPrefixMultiplierDef = 31 31 ( 32 (ShortText: 'y'; FullText: 'yocto'; Value: 1 e-24),33 (ShortText: 'z'; FullText: 'zepto'; Value: 1 e-21),34 (ShortText: 'a'; FullText: 'atto'; Value: 1 e-18),35 (ShortText: 'f'; FullText: 'femto'; Value: 1 e-15),36 (ShortText: 'p'; FullText: 'piko'; Value: 1 e-12),37 (ShortText: 'n'; FullText: 'nano'; Value: 1 e-9),38 (ShortText: 'u'; FullText: 'mikro'; Value: 1 e-6),39 (ShortText: 'm'; FullText: 'mili'; Value: 1 e-3),32 (ShortText: 'y'; FullText: 'yocto'; Value: 1E-24), 33 (ShortText: 'z'; FullText: 'zepto'; Value: 1E-21), 34 (ShortText: 'a'; FullText: 'atto'; Value: 1E-18), 35 (ShortText: 'f'; FullText: 'femto'; Value: 1E-15), 36 (ShortText: 'p'; FullText: 'piko'; Value: 1E-12), 37 (ShortText: 'n'; FullText: 'nano'; Value: 1E-9), 38 (ShortText: 'u'; FullText: 'mikro'; Value: 1E-6), 39 (ShortText: 'm'; FullText: 'mili'; Value: 1E-3), 40 40 (ShortText: ''; FullText: ''; Value: 1e0), 41 41 (ShortText: 'k'; FullText: 'kilo'; Value: 1e3), … … 51 51 TimePrefixMultipliers: TPrefixMultiplierDef = 52 52 ( 53 (ShortText: 'ys'; FullText: 'yocto'; Value: 1 e-24),54 (ShortText: 'zs'; FullText: 'zepto'; Value: 1 e-21),55 (ShortText: 'as'; FullText: 'atto'; Value: 1 e-18),56 (ShortText: 'fs'; FullText: 'femto'; Value: 1 e-15),57 (ShortText: 'ps'; FullText: 'piko'; Value: 1 e-12),58 (ShortText: 'ns'; FullText: 'nano'; Value: 1 e-9),59 (ShortText: 'us'; FullText: 'mikro'; Value: 1 e-6),60 (ShortText: 'ms'; FullText: 'mili'; Value: 1 e-3),53 (ShortText: 'ys'; FullText: 'yocto'; Value: 1E-24), 54 (ShortText: 'zs'; FullText: 'zepto'; Value: 1E-21), 55 (ShortText: 'as'; FullText: 'atto'; Value: 1E-18), 56 (ShortText: 'fs'; FullText: 'femto'; Value: 1E-15), 57 (ShortText: 'ps'; FullText: 'piko'; Value: 1E-12), 58 (ShortText: 'ns'; FullText: 'nano'; Value: 1E-9), 59 (ShortText: 'us'; FullText: 'mikro'; Value: 1E-6), 60 (ShortText: 'ms'; FullText: 'mili'; Value: 1E-3), 61 61 (ShortText: 's'; FullText: 'sekunda'; Value: 1), 62 62 (ShortText: 'min'; FullText: 'minuta'; Value: 60), -
trunk/Packages/Common/UResetableThread.pas
r423 r447 296 296 end. 297 297 298 -
trunk/Packages/Common/UScaleDPI.pas
r424 r447 259 259 begin 260 260 ImgList.Add(Temp[I], nil); 261 Temp[ i].Free;261 Temp[I].Free; 262 262 end; 263 263 finally -
trunk/Packages/Common/UStringTable.pas
r424 r447 39 39 function TStringTable.GetColCount: Integer; 40 40 begin 41 Result := Size. x;41 Result := Size.X; 42 42 end; 43 43 -
trunk/Packages/Common/UTheme.pas
r424 r447 188 188 189 189 end. 190 -
trunk/Packages/Common/UTranslator.pas
r424 r447 420 420 421 421 if Lang = '' then begin 422 for i:= 1 to Paramcount - 1 do423 if (ParamStr( i) = '--LANG') or (ParamStr(i) = '-l') or424 (ParamStr( i) = '--lang') then425 Lang := ParamStr( i+ 1);422 for I := 1 to Paramcount - 1 do 423 if (ParamStr(I) = '--LANG') or (ParamStr(I) = '-l') or 424 (ParamStr(I) = '--lang') then 425 Lang := ParamStr(I + 1); 426 426 end; 427 427 if Lang = '' then begin … … 473 473 DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 474 474 if FileExistsUTF8(Result) then 475 exit;475 Exit; 476 476 477 477 Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + LangID + 478 478 DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 479 479 if FileExistsUTF8(Result) then 480 exit;480 Exit; 481 481 482 482 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator 483 483 + LangID + DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 484 484 if FileExistsUTF8(Result) then 485 exit;485 Exit; 486 486 487 487 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator … … 489 489 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 490 490 if FileExistsUTF8(Result) then 491 exit;491 Exit; 492 492 493 493 {$IFDEF UNIX} … … 496 496 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 497 497 if FileExistsUTF8(Result) then 498 exit;498 Exit; 499 499 {$ENDIF} 500 500 // Let us search for reducted files 501 LangShortID := copy(LangID, 1, 2);501 LangShortID := Copy(LangID, 1, 2); 502 502 // At first, check all was checked 503 503 Result := ExtractFilePath(ParamStrUTF8(0)) + LangShortID + 504 504 DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 505 505 if FileExistsUTF8(Result) then 506 exit;506 Exit; 507 507 508 508 Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + … … 510 510 ExtractFileName(ParamStrUTF8(0)), LCExt); 511 511 if FileExistsUTF8(Result) then 512 exit;512 Exit; 513 513 514 514 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator … … 516 516 ExtractFileName(ParamStrUTF8(0)), LCExt); 517 517 if FileExistsUTF8(Result) then 518 exit;518 Exit; 519 519 520 520 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator … … 522 522 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 523 523 if FileExistsUTF8(Result) then 524 exit;524 Exit; 525 525 526 526 // Full language in file name - this will be default for the project … … 529 529 Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt; 530 530 if FileExistsUTF8(Result) then 531 exit;531 Exit; 532 532 // Common location (like in Lazarus) 533 533 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + 534 534 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt; 535 535 if FileExistsUTF8(Result) then 536 exit;536 Exit; 537 537 538 538 Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + 539 539 DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt; 540 540 if FileExistsUTF8(Result) then 541 exit;541 Exit; 542 542 except 543 543 Result := ''; // Or do something else (useless) … … 548 548 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt); 549 549 if FileExistsUTF8(Result) then 550 exit;550 Exit; 551 551 {$ENDIF} 552 552 Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt( 553 553 ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt; 554 554 if FileExistsUTF8(Result) then 555 exit;555 Exit; 556 556 557 557 Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator + 558 558 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt; 559 559 if FileExistsUTF8(Result) then 560 exit;560 Exit; 561 561 562 562 Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + 563 563 ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt; 564 564 if FileExistsUTF8(Result) then 565 exit;565 Exit; 566 566 end; 567 567 -
trunk/Platform.pas
r442 r447 61 61 end. 62 62 63 -
trunk/Protocol.pas
r420 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), … … 1563 1563 TGetCityData = record 1564 1564 Owner: Integer; 1565 c: TCity;1565 C: TCity; 1566 1566 end; 1567 1567 … … 1644 1644 TCreateUnitData = record 1645 1645 Loc: Integer; 1646 p: Integer;1646 P: Integer; 1647 1647 mix: Integer; 1648 1648 end; … … 1653 1653 TOwnerList = array [0 .. INFIN] of ShortInt; 1654 1654 TByteList = array [0 .. INFIN] of Byte; 1655 TIntList = array [0 .. INFIN] of integer;1655 TIntList = array [0 .. INFIN] of Integer; 1656 1656 TCityList = array [0 .. INFIN] of TCity; 1657 1657 TUnList = array [0 .. INFIN] of TUn; … … 1815 1815 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); 1816 1816 1817 SpecialModelPreq: array [0 .. nSpecialModel - 1] of integer = (preNone,1817 SpecialModelPreq: array [0 .. nSpecialModel - 1] of Integer = (preNone, 1818 1818 adExplosives, preNone, preNone, (* adWri, *) adIntelligence, adTrade, 1819 1819 (* adTheCorporation,adHorsebackRiding,adAutomobile,adNavigation, … … 1824 1824 DelphiRandSeed: Integer; 1825 1825 1826 procedure MakeUnitInfo( p: Integer; const u: TUn; var ui: TUnitInfo);1827 procedure MakeModelInfo( p, mix: Integer; const m: TModel; var mi: TModelInfo);1826 procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo); 1827 procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo); 1828 1828 function IsSameModel(const mi1, mi2: TModelInfo): Boolean; 1829 1829 function SpecialTile(Loc, TerrType, lx: Integer): Integer; … … 1836 1836 implementation 1837 1837 1838 procedure MakeUnitInfo( p: Integer; const u: TUn; var ui: TUnitInfo);1838 procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo); 1839 1839 begin 1840 ui.Owner := p;1841 ui.Loc := u.Loc;1842 ui.Health := u.Health;1843 ui.Fuel := u.Fuel;1844 ui.Job := u.Job;1845 ui.Exp := u.Exp;1846 ui.Load := u.TroopLoad + u.AirLoad;1847 ui.mix := u.mix;1848 ui.Flags := u.Flags;1840 ui.Owner := P; 1841 ui.Loc := U.Loc; 1842 ui.Health := U.Health; 1843 ui.Fuel := U.Fuel; 1844 ui.Job := U.Job; 1845 ui.Exp := U.Exp; 1846 ui.Load := U.TroopLoad + U.AirLoad; 1847 ui.mix := U.mix; 1848 ui.Flags := U.Flags; 1849 1849 end; 1850 1850 1851 procedure MakeModelInfo( p, mix: Integer; const m: TModel; var mi: TModelInfo);1851 procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo); 1852 1852 var 1853 i: Integer;1853 I: Integer; 1854 1854 begin 1855 mi.Owner := p;1855 mi.Owner := P; 1856 1856 mi.mix := mix; 1857 mi.ID := m.ID;1858 mi.Domain := m.Domain;1859 if m.Kind = mkEnemyDeveloped then1857 mi.ID := M.ID; 1858 mi.Domain := M.Domain; 1859 if M.Kind = mkEnemyDeveloped then 1860 1860 mi.Kind := mkSelfDeveloped // important for IsSameModel() 1861 1861 else 1862 mi.Kind := m.Kind;1863 mi.Attack := m.Attack;1864 mi.Defense := m.Defense;1865 mi.Speed := m.Speed;1866 mi.Cost := m.Cost;1862 mi.Kind := M.Kind; 1863 mi.Attack := M.Attack; 1864 mi.Defense := M.Defense; 1865 mi.Speed := M.Speed; 1866 mi.Cost := M.Cost; 1867 1867 if mi.Domain = dAir then 1868 1868 begin 1869 mi.TTrans := m.Cap[mcAirTrans] * m.MTrans;1870 mi.ATrans_Fuel := m.Cap[mcFuel];1869 mi.TTrans := M.Cap[mcAirTrans] * M.MTrans; 1870 mi.ATrans_Fuel := M.Cap[mcFuel]; 1871 1871 end 1872 1872 else 1873 1873 begin 1874 mi.TTrans := m.Cap[mcSeaTrans] * m.MTrans;1875 mi.ATrans_Fuel := m.Cap[mcCarrier] * m.MTrans;1876 end; 1877 mi.Bombs := m.Cap[mcBombs] * m.MStrength * 2;1874 mi.TTrans := M.Cap[mcSeaTrans] * M.MTrans; 1875 mi.ATrans_Fuel := M.Cap[mcCarrier] * M.MTrans; 1876 end; 1877 mi.Bombs := M.Cap[mcBombs] * M.MStrength * 2; 1878 1878 mi.Cap := 0; 1879 for i:= mcFirstNonCap to nFeature - 1 do1880 if m.Cap[i] > 0 then1881 mi.Cap := mi.Cap or (1 shl ( i- mcFirstNonCap));1879 for I := mcFirstNonCap to nFeature - 1 do 1880 if M.Cap[I] > 0 then 1881 mi.Cap := mi.Cap or (1 shl (I - mcFirstNonCap)); 1882 1882 mi.MaxUpgrade := 0; 1883 for i:= 1 to nUpgrade - 1 do1884 if m.Upgrades and (1 shl i) <> 0 then1885 mi.MaxUpgrade := i;1886 mi.Weight := m.Weight;1883 for I := 1 to nUpgrade - 1 do 1884 if M.Upgrades and (1 shl I) <> 0 then 1885 mi.MaxUpgrade := I; 1886 mi.Weight := M.Weight; 1887 1887 mi.Lost := 0; 1888 1888 end; … … 1896 1896 Compare1 := @mi1; 1897 1897 Compare2 := @mi2; 1898 result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and1898 Result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and 1899 1899 (Compare1[2] = Compare2[2]) and (Compare1[3] = Compare2[3]) and 1900 1900 (Compare1[4] = Compare2[4]) and (Compare1[5] = Compare2[5]) … … 1903 1903 function SpecialTile(Loc, TerrType, lx: Integer): Integer; 1904 1904 var 1905 x, y, qx, qy, a: Integer;1905 X, Y, qx, qy, A: Integer; 1906 1906 begin 1907 1907 if TerrType = fOcean then 1908 result := 01908 Result := 0 1909 1909 else 1910 1910 begin 1911 y:= Loc div lx;1912 x := Loc - y* lx;1911 Y := Loc div lx; 1912 X := Loc - Y * lx; 1913 1913 if TerrType = fGrass then { formula for productive grassland } 1914 if Odd((lymax + x - y shr 1) shr 1 + x + (y+ 1) shr 1) then1915 result := 11914 if Odd((lymax + X - Y shr 1) shr 1 + X + (Y + 1) shr 1) then 1915 Result := 1 1916 1916 else 1917 result := 01917 Result := 0 1918 1918 else { formula for special resources } 1919 1919 begin 1920 a := 4 * x - y+ 9980;1921 qx := adiv 10;1922 if (qx * 10 = a) and (qx and 3 <> 0) then1920 A := 4 * X - Y + 9980; 1921 qx := A div 10; 1922 if (qx * 10 = A) and (qx and 3 <> 0) then 1923 1923 begin 1924 qy := ( y + x) div 5;1924 qy := (Y + X) div 5; 1925 1925 if qy and 3 <> qx shr 2 and 1 * 2 then 1926 1926 if (TerrType = fArctic) or (TerrType = fSwamp) then 1927 result := 11927 Result := 1 1928 1928 else if TerrType = fShore then 1929 1929 begin 1930 1930 if (qx + qy) and 1 = 0 then 1931 1931 if qx and 3 = 2 then 1932 result := 21932 Result := 2 1933 1933 else 1934 result := 11934 Result := 1 1935 1935 else 1936 result := 01936 Result := 0 1937 1937 end 1938 1938 else 1939 result := (qx + qy) and 1 + 11939 Result := (qx + qy) and 1 + 1 1940 1940 else 1941 result := 0;1941 Result := 0; 1942 1942 end 1943 1943 else 1944 result := 0;1944 Result := 0; 1945 1945 end; 1946 1946 end; -
trunk/Settings.pas
r433 r447 293 293 end. 294 294 295 -
trunk/Start.pas
r442 r447 69 69 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 70 70 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 71 Shift: TShiftState; x, y: integer);71 Shift: TShiftState; X, Y: Integer); 72 72 procedure FormMouseUp(Sender: TObject; Button: TMouseButton; 73 Shift: TShiftState; x, y: integer);74 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);73 Shift: TShiftState; X, Y: Integer); 74 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 75 75 procedure Up1BtnClick(Sender: TObject); 76 76 procedure Down1BtnClick(Sender: TObject); … … 122 122 MiniMap: TMiniMap; 123 123 LastGame: string; 124 procedure DrawAction( y, IconIndex: integer; HeaderItem, TextItem: string);124 procedure DrawAction(Y, IconIndex: Integer; HeaderItem, TextItem: string); 125 125 procedure InitPopup(PlayerIndex: Integer); 126 126 procedure OfferBrain(Brain: TBrain; FixedLines: Integer); … … 129 129 procedure ChangeTab(NewTab: TStartTab); 130 130 procedure UnlistBackupFile(FileName: string); 131 procedure SmartInvalidate(x0, y0, x1, y1: integer;132 invalidateTab0: boolean = false); overload;131 procedure SmartInvalidate(x0, y0, x1, y1: Integer; 132 invalidateTab0: Boolean = False); overload; 133 133 procedure LoadConfig; 134 134 procedure SaveConfig; … … 160 160 // attention: lx*ly+1 must be prime! 161 161 { MaxWorldSize=8; 162 lxpre: array[0..nWorldSize-1] of integer =(30,40,50,60,70,90,110,130);163 lypre: array[0..nWorldSize-1] of integer =(46,52,60,70,84,94,110,130);162 lxpre: array[0..nWorldSize-1] of Integer =(30,40,50,60,70,90,110,130); 163 lypre: array[0..nWorldSize-1] of Integer =(46,52,60,70,84,94,110,130); 164 164 DefaultWorldTiles=4200; } 165 165 MaxWorldSize = 6; … … 192 192 dxBrain = 104; 193 193 dyBrain = 80; 194 xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,194 xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain, 195 195 x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain, 196 196 x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain); 197 yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,197 yBrain: array [0 .. nPlOffered - 1] of Integer = (y0Brain, y0Brain - dyBrain, 198 198 y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain, 199 199 y0Brain + dyBrain, y0Brain, y0Brain - dyBrain); … … 202 202 TabHeight = 40; 203 203 204 InitAlive: array [1 .. nPl] of integer = (1, 1 + 2, 1 + 2 + 32,204 InitAlive: array [1 .. nPl] of Integer = (1, 1 + 2, 1 + 2 + 32, 205 205 1 + 2 + 8 + 128, 1 + 2 + 8 + 32 + 128, 1 + 2 + 8 + 16 + 64 + 128, 206 206 1 + 2 + 4 + 16 + 32 + 64 + 256, 511 - 32, 511, 511 - 32, 511, 511 - 32, 511, 207 207 511 - 32, 511); 208 InitMulti: array [nPlOffered + 1 .. nPl] of integer = (256, 256, 256 + 128,208 InitMulti: array [nPlOffered + 1 .. nPl] of Integer = (256, 256, 256 + 128, 209 209 256 + 128, 256 + 128 + 64, 256 + 128 + 64); 210 210 211 PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3);212 EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1);211 PlayerAutoDiff: array [1 .. 5] of Integer = (1, 1, 2, 2, 3); 212 EnemyAutoDiff: array [1 .. 5] of Integer = (4, 3, 2, 1, 1); 213 213 214 214 { TStartDlg } … … 216 216 procedure TStartDlg.FormCreate(Sender: TObject); 217 217 var 218 x, i: Integer;218 X, I: Integer; 219 219 PlayerSlot: TPlayerSlot; 220 220 AIBrains: TBrains; … … 236 236 237 237 BrainDefault := nil; 238 for i:= Brains.IndexOf(BrainRandom) to Brains.Count - 1 do239 if AnsiCompareFileName(DefaultAI, Brains[ i].FileName) = 0 then240 BrainDefault := Brains[ i];238 for I := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do 239 if AnsiCompareFileName(DefaultAI, Brains[I].FileName) = 0 then 240 BrainDefault := Brains[I]; 241 241 if (BrainDefault = BrainRandom) and (Brains.GetKindCount(btAI) < 2) then 242 242 BrainDefault := nil; … … 260 260 ReplayBtn.Hint := Phrases.Lookup('BTN_REPLAY'); 261 261 PlayerSlots.Count := nPlOffered; 262 for i:= 0 to PlayerSlots.Count - 1 do263 with PlayerSlots[ i] do begin262 for I := 0 to PlayerSlots.Count - 1 do 263 with PlayerSlots[I] do begin 264 264 DiffUpBtn := TButtonC.Create(self); 265 265 DiffUpBtn.Graphic := HGrSystem.Data; 266 DiffUpBtn.left := xBrain[ i] - 18;267 DiffUpBtn.top := yBrain[ i] + 39;266 DiffUpBtn.left := xBrain[I] - 18; 267 DiffUpBtn.top := yBrain[I] + 39; 268 268 DiffUpBtn.ButtonIndex := 1; 269 269 DiffUpBtn.Parent := self; … … 271 271 DiffDownBtn := TButtonC.Create(self); 272 272 DiffDownBtn.Graphic := HGrSystem.Data; 273 DiffDownBtn.left := xBrain[ i] - 18;274 DiffDownBtn.top := yBrain[ i] + 51;273 DiffDownBtn.left := xBrain[I] - 18; 274 DiffDownBtn.top := yBrain[I] + 51; 275 275 DiffDownBtn.ButtonIndex := 0; 276 276 DiffDownBtn.Parent := self; 277 277 DiffDownBtn.OnClick := DiffBtnClick; 278 278 end; 279 for i:= 6 to 8 do280 with PlayerSlots[ i] do begin279 for I := 6 to 8 do 280 with PlayerSlots[I] do begin 281 281 MultiBtn := TButtonC.Create(self); 282 282 MultiBtn.Graphic := HGrSystem.Data; 283 MultiBtn.left := xBrain[ i] - 18;284 MultiBtn.top := yBrain[ i];283 MultiBtn.left := xBrain[I] - 18; 284 MultiBtn.top := yBrain[I]; 285 285 MultiBtn.Parent := self; 286 286 MultiBtn.OnClick := MultiBtnClick; … … 288 288 end; 289 289 290 x:= BiColorTextWidth(Canvas, Phrases.Lookup('STARTCONTROLS', 7)) div 2;291 CustomizeBtn.left := x0Brain + 32 - 16 - x;290 X := BiColorTextWidth(Canvas, Phrases.Lookup('STARTCONTROLS', 7)) div 2; 291 CustomizeBtn.left := x0Brain + 32 - 16 - X; 292 292 if AutoDiff < 0 then 293 293 CustomizeBtn.ButtonIndex := 3 … … 339 339 end; 340 340 341 procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: integer;342 invalidateTab0: boolean);343 var 344 i: integer;341 procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: Integer; 342 invalidateTab0: Boolean); 343 var 344 I: Integer; 345 345 r0, r1: HRgn; 346 346 begin 347 347 r0 := CreateRectRgn(x0, y0, x1, y1); 348 for i:= 0 to ControlCount - 1 do349 if not (Controls[ i] is TArea) and Controls[i].Visible then348 for I := 0 to ControlCount - 1 do 349 if not (Controls[I] is TArea) and Controls[I].Visible then 350 350 begin 351 with Controls[ i].BoundsRect do351 with Controls[I].BoundsRect do 352 352 r1 := CreateRectRgn(left, top, Right, Bottom); 353 353 CombineRgn(r0, r0, r1, RGN_DIFF); … … 359 359 DeleteObject(r1); 360 360 end; 361 InvalidateRgn(Handle, r0, false);361 InvalidateRgn(Handle, r0, False); 362 362 DeleteObject(r0); 363 363 end; … … 530 530 end; 531 531 532 procedure TStartDlg.DrawAction( y, IconIndex: integer; HeaderItem, TextItem: string);532 procedure TStartDlg.DrawAction(Y, IconIndex: Integer; HeaderItem, TextItem: string); 533 533 begin 534 534 Canvas.Font.Assign(UniFont[ftCaption]); 535 535 Canvas.Font.Style := Canvas.Font.Style + [fsUnderline]; 536 RisedTextOut(Canvas, xAction, y- 3, Phrases2.Lookup(HeaderItem));536 RisedTextOut(Canvas, xAction, Y - 3, Phrases2.Lookup(HeaderItem)); 537 537 Canvas.Font.Assign(UniFont[ftNormal]); 538 538 BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText], 539 $000000, xAction, y+ 21, Phrases2.Lookup(TextItem));539 $000000, xAction, Y + 21, Phrases2.Lookup(TextItem)); 540 540 541 541 UnshareBitmap(LogoBuffer); 542 542 BitBltCanvas(LogoBuffer.Canvas, 0, 0, 50, 50, Canvas, 543 xActionIcon - 2, y- 2);543 xActionIcon - 2, Y - 2); 544 544 GlowFrame(LogoBuffer, 8, 8, 34, 34, $202020); 545 BitBltCanvas(Canvas, xActionIcon - 2, y- 2, 50, 50,545 BitBltCanvas(Canvas, xActionIcon - 2, Y - 2, 50, 50, 546 546 LogoBuffer.Canvas, 0, 0); 547 BitBltCanvas(Canvas, xActionIcon, y, 40, 40, BigImp.Canvas,547 BitBltCanvas(Canvas, xActionIcon, Y, 40, 40, BigImp.Canvas, 548 548 (IconIndex mod 7) * xSizeBig + 8, (IconIndex div 7) * ySizeBig); 549 RFrame(Canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y+ 40,549 RFrame(Canvas, xActionIcon - 1, Y - 1, xActionIcon + 40, Y + 40, 550 550 $000000, $000000); 551 551 end; … … 555 555 TabNames: array[TStartTab] of Integer = (0, 11, 3, 4); 556 556 var 557 i, w, h, xMini, yMini, y: integer;558 s: string;557 I, W, H, xMini, yMini, Y: Integer; 558 S: string; 559 559 Tab2: TStartTab; 560 560 MainAction: TMainAction; … … 588 588 589 589 // draw tabs 590 Frame(Canvas, 2, 2 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize - 1,590 Frame(Canvas, 2, 2 + 2 * Integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize - 1, 591 591 TabHeight, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 592 Frame(Canvas, 1, 1 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize,592 Frame(Canvas, 1, 1 + 2 * Integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize, 593 593 TabHeight, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 594 Canvas.Pixels[1, 1 + 2 * integer(Tab <> tbMain)] := MainTexture.ColorBevelShade;594 Canvas.Pixels[1, 1 + 2 * Integer(Tab <> tbMain)] := MainTexture.ColorBevelShade; 595 595 for Tab2 := tbMap to tbPrevious do 596 596 begin 597 Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 2, 2 + 2 * integer(Tab <> Tab2),597 Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 2, 2 + 2 * Integer(Tab <> Tab2), 598 598 TabOffset + (Integer(Tab2) + 1) * TabSize - 1, TabHeight, MainTexture.ColorBevelLight, 599 599 MainTexture.ColorBevelShade); 600 Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2),600 Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * Integer(Tab <> Tab2), 601 601 TabOffset + (Integer(Tab2) + 1) * TabSize, TabHeight, MainTexture.ColorBevelLight, 602 602 MainTexture.ColorBevelShade); 603 Canvas.Pixels[TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2)] :=603 Canvas.Pixels[TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * Integer(Tab <> Tab2)] := 604 604 MainTexture.ColorBevelShade; 605 605 end; … … 607 607 for Tab2 := tbMap to tbPrevious do 608 608 begin 609 s:= Phrases.Lookup('STARTCONTROLS', TabNames[Tab2]);609 S := Phrases.Lookup('STARTCONTROLS', TabNames[Tab2]); 610 610 RisedTextOut(Canvas, TabOffset + Integer(Tab2) * TabSize + 1 + 611 (TabSize - BiColorTextWidth(Canvas, s)) div 2,612 10 + 2 * integer(Tab <> Tab2), s);611 (TabSize - BiColorTextWidth(Canvas, S)) div 2, 612 10 + 2 * Integer(Tab <> Tab2), S); 613 613 end; 614 614 Frame(Canvas, TabOffset + 4 * TabSize + 1, -1, ClientWidth, TabHeight, … … 640 640 UnshareBitmap(LogoBuffer); 641 641 BitBltCanvas(LogoBuffer.Canvas, 0, 0, MenuLogo.Width, MenuLogo.Height, Canvas, 6, 642 3 + 2 * integer(Tab <> tbMain));642 3 + 2 * Integer(Tab <> tbMain)); 643 643 644 644 ImageOp_BCC(LogoBuffer, Templates.Data, 0, 0, MenuLogo.Left, MenuLogo.Top, … … 646 646 ImageOp_BCC(LogoBuffer, Templates.Data, 10, 27, MenuLogo.Left + 10, 647 647 MenuLogo.Top + 27, MenuLogo.Width - 10, 9, $BFBF20, $4040DF); // logo part 2 648 BitBltCanvas(Canvas, 6, 3 + 2 * integer(Tab <> tbMain), MenuLogo.Width, MenuLogo.Height,648 BitBltCanvas(Canvas, 6, 3 + 2 * Integer(Tab <> tbMain), MenuLogo.Width, MenuLogo.Height, 649 649 LogoBuffer.Canvas, 0, 0); 650 650 651 651 if Page = pgMain then begin 652 652 if SelectedAction <> maNone then // mark selected action 653 for i:= 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do653 for I := 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do 654 654 begin 655 w := ClientWidth - 2 * ActionSideBorder - i* wBuffer;656 if w> wBuffer then657 w:= wBuffer;658 h:= ActionPitch;659 if yAction + Integer(SelectedAction) * ActionPitch - 8 + h> ClientHeight - ActionBottomBorder655 W := ClientWidth - 2 * ActionSideBorder - I * wBuffer; 656 if W > wBuffer then 657 W := wBuffer; 658 H := ActionPitch; 659 if yAction + Integer(SelectedAction) * ActionPitch - 8 + H > ClientHeight - ActionBottomBorder 660 660 then 661 h:= ClientHeight - ActionBottomBorder -661 H := ClientHeight - ActionBottomBorder - 662 662 (yAction + Integer(SelectedAction) * ActionPitch - 8); 663 663 664 664 UnshareBitmap(LogoBuffer); 665 BitBltCanvas(LogoBuffer.Canvas, 0, 0, w, h, Canvas,666 ActionSideBorder + i* wBuffer, yAction + Integer(SelectedAction) * ActionPitch665 BitBltCanvas(LogoBuffer.Canvas, 0, 0, W, H, Canvas, 666 ActionSideBorder + I * wBuffer, yAction + Integer(SelectedAction) * ActionPitch 667 667 - 8); 668 MakeBlue(LogoBuffer, 0, 0, w, h);669 BitBltCanvas(Canvas, ActionSideBorder + i* wBuffer,670 yAction + Integer(SelectedAction) * ActionPitch - 8, w, h,668 MakeBlue(LogoBuffer, 0, 0, W, H); 669 BitBltCanvas(Canvas, ActionSideBorder + I * wBuffer, 670 yAction + Integer(SelectedAction) * ActionPitch - 8, W, H, 671 671 LogoBuffer.Canvas, 0, 0); 672 672 end; 673 y:= yAction;673 Y := yAction; 674 674 for MainAction := Low(TMainActionSet) to High(TMainActionSet) do 675 675 begin 676 676 if MainAction in ActionsOffered then 677 677 case MainAction of 678 maConfig: DrawAction( y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');679 maManual: DrawAction( y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');680 maCredits: DrawAction( y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');681 maAIDev: DrawAction( y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');678 maConfig: DrawAction(Y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG'); 679 maManual: DrawAction(Y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL'); 680 maCredits: DrawAction(Y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS'); 681 maAIDev: DrawAction(Y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV'); 682 682 maWeb: 683 683 begin 684 684 Canvas.Font.Assign(UniFont[ftCaption]); 685 685 // Canvas.Font.Style:=Canvas.Font.Style+[fsUnderline]; 686 RisedTextOut(Canvas, xActionIcon + 99, y,686 RisedTextOut(Canvas, xActionIcon + 99, Y, 687 687 Format(Phrases2.Lookup('ACTIONHEADER_WEB'), [CevoHomepageShort])); 688 688 Canvas.Font.Assign(UniFont[ftNormal]); … … 690 690 UnshareBitmap(LogoBuffer); 691 691 BitBltCanvas(LogoBuffer.Canvas, 0, 0, LinkArrows.Width, LinkArrows.Height, Canvas, 692 xActionIcon, y+ 2);692 xActionIcon, Y + 2); 693 693 ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), LinkArrows.BoundsRect, 0, 694 694 Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText]); 695 BitBltCanvas(Canvas, xActionIcon, y+ 2, LinkArrows.Width, LinkArrows.Height,695 BitBltCanvas(Canvas, xActionIcon, Y + 2, LinkArrows.Width, LinkArrows.Height, 696 696 LogoBuffer.Canvas, 0, 0); 697 697 end; 698 698 end; 699 Inc( y, ActionPitch);699 Inc(Y, ActionPitch); 700 700 end; 701 701 end … … 705 705 TurnToString(MaxTurn), 344, y0Mini + 61, 170); 706 706 707 s:= Phrases.Lookup('STARTCONTROLS', 7);708 w := Canvas.TextWidth(s);709 LoweredTextOut(Canvas, -2, MainTexture, x0Brain + 32 - wdiv 2,710 y0Brain + dyBrain + 69, s);707 S := Phrases.Lookup('STARTCONTROLS', 7); 708 W := Canvas.TextWidth(S); 709 LoweredTextOut(Canvas, -2, MainTexture, x0Brain + 32 - W div 2, 710 y0Brain + dyBrain + 69, S); 711 711 712 712 InitOrnament; 713 713 if AutoDiff < 0 then 714 714 begin 715 for i:= 12 to 19 do716 if ( i < 13) or (i> 17) then begin717 BitBltCanvas(Canvas, 9 + i* 27, yLogo - 2, Ornament.Width, Ornament.Height,715 for I := 12 to 19 do 716 if (I < 13) or (I > 17) then begin 717 BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height, 718 718 HGrSystem2.Mask.Canvas, Ornament.Left, Ornament.Top, SRCAND); 719 BitBltCanvas(Canvas, 9 + i* 27, yLogo - 2, Ornament.Width, Ornament.Height,719 BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height, 720 720 HGrSystem2.Data.Canvas, Ornament.Left, Ornament.Top, SRCPAINT); 721 721 end; … … 723 723 MainTexture.ColorBevelShade); 724 724 725 for i:= 0 to nPlOffered - 1 do726 if 1 shl iand SlotAvailable <> 0 then725 for I := 0 to nPlOffered - 1 do 726 if 1 shl I and SlotAvailable <> 0 then 727 727 begin 728 if Assigned(PlayersBrain[ i]) then729 FrameImage(Canvas, PlayersBrain[ i].Picture, xBrain[i], yBrain[i],730 64, 64, 0, 0, true)728 if Assigned(PlayersBrain[I]) then 729 FrameImage(Canvas, PlayersBrain[I].Picture, xBrain[I], yBrain[I], 730 64, 64, 0, 0, True) 731 731 else 732 FrameImage(Canvas, EmptyPicture, xBrain[ i], yBrain[i], 64, 64,733 0, 0, true);734 if Assigned(PlayersBrain[I]) and (PlayersBrain[ i].Kind in [btTerm, btRandom, btAI]) then732 FrameImage(Canvas, EmptyPicture, xBrain[I], yBrain[I], 64, 64, 733 0, 0, True); 734 if Assigned(PlayersBrain[I]) and (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then 735 735 begin 736 BitBltCanvas(Canvas, xBrain[ i] - 18, yBrain[i] + 19, 12, 14,737 HGrSystem.Data.Canvas, 134 + (Difficulty[ i] - 1) *736 BitBltCanvas(Canvas, xBrain[I] - 18, yBrain[I] + 19, 12, 14, 737 HGrSystem.Data.Canvas, 134 + (Difficulty[I] - 1) * 738 738 13, 28); 739 Frame(Canvas, xBrain[ i] - 19, yBrain[i] + 18, xBrain[i] - 18 + 12,740 yBrain[ i] + (19 + 14), $000000, $000000);741 RFrame(Canvas, PlayerSlots[ i].DiffUpBtn.left - 1, PlayerSlots[i].DiffUpBtn.top - 1,742 PlayerSlots[ i].DiffUpBtn.left + 12, PlayerSlots[i].DiffUpBtn.top + 24,739 Frame(Canvas, xBrain[I] - 19, yBrain[I] + 18, xBrain[I] - 18 + 12, 740 yBrain[I] + (19 + 14), $000000, $000000); 741 RFrame(Canvas, PlayerSlots[I].DiffUpBtn.left - 1, PlayerSlots[I].DiffUpBtn.top - 1, 742 PlayerSlots[I].DiffUpBtn.left + 12, PlayerSlots[I].DiffUpBtn.top + 24, 743 743 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 744 744 with Canvas do 745 745 begin 746 746 Brush.Color := $000000; 747 FillRect(Rect(xBrain[ i] - 5, yBrain[i] + 25, xBrain[i] - 2,748 yBrain[ i] + 27));747 FillRect(Rect(xBrain[I] - 5, yBrain[I] + 25, xBrain[I] - 2, 748 yBrain[I] + 27)); 749 749 Brush.Style := bsClear; 750 750 end; … … 754 754 PlayerSlots[I].MultiBtn.left + 12, PlayerSlots[I].MultiBtn.top + 12, 755 755 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 756 BitBltCanvas(Canvas, xBrain[ i] - 31, yBrain[i], 13, 12,756 BitBltCanvas(Canvas, xBrain[I] - 31, yBrain[I], 13, 12, 757 757 HGrSystem.Data.Canvas, 88, 47); 758 758 end; 759 759 end; 760 if Assigned(PlayersBrain[ i]) then760 if Assigned(PlayersBrain[I]) then 761 761 begin 762 PlayerSlots[ i].DiffUpBtn.Hint := Format(Phrases.Lookup('STARTCONTROLS', 9),763 [PlayersBrain[ i].Name]);764 PlayerSlots[ i].DiffDownBtn.Hint := PlayerSlots[i].DiffUpBtn.Hint;762 PlayerSlots[I].DiffUpBtn.Hint := Format(Phrases.Lookup('STARTCONTROLS', 9), 763 [PlayersBrain[I].Name]); 764 PlayerSlots[I].DiffDownBtn.Hint := PlayerSlots[I].DiffUpBtn.Hint; 765 765 end; 766 766 end; … … 773 773 yMain + 140 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 15)); 774 774 if Page = pgStartRandom then 775 s:= IntToStr(AutoEnemies)775 S := IntToStr(AutoEnemies) 776 776 else if nMapStartPositions = 0 then 777 s:= '0'777 S := '0' 778 778 else 779 s:= IntToStr(nMapStartPositions - 1);780 RisedTextOut(Canvas, 198 - BiColorTextWidth(Canvas, s), yMain + 140, s);779 S := IntToStr(nMapStartPositions - 1); 780 RisedTextOut(Canvas, 198 - BiColorTextWidth(Canvas, S), yMain + 140, S); 781 781 782 782 DLine(Canvas, 24, xDefault - 6, yMain + 164 + 19, … … 786 786 if AutoDiff = 1 then 787 787 FrameImage(Canvas, Brains.GetBeginner.Picture, xDefault, yDefault, 64, 788 64, 0, 0, false)788 64, 0, 0, False) 789 789 else 790 790 FrameImage(Canvas, BrainDefault.Picture, xDefault, yDefault, 64, 64, 791 0, 0, true);791 0, 0, True); 792 792 DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.ColorBevelLight, 793 793 MainTexture.ColorBevelShade); … … 795 795 RisedTextOut(Canvas, 56, y0Mini + 61, 796 796 Phrases.Lookup('STARTCONTROLS', 14)); 797 s:= Phrases.Lookup('AUTODIFF', AutoDiff - 1);798 RisedTextOut(Canvas, 272 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);799 800 for i:= 0 to 19 do801 if ( i < 2) or (i> 6) then begin802 BitBltCanvas(Canvas, 9 + i* 27, yLogo - 2, Ornament.Width, Ornament.Height,797 S := Phrases.Lookup('AUTODIFF', AutoDiff - 1); 798 RisedTextOut(Canvas, 272 - BiColorTextWidth(Canvas, S), y0Mini + 61, S); 799 800 for I := 0 to 19 do 801 if (I < 2) or (I > 6) then begin 802 BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height, 803 803 HGrSystem2.Mask.Canvas, Ornament.Left, Ornament.Top, SRCAND); 804 BitBltCanvas(Canvas, 9 + i* 27, yLogo - 2, Ornament.Width, Ornament.Height,804 BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height, 805 805 HGrSystem2.Data.Canvas, Ornament.Left, Ornament.Top, SRCPAINT); 806 806 end; … … 825 825 MainTexture.ColorBevelShade); 826 826 RisedTextOut(Canvas, 344, y0Mini + 61, Phrases.Lookup('STARTCONTROLS', 8)); 827 s:= TurnToString(LoadTurn);828 RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);827 S := TurnToString(LoadTurn); 828 RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, S), y0Mini + 61, S); 829 829 end 830 830 else if Page = pgEditRandom then … … 840 840 begin 841 841 // DLine(Canvas,344,514,y0Mini+61+19,MainTexture.ColorBevelLight,MainTexture.ColorBevelShade); 842 s:= Format(Phrases2.Lookup('MAPPROP'),842 S := Format(Phrases2.Lookup('MAPPROP'), 843 843 [(nMapLandTiles * 100 + 556) div 1112, 844 844 // 1112 is typical for world with 100% size and default land mass 845 845 nMapStartPositions]); 846 RisedTextOut(Canvas, x0Mini - BiColorTextWidth(Canvas, s) div 2,847 y0Mini + 61, s);846 RisedTextOut(Canvas, x0Mini - BiColorTextWidth(Canvas, S) div 2, 847 y0Mini + 61, S); 848 848 end; 849 849 … … 888 888 MainTexture.ColorBevelLight); 889 889 890 s:= '';890 S := ''; 891 891 if MiniMap.Mode = mmPicture then 892 892 begin … … 894 894 MiniMap.Bitmap.Canvas, 0, 0); 895 895 if Page = pgStartRandom then 896 s:= Phrases.Lookup('RANMAP')896 S := Phrases.Lookup('RANMAP') 897 897 end 898 898 else if MiniMap.Mode = mmMultiPlayer then 899 s:= Phrases.Lookup('MPMAP')899 S := Phrases.Lookup('MPMAP') 900 900 else if Page = pgStartMap then 901 s:= Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt))901 S := Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt)) 902 902 else if Page = pgEditMap then 903 s:= List.Items[List.ItemIndex]903 S := List.Items[List.ItemIndex] 904 904 else if Page = pgNoLoad then 905 s:= Phrases.Lookup('NOGAMES');906 if s<> '' then907 RisedTextOut(Canvas, x0Mini + 2 - BiColorTextWidth(Canvas, s) div 2,908 y0Mini - 8, s);905 S := Phrases.Lookup('NOGAMES'); 906 if S <> '' then 907 RisedTextOut(Canvas, x0Mini + 2 - BiColorTextWidth(Canvas, S) div 2, 908 y0Mini - 8, S); 909 909 end; 910 910 end; … … 959 959 begin // load 960 960 FileName := List.Items[List.ItemIndex]; 961 if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, false)961 if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, False) 962 962 then 963 963 UnlistBackupFile(FileName) … … 979 979 with Reg do 980 980 try 981 OpenKey(AppRegistryKey, true);981 OpenKey(AppRegistryKey, True); 982 982 if ValueExists('GameCount') then GameCount := ReadInteger('GameCount') 983 983 else GameCount := 0; … … 1168 1168 if Assigned(PlayersBrain[I]) and (PlayersBrain[I].Kind = btTerm) then begin 1169 1169 PlayersBrain[I] := nil; 1170 PlayerSlots[I].DiffUpBtn.Visible := false;1170 PlayerSlots[I].DiffUpBtn.Visible := False; 1171 1171 PlayerSlots[I].DiffUpBtn.Tag := 0; 1172 PlayerSlots[I].DiffDownBtn.Visible := false;1172 PlayerSlots[I].DiffDownBtn.Visible := False; 1173 1173 PlayerSlots[I].DiffDownBtn.Tag := 0; 1174 1174 if PlayerSlots[I].OfferMultiple then begin 1175 PlayerSlots[I].MultiBtn.Visible := false;1175 PlayerSlots[I].MultiBtn.Visible := False; 1176 1176 PlayerSlots[I].MultiBtn.Tag := 0; 1177 1177 end; … … 1199 1199 J := FixedLines; 1200 1200 while (J < PopupMenu1.Items.Count) and 1201 (StrIComp( pchar(MenuItem.Caption), pchar(PopupMenu1.Items[J].Caption)) > 0) do1201 (StrIComp(PChar(MenuItem.Caption), PChar(PopupMenu1.Items[J].Caption)) > 0) do 1202 1202 Inc(J); 1203 1203 MenuItem.RadioItem := True; … … 1210 1210 var 1211 1211 I: Integer; 1212 FixedLines: integer;1212 FixedLines: Integer; 1213 1213 MenuItem: TMenuItem; 1214 1214 AIBrains: TBrains; … … 1244 1244 end; 1245 1245 for I := Brains.IndexOf(BrainTerm) downto 0 do // offer game interfaces 1246 if (PlayerPopupIndex = 0) or (Brains[ i].Kind = btTerm) and1246 if (PlayerPopupIndex = 0) or (Brains[I].Kind = btTerm) and 1247 1247 (PlayersBrain[0].Kind <> btNoTerm) then begin 1248 1248 OfferBrain(Brains[I], FixedLines); … … 1268 1268 if (AIBrains[I].Flags and fMultiple <> 0) or (AIBrains[I].Flags and fUsed = 0) 1269 1269 or (Brains[I] = PlayersBrain[PlayerPopupIndex]) then 1270 OfferBrain(AIBrains[ i], FixedLines);1270 OfferBrain(AIBrains[I], FixedLines); 1271 1271 FreeAndNil(AIBrains); 1272 1272 end; … … 1283 1283 repeat 1284 1284 I := FormerGames.Count; 1285 while (I > 0) and (F.Time < integer(FormerGames.Objects[I - 1])) do1285 while (I > 0) and (F.Time < Integer(FormerGames.Objects[I - 1])) do 1286 1286 Dec(I); 1287 1287 FormerGames.InsertObject(I, Copy(F.Name, 1, Length(F.Name) - 5), … … 1297 1297 procedure TStartDlg.UpdateMaps; 1298 1298 var 1299 f: TSearchRec;1299 F: TSearchRec; 1300 1300 begin 1301 1301 Maps.Clear; 1302 if FindFirst(GetMapsDir + DirectorySeparator + '*' + CevoMapExt, $21, f) = 0 then1302 if FindFirst(GetMapsDir + DirectorySeparator + '*' + CevoMapExt, $21, F) = 0 then 1303 1303 repeat 1304 Maps.Add(Copy( f.Name, 1, Length(f.Name) - Length(CevoMapExt)));1305 until FindNext( f) <> 0;1304 Maps.Add(Copy(F.Name, 1, Length(F.Name) - Length(CevoMapExt))); 1305 until FindNext(F) <> 0; 1306 1306 FindClose(F); 1307 1307 Maps.Sort; … … 1314 1314 procedure TStartDlg.ChangePage(NewPage: TStartPage); 1315 1315 var 1316 i, j, p1: integer;1317 s: string;1316 I, J, p1: Integer; 1317 S: string; 1318 1318 Reg: TRegistry; 1319 InvalidateTab0: boolean;1319 InvalidateTab0: Boolean; 1320 1320 begin 1321 1321 InvalidateTab0 := (Page = pgMain) or (NewPage = pgMain); … … 1326 1326 StartBtn.Caption := Phrases.Lookup('STARTCONTROLS', 1); 1327 1327 if Page = pgStartRandom then 1328 i:= nPlOffered1328 I := nPlOffered 1329 1329 else 1330 1330 begin 1331 i:= nMapStartPositions;1332 if i= 0 then1331 I := nMapStartPositions; 1332 if I = 0 then 1333 1333 begin 1334 1334 PlayersBrain[0] := BrainSuperVirtual; … … 1336 1336 end; 1337 1337 if PlayersBrain[0].Kind in [btNoTerm, btSuperVirtual] then 1338 inc(i);1339 if i> nPl then1340 i:= nPl;1341 if i<= nPlOffered then1338 Inc(I); 1339 if I > nPl then 1340 I := nPl; 1341 if I <= nPlOffered then 1342 1342 MultiControl := 0 1343 1343 else 1344 MultiControl := InitMulti[ i];1344 MultiControl := InitMulti[I]; 1345 1345 end; 1346 if InitAlive[ i] <> SlotAvailable then1346 if InitAlive[I] <> SlotAvailable then 1347 1347 if Page = pgStartRandom then 1348 1348 begin // restore AI assignment of last start … … 1353 1353 for p1 := 0 to nPlOffered - 1 do begin 1354 1354 PlayersBrain[p1] := nil; 1355 s:= ReadString('Control' + IntToStr(p1));1355 S := ReadString('Control' + IntToStr(p1)); 1356 1356 Difficulty[p1] := ReadInteger('Diff' + IntToStr(p1)); 1357 if s<> '' then1358 for j:= 0 to Brains.Count - 1 do1359 if AnsiCompareFileName( s, Brains[j].FileName) = 0 then1360 PlayersBrain[p1] := Brains[ j];1357 if S <> '' then 1358 for J := 0 to Brains.Count - 1 do 1359 if AnsiCompareFileName(S, Brains[J].FileName) = 0 then 1360 PlayersBrain[p1] := Brains[J]; 1361 1361 end; 1362 1362 finally … … 1366 1366 else 1367 1367 for p1 := 1 to nPl - 1 do 1368 if 1 shl p1 and InitAlive[ i] <> 0 then1368 if 1 shl p1 and InitAlive[I] <> 0 then 1369 1369 begin 1370 1370 PlayersBrain[p1] := BrainDefault; … … 1373 1373 else 1374 1374 PlayersBrain[p1] := nil; 1375 SlotAvailable := InitAlive[ i];1376 for i:= 0 to nPlOffered - 1 do1377 if (AutoDiff < 0) and Assigned(PlayersBrain[ i]) and1378 (PlayersBrain[ i].Kind in [btTerm, btRandom, btAI]) then1375 SlotAvailable := InitAlive[I]; 1376 for I := 0 to nPlOffered - 1 do 1377 if (AutoDiff < 0) and Assigned(PlayersBrain[I]) and 1378 (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then 1379 1379 begin 1380 PlayerSlots[ i].DiffUpBtn.Tag := 768;1381 PlayerSlots[ i].DiffDownBtn.Tag := 768;1380 PlayerSlots[I].DiffUpBtn.Tag := 768; 1381 PlayerSlots[I].DiffDownBtn.Tag := 768; 1382 1382 end 1383 1383 else 1384 1384 begin 1385 PlayerSlots[ i].DiffUpBtn.Tag := 0;1386 PlayerSlots[ i].DiffDownBtn.Tag := 0;1385 PlayerSlots[I].DiffUpBtn.Tag := 0; 1386 PlayerSlots[I].DiffDownBtn.Tag := 0; 1387 1387 end; 1388 for i:= 6 to 8 do1389 if (AutoDiff < 0) and Assigned(PlayersBrain[ i]) and1390 (PlayersBrain[ i].Kind in [btTerm, btRandom, btAI]) then1388 for I := 6 to 8 do 1389 if (AutoDiff < 0) and Assigned(PlayersBrain[I]) and 1390 (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then 1391 1391 begin 1392 PlayerSlots[ i].MultiBtn.Tag := 768;1393 PlayerSlots[ i].MultiBtn.ButtonIndex := 2 + (MultiControl shr i) and 1;1394 PlayerSlots[ i].MultiBtn.Enabled := Page = pgStartRandom1392 PlayerSlots[I].MultiBtn.Tag := 768; 1393 PlayerSlots[I].MultiBtn.ButtonIndex := 2 + (MultiControl shr I) and 1; 1394 PlayerSlots[I].MultiBtn.Enabled := Page = pgStartRandom 1395 1395 end 1396 1396 else 1397 PlayerSlots[ i].MultiBtn.Tag := 0;1397 PlayerSlots[I].MultiBtn.Tag := 0; 1398 1398 if (AutoDiff > 0) and (Page <> pgStartMap) then 1399 1399 begin … … 1434 1434 1435 1435 PaintInfo; 1436 for i:= 0 to ControlCount - 1 do1437 Controls[ i].Visible := Controls[i].Tag and (256 shl Integer(Page)) <> 0;1436 for I := 0 to ControlCount - 1 do 1437 Controls[I].Visible := Controls[I].Tag and (256 shl Integer(Page)) <> 0; 1438 1438 if Page = pgLoad then 1439 1439 ReplayBtn.Visible := MiniMap.Mode <> mmMultiPlayer; … … 1479 1479 1480 1480 procedure TStartDlg.FormMouseDown(Sender: TObject; Button: TMouseButton; 1481 Shift: TShiftState; x, y: integer);1481 Shift: TShiftState; X, Y: Integer); 1482 1482 var 1483 1483 I: Integer; 1484 1484 begin 1485 if ( y < TabHeight + 1) and (x- TabOffset < TabSize * 4) and1486 (( x- TabOffset) div TabSize <> Integer(Tab)) then1485 if (Y < TabHeight + 1) and (X - TabOffset < TabSize * 4) and 1486 ((X - TabOffset) div TabSize <> Integer(Tab)) then 1487 1487 begin 1488 1488 // Play('BUTTON_DOWN'); 1489 1489 ListIndex[Tab] := List.ItemIndex; 1490 ChangeTab(TStartTab(( x- TabOffset) div TabSize));1490 ChangeTab(TStartTab((X - TabOffset) div TabSize)); 1491 1491 end 1492 1492 else if Page = pgMain then begin … … 1503 1503 begin 1504 1504 for I := 0 to nPlOffered - 1 do 1505 if (1 shl I and SlotAvailable <> 0) and ( x>= xBrain[I]) and1506 ( y >= yBrain[I]) and (x < xBrain[I] + 64) and (y< yBrain[I] + 64) then1505 if (1 shl I and SlotAvailable <> 0) and (X >= xBrain[I]) and 1506 (Y >= yBrain[I]) and (X < xBrain[I] + 64) and (Y < yBrain[I] + 64) then 1507 1507 begin 1508 1508 InitPopup(I); … … 1514 1514 end 1515 1515 else if (AutoDiff > 1) and ((Page = pgStartRandom) or (Page = pgStartMap)) and 1516 ( x >= xDefault) and (y >= yDefault) and (x< xDefault + 64) and1517 ( y< yDefault + 64) then1516 (X >= xDefault) and (Y >= yDefault) and (X < xDefault + 64) and 1517 (Y < yDefault + 64) then 1518 1518 if Brains.GetKindCount(btAI) < 2 then 1519 1519 SimpleMessage(Phrases.Lookup('NOALTAI')) … … 1523 1523 PopupMenu1.Popup(left + xDefault + 4, top + yDefault + 4); 1524 1524 end 1525 else if (Page = pgLoad) and (LastTurn > 0) and ( y>= yTurnSlider) and1526 ( y < yTurnSlider + 7) and (x>= xTurnSlider) and1527 ( x<= xTurnSlider + wTurnSlider) then1528 begin 1529 LoadTurn := LastTurn * ( x- xTurnSlider) div wTurnSlider;1525 else if (Page = pgLoad) and (LastTurn > 0) and (Y >= yTurnSlider) and 1526 (Y < yTurnSlider + 7) and (X >= xTurnSlider) and 1527 (X <= xTurnSlider + wTurnSlider) then 1528 begin 1529 LoadTurn := LastTurn * (X - xTurnSlider) div wTurnSlider; 1530 1530 SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider + 2, 1531 1531 yTurnSlider + 9); … … 1540 1540 if MaxTurn < 1400 then 1541 1541 begin 1542 inc(MaxTurn, 200);1542 Inc(MaxTurn, 200); 1543 1543 SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82); 1544 1544 end; … … 1546 1546 if LoadTurn < LastTurn then 1547 1547 begin 1548 inc(LoadTurn);1548 Inc(LoadTurn); 1549 1549 SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider 1550 1550 + 2, yTurnSlider + 9); … … 1553 1553 if StartLandMass < 96 then 1554 1554 begin 1555 inc(StartLandMass, 5);1555 Inc(StartLandMass, 5); 1556 1556 PaintInfo; 1557 1557 SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21); … … 1566 1566 if MaxTurn > 400 then 1567 1567 begin 1568 dec(MaxTurn, 200);1568 Dec(MaxTurn, 200); 1569 1569 SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82); 1570 1570 end; … … 1572 1572 if LoadTurn > 0 then 1573 1573 begin 1574 dec(LoadTurn);1574 Dec(LoadTurn); 1575 1575 SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider 1576 1576 + 2, yTurnSlider + 9); … … 1579 1579 if StartLandMass > 10 then 1580 1580 begin 1581 dec(StartLandMass, 5);1581 Dec(StartLandMass, 5); 1582 1582 PaintInfo; 1583 1583 SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21); … … 1634 1634 procedure TStartDlg.RenameBtnClick(Sender: TObject); 1635 1635 var 1636 i: integer;1636 I: Integer; 1637 1637 NewName: string; 1638 f: file;1639 ok: boolean;1638 F: file; 1639 ok: Boolean; 1640 1640 MapPictureFileName: string; 1641 1641 begin … … 1655 1655 (NewName <> List.Items[List.ItemIndex]) then 1656 1656 begin 1657 for i:= 1 to Length(NewName) do1658 if NewName[ i] in ['\', '/', ':', '*', '?', '"', '<', '>', '|'] then1657 for I := 1 to Length(NewName) do 1658 if NewName[I] in ['\', '/', ':', '*', '?', '"', '<', '>', '|'] then 1659 1659 begin 1660 SimpleMessage(Format(Phrases.Lookup('NOFILENAME'), [NewName[ i]]));1660 SimpleMessage(Format(Phrases.Lookup('NOFILENAME'), [NewName[I]])); 1661 1661 Exit; 1662 1662 end; 1663 1663 if Page = pgLoad then 1664 AssignFile( f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)1664 AssignFile(F, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt) 1665 1665 else 1666 AssignFile( f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +1666 AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] + 1667 1667 CevoMapExt); 1668 ok := true;1668 ok := True; 1669 1669 try 1670 1670 if Page = pgLoad then 1671 Rename( f, GetSavedDir + DirectorySeparator + NewName + CevoExt)1671 Rename(F, GetSavedDir + DirectorySeparator + NewName + CevoExt) 1672 1672 else 1673 Rename( f, GetMapsDir + DirectorySeparator + NewName + CevoMapExt);1673 Rename(F, GetMapsDir + DirectorySeparator + NewName + CevoMapExt); 1674 1674 except 1675 1675 // Play('INVALID'); … … 1682 1682 if FileExists(MapPictureFileName) then 1683 1683 try 1684 AssignFile( f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex]1684 AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] 1685 1685 + CevoMapPictureExt); 1686 Rename( f, GetMapsDir + DirectorySeparator + NewName + CevoMapPictureExt);1686 Rename(F, GetMapsDir + DirectorySeparator + NewName + CevoMapPictureExt); 1687 1687 except 1688 1688 end; … … 1704 1704 procedure TStartDlg.DeleteBtnClick(Sender: TObject); 1705 1705 var 1706 iDel: integer;1707 f: file;1706 iDel: Integer; 1707 F: file; 1708 1708 begin 1709 1709 if List.ItemIndex >= 0 then … … 1718 1718 begin 1719 1719 if Page = pgLoad then 1720 AssignFile( f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)1720 AssignFile(F, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt) 1721 1721 else 1722 AssignFile( f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +1722 AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] + 1723 1723 CevoMapExt); 1724 Erase( f);1724 Erase(F); 1725 1725 iDel := List.ItemIndex; 1726 1726 if Page = pgLoad then … … 1743 1743 List.Invalidate; 1744 1744 if Page = pgLoad then 1745 TurnValid := false;1745 TurnValid := False; 1746 1746 PaintInfo; 1747 1747 if Page = pgLoad then … … 1842 1842 1843 1843 procedure TStartDlg.FormMouseUp(Sender: TObject; Button: TMouseButton; 1844 Shift: TShiftState; x, y: integer);1844 Shift: TShiftState; X, Y: Integer); 1845 1845 begin 1846 1846 Tracking := False; … … 1848 1848 1849 1849 procedure TStartDlg.FormMouseMove(Sender: TObject; Shift: TShiftState; 1850 x, y: integer);1850 X, Y: Integer); 1851 1851 var 1852 1852 OldLoadTurn: Integer; … … 1855 1855 if Tracking then 1856 1856 begin 1857 x := x- xTurnSlider;1858 if x< 0 then1859 x:= 01860 else if x> wTurnSlider then1861 x:= wTurnSlider;1857 X := X - xTurnSlider; 1858 if X < 0 then 1859 X := 0 1860 else if X > wTurnSlider then 1861 X := wTurnSlider; 1862 1862 OldLoadTurn := LoadTurn; 1863 LoadTurn := LastTurn * xdiv wTurnSlider;1863 LoadTurn := LastTurn * X div wTurnSlider; 1864 1864 if LoadTurn < OldLoadTurn then 1865 1865 begin … … 1879 1879 else if Page = pgMain then 1880 1880 begin 1881 if ( x >= ActionSideBorder) and (x< ClientWidth - ActionSideBorder) and1882 ( y >= yAction - 8) and (y< ClientHeight - ActionBottomBorder) then1881 if (X >= ActionSideBorder) and (X < ClientWidth - ActionSideBorder) and 1882 (Y >= yAction - 8) and (Y < ClientHeight - ActionBottomBorder) then 1883 1883 begin 1884 NewSelectedAction := TMainAction(( y- (yAction - 8)) div ActionPitch);1884 NewSelectedAction := TMainAction((Y - (yAction - 8)) div ActionPitch); 1885 1885 if not (NewSelectedAction in ActionsOffered) then 1886 1886 NewSelectedAction := maNone; -
trunk/UBrain.pas
r442 r447 206 206 end. 207 207 208 -
trunk/UMiniMap.pas
r442 r447 330 330 end. 331 331 332 -
trunk/UnitProcessing.pas
r442 r447 13 13 TMoveInfo = record 14 14 MoveType: TMoveType; 15 Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: integer;16 MountainDelay: boolean;15 Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: Integer; 16 MountainDelay: Boolean; 17 17 end; 18 18 19 19 var 20 uixSelectedTransport: integer;21 Worked: array [0 .. nPl - 1] of integer; { settler work statistics }20 uixSelectedTransport: Integer; 21 Worked: array [0 .. nPl - 1] of Integer; { settler work statistics } 22 22 23 23 // Moving/Combat 24 function HostileDamage( p, mix, Loc, MP: integer): integer;25 function CalculateMove( p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;26 var MoveInfo: TMoveInfo): integer;27 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;28 var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;29 function LoadUnit( p, uix: integer; TestOnly: boolean): integer;30 function UnloadUnit( p, uix: integer; TestOnly: boolean): integer;31 procedure Recover( p, uix: integer);32 function GetMoveAdvice( p, uix: integer; var a: TMoveAdviceData): integer;33 function CanPlaneReturn( p, uix: integer;34 PlaneReturnData: TPlaneReturnData): boolean;24 function HostileDamage(P, mix, Loc, MP: Integer): Integer; 25 function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean; 26 var MoveInfo: TMoveInfo): Integer; 27 function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast; 28 var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer; 29 function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer; 30 function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer; 31 procedure Recover(P, uix: Integer); 32 function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer; 33 function CanPlaneReturn(P, uix: Integer; 34 PlaneReturnData: TPlaneReturnData): Boolean; 35 35 36 36 // Terrain Improvement 37 function StartJob( p, uix, NewJob: integer; TestOnly: boolean): integer;38 function Work( p, uix: integer): boolean;39 function GetJobProgress( p, Loc: integer;40 var JobProgressData: TJobProgressData): integer;37 function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer; 38 function Work(P, uix: Integer): Boolean; 39 function GetJobProgress(P, Loc: Integer; 40 var JobProgressData: TJobProgressData): Integer; 41 41 42 42 // Start/End Game … … 74 74 75 75 type 76 TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of word;76 TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of Word; 77 77 78 78 var … … 83 83 ____________________________________________________________________ 84 84 } 85 function HostileDamage( p, mix, Loc, MP: integer): integer;86 var 87 Tile: integer;85 function HostileDamage(P, mix, Loc, MP: Integer): Integer; 86 var 87 Tile: Integer; 88 88 begin 89 89 Tile := RealMap[Loc]; 90 if (RW[ p].Model[mix].Domain >= dSea) or (RW[p].Model[mix].Kind = mkSettler)91 and (RW[ p].Model[mix].Speed >= 200) or90 if (RW[P].Model[mix].Domain >= dSea) or (RW[P].Model[mix].Kind = mkSettler) 91 and (RW[P].Model[mix].Speed >= 200) or 92 92 (Tile and (fCity or fRiver or fCanal) <> 0) or (Tile and fTerImp = tiBase) 93 or (GWonder[woGardens].EffectiveOwner = p) then94 result := 093 or (GWonder[woGardens].EffectiveOwner = P) then 94 Result := 0 95 95 else if (Tile and fTerrain = fDesert) and 96 96 (Tile and fSpecial <> fSpecial1 { Oasis } ) then 97 97 begin 98 assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));99 result := (DesertThurst * MP - 1) div RW[p].Model[mix].Speed + 198 Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm)); 99 Result := (DesertThurst * MP - 1) div RW[P].Model[mix].Speed + 1 100 100 end 101 101 else if Tile and fTerrain = fArctic then 102 102 begin 103 assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));104 result := (ArcticThurst * MP - 1) div RW[p].Model[mix].Speed + 1103 Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm)); 104 Result := (ArcticThurst * MP - 1) div RW[P].Model[mix].Speed + 1 105 105 end 106 106 else 107 result := 0108 end; 109 110 function Controlled( p, Loc: integer; IsDest: boolean): integer;107 Result := 0; 108 end; 109 110 function Controlled(P, Loc: Integer; IsDest: Boolean): Integer; 111 111 { whether tile at Loc is in control zone of enemy unit 112 112 returns combination of tile control flags } 113 113 var 114 Loc1, V8: integer;114 Loc1, V8: Integer; 115 115 Adjacent: TVicinity8Loc; 116 116 begin 117 result := 0;118 if IsDest and (Occupant[Loc] = p) and (ZoCMap[Loc] > 0) then119 exit;117 Result := 0; 118 if IsDest and (Occupant[Loc] = P) and (ZoCMap[Loc] > 0) then 119 Exit; 120 120 // destination tile, not controlled if already occupied 121 121 122 if (RealMap[Loc] and fCity = 0) or ( integer(RealMap[Loc] shr 27) <> p) and123 (ServerVersion[ p] >= $000EF0) then122 if (RealMap[Loc] and fCity = 0) or (Integer(RealMap[Loc] shr 27) <> P) and 123 (ServerVersion[P] >= $000EF0) then 124 124 begin // not own city 125 125 V8_to_Loc(Loc, Adjacent); … … 128 128 Loc1 := Adjacent[V8]; 129 129 if (Loc1 >= 0) and (Loc1 < MapSize) and (ZoCMap[Loc1] > 0) and 130 (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> p) and131 (RW[ p].Treaty[Occupant[Loc1]] < trAlliance) then132 if ObserveLevel[Loc1] and (3 shl ( p* 2)) > 0 then130 (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> P) and 131 (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then 132 if ObserveLevel[Loc1] and (3 shl (P * 2)) > 0 then 133 133 begin // p observes tile 134 result := coKnown or coTrue;135 exit;134 Result := coKnown or coTrue; 135 Exit; 136 136 end 137 137 else 138 result := coTrue; // p does not observe tile138 Result := coTrue; // p does not observe tile 139 139 end; 140 140 end; 141 141 end; 142 142 143 function GetMoveCost( p, mix, FromLoc, ToLoc, MoveLength: integer;144 var MoveCost: integer): integer;143 function GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength: Integer; 144 var MoveCost: Integer): Integer; 145 145 // MoveLength - 2 for short move, 3 for long move 146 146 var 147 FromTile, ToTile: integer;148 begin 149 result := eOK;147 FromTile, ToTile: Integer; 148 begin 149 Result := eOK; 150 150 FromTile := RealMap[FromLoc]; 151 151 ToTile := RealMap[ToLoc]; 152 with RW[ p].Model[mix] do152 with RW[P].Model[mix] do 153 153 begin 154 154 case Domain of … … 160 160 if (FromTile and (fRR or fCity) <> 0) and 161 161 (ToTile and (fRR or fCity) <> 0) then 162 if GWonder[woShinkansen].EffectiveOwner = pthen162 if GWonder[woShinkansen].EffectiveOwner = P then 163 163 MoveCost := 0 164 164 else … … 174 174 MoveCost := 20 175 175 else if Cap[mcOver] > 0 then 176 result := eNoRoad176 Result := eNoRoad 177 177 else 178 178 case Terrain[ToTile and fTerrain].MoveCost of … … 181 181 2: 182 182 begin 183 assert(Speed - 150 <= 600);183 Assert(Speed - 150 <= 600); 184 184 MoveCost := 50 + (Speed - 150) * 13 shr 7; // heavy terrain 185 185 end; … … 187 187 begin 188 188 MoveCost := Speed; 189 result := eMountains;190 exit;189 Result := eMountains; 190 Exit; 191 191 end; 192 192 end; … … 194 194 end 195 195 else 196 result := eDomainMismatch;196 Result := eDomainMismatch; 197 197 198 198 dSea: … … 202 202 MoveCost := 50 * MoveLength { valid move } 203 203 else 204 result := eNoNav { navigation required for open sea }205 else 206 result := eDomainMismatch;204 Result := eNoNav { navigation required for open sea } 205 else 206 Result := eDomainMismatch; 207 207 208 208 dAir: … … 212 212 end; 213 213 214 function CalculateMove( p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;215 var MoveInfo: TMoveInfo): integer;214 function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean; 215 var MoveInfo: TMoveInfo): Integer; 216 216 var 217 217 uix1, p1, FromLoc, DestControlled, AStr, DStr, ABaseDamage, 218 DBaseDamage: integer;218 DBaseDamage: Integer; 219 219 PModel: ^TModel; 220 220 BattleForecast: TBattleForecast; 221 221 begin 222 with RW[ p], Un[uix] do222 with RW[P], Un[uix] do 223 223 begin 224 224 PModel := @Model[mix]; 225 225 FromLoc := Loc; 226 226 227 BattleForecast.pAtt := p;227 BattleForecast.pAtt := P; 228 228 BattleForecast.mixAtt := mix; 229 229 BattleForecast.HealthAtt := Health; … … 231 231 BattleForecast.FlagsAtt := Flags; 232 232 BattleForecast.Movement := Movement; 233 result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix,233 Result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix, 234 234 MoveInfo.Dcix, AStr, DStr, ABaseDamage, DBaseDamage); 235 235 236 if result = eHiddenUnit then236 if Result = eHiddenUnit then 237 237 if TestOnly then 238 result := eOK // behave just like unit was moving238 Result := eOK // behave just like unit was moving 239 239 else if Mode > moLoading_Fast then 240 240 Map[ToLoc] := Map[ToLoc] or fHiddenUnit; 241 if result = eStealthUnit then241 if Result = eStealthUnit then 242 242 if TestOnly then 243 result := eOK // behave just like unit was moving243 Result := eOK // behave just like unit was moving 244 244 else if Mode > moLoading_Fast then 245 245 Map[ToLoc] := Map[ToLoc] or fStealthUnit; 246 if result < rExecuted then247 exit;248 249 case result of246 if Result < rExecuted then 247 Exit; 248 249 case Result of 250 250 eOK: 251 251 MoveInfo.MoveType := mtMove; … … 261 261 begin 262 262 p1 := RealMap[ToLoc] shr 27; 263 if (p1 < nPl) and (p1 <> p) and263 if (p1 < nPl) and (p1 <> P) and 264 264 ((RealMap[Loc] shr 27 <> Cardinal(p1)) and (PModel.Kind <> mkDiplomat) 265 265 and (Treaty[p1] >= trPeace) and (Treaty[p1] < trAlliance) or 266 266 (RealMap[ToLoc] and fCity <> 0) and (Treaty[p1] >= trPeace)) then 267 267 begin 268 result := eTreaty;269 exit;268 Result := eTreaty; 269 Exit; 270 270 end; // keep peace treaty! 271 271 end; 272 272 if (RealMap[ToLoc] and fCity <> 0) and 273 (RealMap[ToLoc] shr 27 <> Cardinal( p)) then // empty enemy city273 (RealMap[ToLoc] shr 27 <> Cardinal(P)) then // empty enemy city 274 274 if PModel.Kind = mkDiplomat then 275 275 begin … … 280 280 if PModel.Flags and mdCivil <> 0 then 281 281 begin 282 result := eNoCapturer;283 exit;282 Result := eNoCapturer; 283 Exit; 284 284 end; 285 285 MoveInfo.MoveType := mtCapture; … … 289 289 if (PModel.Domain = dSea) and (PModel.Cap[mcArtillery] = 0) then 290 290 begin 291 result := eDomainMismatch;292 exit;291 Result := eDomainMismatch; 292 Exit; 293 293 end 294 294 else if (PModel.Attack = 0) and … … 296 296 then 297 297 begin 298 result := eNoBombarder;299 exit;298 Result := eNoBombarder; 299 Exit; 300 300 end 301 301 else if Movement < 100 then 302 302 begin 303 result := eNoTime_Bombard;304 exit;303 Result := eNoTime_Bombard; 304 Exit; 305 305 end; 306 306 MoveInfo.MoveType := mtBombard; 307 result := eBombarded;308 end; 309 end; 310 311 MoveInfo.MountainDelay := false;307 Result := eBombarded; 308 end; 309 end; 310 311 MoveInfo.MountainDelay := False; 312 312 if MoveInfo.MoveType in [mtAttack, mtBombard, mtExpel] then 313 313 begin … … 317 317 then 318 318 begin 319 result := eViolation;320 exit319 Result := eViolation; 320 Exit; 321 321 end; 322 322 if MoveInfo.MoveType = mtBombard then … … 337 337 MoveInfo.Cost := PModel.Speed; 338 338 if RealMap[ToLoc] and fTerrain < fGrass then 339 result := eDomainMismatch;339 Result := eDomainMismatch; 340 340 end 341 341 else 342 342 begin 343 result := GetMoveCost(p, mix, FromLoc, ToLoc, MoveLength,343 Result := GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength, 344 344 MoveInfo.Cost); 345 if result = eMountains then346 begin 347 result := eOK;348 MoveInfo.MountainDelay := true345 if Result = eMountains then 346 begin 347 Result := eOK; 348 MoveInfo.MountainDelay := True 349 349 end; 350 350 end; 351 if ( result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then352 result := eMissionDone;351 if (Result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then 352 Result := eMissionDone; 353 353 354 354 MoveInfo.ToMaster := -1; 355 if ( result = eDomainMismatch) and (PModel.Domain < dSea) and355 if (Result = eDomainMismatch) and (PModel.Domain < dSea) and 356 356 (PModel.Cap[mcOver] = 0) then 357 357 begin … … 361 361 (TroopLoad < Model[mix].MTrans * Model[mix].Cap[mcSeaTrans]) then 362 362 begin 363 result := eLoaded;363 Result := eLoaded; 364 364 MoveInfo.Cost := PModel.Speed; 365 365 MoveInfo.ToMaster := uix1; … … 378 378 (AirLoad < Model[mix].MTrans * Model[mix].Cap[mcCarrier]) then 379 379 begin // load plane to ship 380 result := eLoaded;380 Result := eLoaded; 381 381 MoveInfo.ToMaster := uix1; 382 382 if (uixSelectedTransport >= 0) and (uix1 = uixSelectedTransport) … … 385 385 end; 386 386 end; 387 if result < rExecuted then388 exit;387 if Result < rExecuted then 388 Exit; 389 389 390 390 if (Master < 0) and (MoveInfo.ToMaster < 0) then 391 MoveInfo.EndHealth := Health - HostileDamage( p, mix, ToLoc,391 MoveInfo.EndHealth := Health - HostileDamage(P, mix, ToLoc, 392 392 MoveInfo.Cost) 393 393 else … … 395 395 396 396 if (Mode = moPlaying) and (PModel.Flags and mdZOC <> 0) and (Master < 0) 397 and (MoveInfo.ToMaster < 0) and (Controlled( p, FromLoc, false) >= coTrue)397 and (MoveInfo.ToMaster < 0) and (Controlled(P, FromLoc, False) >= coTrue) 398 398 then 399 399 begin 400 DestControlled := Controlled( p, ToLoc, true);400 DestControlled := Controlled(P, ToLoc, True); 401 401 if DestControlled >= coTrue + coKnown then 402 402 begin 403 result := eZOC;404 exit;403 Result := eZOC; 404 Exit; 405 405 end 406 406 else if not TestOnly and (DestControlled >= coTrue) then 407 407 begin 408 result := eZOC_EnemySpotted;409 exit;408 Result := eZOC_EnemySpotted; 409 Exit; 410 410 end; 411 411 end; 412 if (Movement = 0) and (ServerVersion[ p] >= $0100F1) or412 if (Movement = 0) and (ServerVersion[P] >= $0100F1) or 413 413 (MoveInfo.Cost > Movement) then 414 414 if (Master >= 0) or (MoveInfo.ToMaster >= 0) then 415 415 begin 416 result := eNoTime_Load;417 exit;416 Result := eNoTime_Load; 417 Exit; 418 418 end 419 419 else 420 420 begin 421 result := eNoTime_Move;422 exit;421 Result := eNoTime_Move; 422 Exit; 423 423 end; 424 424 if (MoveInfo.EndHealth <= 0) or (MoveInfo.MoveType = mtSpyMission) then 425 result := result or rUnitRemoved;425 Result := Result or rUnitRemoved; 426 426 // spy mission or victim of HostileDamage 427 427 … … 438 438 end; 439 439 440 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;441 var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;442 var 443 Time, Defender, ABon, DBon, DCnt, MultiDamage: integer;440 function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast; 441 var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer; 442 var 443 Time, Defender, ABon, DBon, DCnt, MultiDamage: Integer; 444 444 PModel, DModel: ^TModel; 445 445 begin … … 449 449 if (Defender < 0) or (Defender = pAtt) then 450 450 begin 451 result := eOK;452 exit;451 Result := eOK; 452 Exit; 453 453 end; // no attack, simple move 454 454 … … 459 459 EndHealthAtt := HealthAtt; 460 460 EndHealthDef := RW[Defender].Un[Duix].Health; 461 result := eOK;462 exit;461 Result := eOK; 462 Exit; 463 463 end; 464 464 … … 470 470 (ObserveLevel[Loc] shr (2 * pAtt) and 3 < lObserveAll) then 471 471 begin 472 result := eHiddenUnit;473 exit;472 Result := eHiddenUnit; 473 Exit; 474 474 end; // attacking submarine not allowed 475 475 if (DModel.Cap[mcStealth] > 0) and 476 476 (ObserveLevel[Loc] shr (2 * pAtt) and 3 <> lObserveSuper) then 477 477 begin 478 result := eStealthUnit;479 exit;478 Result := eStealthUnit; 479 Exit; 480 480 end; // attacking stealth aircraft not allowed 481 481 if (DModel.Domain = dAir) and (DModel.Kind <> mkSpecial_Glider) and 482 482 (PModel.Domain <> dAir) then 483 483 begin 484 result := eDomainMismatch;485 exit;484 Result := eDomainMismatch; 485 Exit; 486 486 end; // can't attack plane 487 487 end; … … 492 492 (PModel.Domain = dSea) and (RealMap[Loc] and fTerrain >= fGrass)) then 493 493 begin 494 result := eDomainMismatch;495 exit;494 Result := eDomainMismatch; 495 Exit; 496 496 end; 497 497 if (PModel.Attack = 0) and not((PModel.Cap[mcBombs] > 0) and 498 498 (FlagsAtt and unBombsLoaded <> 0) and (DModel.Domain < dAir)) then 499 499 begin 500 result := eInvalid;501 exit;500 Result := eInvalid; 501 Exit; 502 502 end; 503 503 504 504 if Movement = 0 then 505 505 begin 506 result := eNoTime_Attack;507 exit;508 end; 509 510 {$IFOPT O-} assert(InvalidTreatyMap = 0); {$ENDIF}506 Result := eNoTime_Attack; 507 Exit; 508 end; 509 510 {$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF} 511 511 if RW[pAtt].Treaty[Defender] >= trPeace then 512 512 begin 513 513 if (PModel.Domain <> dAir) and (PModel.Attack > 0) and 514 ( integer(RealMap[Loc] shr 27) = pAtt) then514 (Integer(RealMap[Loc] shr 27) = pAtt) then 515 515 if Movement >= 100 then 516 516 begin // expel friendly unit 517 517 EndHealthDef := RW[Defender].Un[Duix].Health; 518 518 EndHealthAtt := HealthAtt; 519 result := eExpelled519 Result := eExpelled 520 520 end 521 521 else 522 result := eNoTime_Expel522 Result := eNoTime_Expel 523 523 else 524 result := eTreaty;525 exit;524 Result := eTreaty; 525 Exit; 526 526 end; 527 527 … … 534 534 (Continent[RW[Defender].City[Dcix].Loc] = GrWallContinent[Defender])) 535 535 then 536 inc(DBon, 8)536 Inc(DBon, 8) 537 537 else if (PModel.Domain = dSea) and 538 538 (RW[Defender].City[Dcix].Built[imCoastalFort] = 1) then 539 inc(DBon, 4)539 Inc(DBon, 4) 540 540 else if (PModel.Domain = dAir) and 541 541 (RW[Defender].City[Dcix].Built[imMissileBat] = 1) then 542 inc(DBon, 4);542 Inc(DBon, 4); 543 543 if RW[Defender].City[Dcix].Built[imBunker] = 1 then 544 inc(DBon, 4)544 Inc(DBon, 4) 545 545 end; 546 546 if (PModel.Domain = dAir) and (DModel.Cap[mcAirDef] > 0) then 547 inc(DBon, 4);547 Inc(DBon, 4); 548 548 DStr := DModel.Defense * DBon * 100; 549 549 if (DModel.Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or … … 622 622 623 623 if EndHealthDef > 0 then 624 result := eLost624 Result := eLost 625 625 else if EndHealthAtt > 0 then 626 result := eWon626 Result := eWon 627 627 else 628 result := eBloody;628 Result := eBloody; 629 629 end; 630 630 end; 631 631 632 function LoadUnit( p, uix: integer; TestOnly: boolean): integer;633 var 634 uix1, d, Cost, ToMaster: integer;635 begin 636 result := eOK;637 with RW[ p].Un[uix] do638 begin 639 d := RW[p].Model[mix].Domain;640 if (Master >= 0) or ( d= dSea) or641 (RW[ p].Model[mix].Cap[mcAirTrans] + RW[p].Model[mix].Cap[mcOver] > 0) then642 result := eViolation632 function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer; 633 var 634 uix1, D, Cost, ToMaster: Integer; 635 begin 636 Result := eOK; 637 with RW[P].Un[uix] do 638 begin 639 D := RW[P].Model[mix].Domain; 640 if (Master >= 0) or (D = dSea) or 641 (RW[P].Model[mix].Cap[mcAirTrans] + RW[P].Model[mix].Cap[mcOver] > 0) then 642 Result := eViolation 643 643 else 644 644 begin 645 645 ToMaster := -1; 646 for uix1 := 0 to RW[ p].nUn - 1 do647 if RW[ p].Un[uix1].Loc = Loc then648 with RW[ p].Un[uix1], RW[p].Model[mix] do649 if ( d< dSea) and646 for uix1 := 0 to RW[P].nUn - 1 do 647 if RW[P].Un[uix1].Loc = Loc then 648 with RW[P].Un[uix1], RW[P].Model[mix] do 649 if (D < dSea) and 650 650 (TroopLoad < MTrans * (Cap[mcSeaTrans] + Cap[mcAirTrans])) or 651 ( d= dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then651 (D = dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then 652 652 begin { load onto unit uix1 } 653 653 if (uixSelectedTransport < 0) or (uix1 = uixSelectedTransport) … … 661 661 end; 662 662 if ToMaster < 0 then 663 result := eNoLoadCapacity663 Result := eNoLoadCapacity 664 664 else 665 665 begin 666 if d= dAir then666 if D = dAir then 667 667 Cost := 100 668 668 else 669 Cost := RW[ p].Model[mix].Speed;669 Cost := RW[P].Model[mix].Speed; 670 670 if Movement < Cost then 671 result := eNoTime_Load671 Result := eNoTime_Load 672 672 else if not TestOnly then 673 673 begin 674 FreeUnit( p, uix);675 dec(Movement, Cost);676 if d= dAir then677 inc(RW[p].Un[ToMaster].AirLoad)674 FreeUnit(P, uix); 675 Dec(Movement, Cost); 676 if D = dAir then 677 Inc(RW[P].Un[ToMaster].AirLoad) 678 678 else 679 inc(RW[p].Un[ToMaster].TroopLoad);679 Inc(RW[P].Un[ToMaster].TroopLoad); 680 680 Master := ToMaster; 681 681 UpdateUnitMap(Loc); … … 686 686 end; 687 687 688 function UnloadUnit( p, uix: integer; TestOnly: boolean): integer;689 var 690 Cost: integer;691 begin 692 result := eOK;693 with RW[ p].Un[uix] do688 function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer; 689 var 690 Cost: Integer; 691 begin 692 Result := eOK; 693 with RW[P].Un[uix] do 694 694 if Master < 0 then 695 result := eNotChanged696 else if (RW[ p].Model[mix].Domain < dSea) and695 Result := eNotChanged 696 else if (RW[P].Model[mix].Domain < dSea) and 697 697 (RealMap[Loc] and fTerrain < fGrass) then 698 result := eDomainMismatch698 Result := eDomainMismatch 699 699 // else if (RW[p].Model[mix].Domain<dSea) 700 700 // and (RW[p].Model[mix].Flags and mdCivil<>0) … … 702 702 else 703 703 begin 704 if RW[ p].Model[mix].Domain = dAir then704 if RW[P].Model[mix].Domain = dAir then 705 705 Cost := 100 706 706 else 707 Cost := RW[ p].Model[mix].Speed;707 Cost := RW[P].Model[mix].Speed; 708 708 if Movement < Cost then 709 result := eNoTime_Load709 Result := eNoTime_Load 710 710 else if not TestOnly then 711 711 begin 712 dec(Movement, Cost);713 if RW[ p].Model[mix].Domain = dAir then714 dec(RW[p].Un[Master].AirLoad)715 else 716 begin 717 dec(RW[p].Un[Master].TroopLoad);712 Dec(Movement, Cost); 713 if RW[P].Model[mix].Domain = dAir then 714 Dec(RW[P].Un[Master].AirLoad) 715 else 716 begin 717 Dec(RW[P].Un[Master].TroopLoad); 718 718 // Movement:=0 // no more movement after unload 719 719 end; 720 720 Master := -1; 721 PlaceUnit( p, uix);721 PlaceUnit(P, uix); 722 722 UpdateUnitMap(Loc); 723 723 end; … … 725 725 end; 726 726 727 procedure Recover( p, uix: integer);728 var 729 cix, Recovery: integer;730 begin 731 with RW[ p], Un[uix] do727 procedure Recover(P, uix: Integer); 728 var 729 cix, Recovery: Integer; 730 begin 731 with RW[P], Un[uix] do 732 732 begin 733 733 if (Master >= 0) and (Model[Un[Master].mix].Cap[mcSupplyShip] > 0) then … … 739 739 cix := nCity - 1; 740 740 while (cix >= 0) and (City[cix].Loc <> Loc) do 741 dec(cix);741 Dec(cix); 742 742 if City[cix].Flags and chDisorder <> 0 then 743 743 Recovery := NoCityRecovery … … 762 762 if Recovery > 100 - Health then 763 763 Recovery := 100 - Health; 764 inc(Health, Recovery);764 Inc(Health, Recovery); 765 765 end; 766 766 end; 767 767 768 function GetMoveAdvice( p, uix: integer; var a: TMoveAdviceData): integer;768 function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer; 769 769 const 770 770 // domains … … 778 778 gmaAlpine = 8; 779 779 var 780 i, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8,780 I, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8, 781 781 MoveInfo, HeavyCost, RailCost, MoveCost, AddDamage, MaxDamage, 782 MovementLeft: integer;782 MovementLeft: Integer; 783 783 Map: ^TTileList; 784 784 Q: TIPQ; 785 785 Adjacent: TVicinity8Loc; 786 From: array [0 .. lxmax * lymax - 1] of integer;787 Time: array [0 .. lxmax * lymax - 1] of integer;788 Damage: array [0 .. lxmax * lymax - 1] of integer;789 MountainDelay, Resistant: boolean;786 From: array [0 .. lxmax * lymax - 1] of Integer; 787 Time: array [0 .. lxmax * lymax - 1] of Integer; 788 Damage: array [0 .. lxmax * lymax - 1] of Integer; 789 MountainDelay, Resistant: Boolean; 790 790 // tt,tt0: int64; 791 791 begin 792 792 // QueryPerformanceCounter(tt0); 793 793 794 MaxDamage := RW[ p].Un[uix].Health - 1;795 if MaxDamage > a.MaxHostile_MovementLeft then796 if a.MaxHostile_MovementLeft >= 0 then797 MaxDamage := a.MaxHostile_MovementLeft794 MaxDamage := RW[P].Un[uix].Health - 1; 795 if MaxDamage > A.MaxHostile_MovementLeft then 796 if A.MaxHostile_MovementLeft >= 0 then 797 MaxDamage := A.MaxHostile_MovementLeft 798 798 else 799 799 MaxDamage := 0; 800 800 801 Map := @(RW[ p].Map^);802 if ( a.ToLoc <> maNextCity) and ((a.ToLoc < 0) or (a.ToLoc >= MapSize)) then803 begin 804 result := eInvalid;805 exit;801 Map := @(RW[P].Map^); 802 if (A.ToLoc <> maNextCity) and ((A.ToLoc < 0) or (A.ToLoc >= MapSize)) then 803 begin 804 Result := eInvalid; 805 Exit; 806 806 end; 807 if ( a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fUNKNOWN) then808 begin 809 result := eNoWay;810 exit;807 if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fUNKNOWN) then 808 begin 809 Result := eNoWay; 810 Exit; 811 811 end; 812 812 813 with RW[ p].Model[RW[p].Un[uix].mix] do813 with RW[P].Model[RW[P].Un[uix].mix] do 814 814 case Domain of 815 815 dGround: 816 if ( a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fOcean) then817 begin 818 result := eDomainMismatch;819 exit;816 if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fOcean) then 817 begin 818 Result := eDomainMismatch; 819 Exit; 820 820 end 821 821 else … … 826 826 MoveInfo := gmaGround_NoZoC; 827 827 if Cap[mcOver] > 0 then 828 inc(MoveInfo, gmaOver);828 Inc(MoveInfo, gmaOver); 829 829 if Cap[mcAlpine] > 0 then 830 inc(MoveInfo, gmaAlpine);830 Inc(MoveInfo, gmaAlpine); 831 831 HeavyCost := 50 + (Speed - 150) * 13 shr 7; 832 if GWonder[woShinkansen].EffectiveOwner = pthen832 if GWonder[woShinkansen].EffectiveOwner = P then 833 833 RailCost := 0 834 834 else … … 836 836 maxmov := Speed; 837 837 initmov := 0; 838 Resistant := (GWonder[woGardens].EffectiveOwner = p) or838 Resistant := (GWonder[woGardens].EffectiveOwner = P) or 839 839 (Kind = mkSettler) and (Speed >= 200); 840 840 end; 841 841 dSea: 842 if ( a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain >= fGrass) and843 (Map[ a.ToLoc] and (fCity or fUnit or fCanal) = 0) then844 begin 845 result := eDomainMismatch;846 exit;842 if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain >= fGrass) and 843 (Map[A.ToLoc] and (fCity or fUnit or fCanal) = 0) then 844 begin 845 Result := eDomainMismatch; 846 Exit; 847 847 end 848 848 else … … 850 850 MoveInfo := gmaSea; 851 851 if Cap[mcNav] > 0 then 852 inc(MoveInfo, gmaNav);853 maxmov := UnitSpeed( p, RW[p].Un[uix].mix, 100);854 initmov := maxmov - UnitSpeed( p, RW[p].Un[uix].mix,855 RW[ p].Un[uix].Health);852 Inc(MoveInfo, gmaNav); 853 maxmov := UnitSpeed(P, RW[P].Un[uix].mix, 100); 854 initmov := maxmov - UnitSpeed(P, RW[P].Un[uix].mix, 855 RW[P].Un[uix].Health); 856 856 end; 857 857 dAir: … … 863 863 end; 864 864 865 FromLoc := RW[ p].Un[uix].Loc;865 FromLoc := RW[P].Un[uix].Loc; 866 866 FillChar(Time, SizeOf(Time), 255); { -1 } 867 867 Damage[FromLoc] := 0; 868 868 Q := TIPQ.Create(MapSize); 869 Q.Put(FromLoc, (maxmov - RW[ p].Un[uix].Movement) shl 8);869 Q.Put(FromLoc, (maxmov - RW[P].Un[uix].Movement) shl 8); 870 870 while Q.Get(Loc, T) do 871 871 begin 872 872 Time[Loc] := T; 873 if T >= ( a.MoreTurns + 1) shl 20 then873 if T >= (A.MoreTurns + 1) shl 20 then 874 874 begin 875 875 Loc := -1; … … 877 877 end; 878 878 FromTile := Map[Loc]; 879 if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (FromTile and fCity <> 0)879 if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (FromTile and fCity <> 0) 880 880 then 881 881 Break; 882 882 if T and $FFF00 = $FFF00 then 883 inc(T, $100000); // indicates mountain delay883 Inc(T, $100000); // indicates mountain delay 884 884 V8_to_Loc(Loc, Adjacent); 885 885 for V8 := 0 to 7 do … … 889 889 begin 890 890 ToTile := Map[Loc1]; 891 if (Loc1 = a.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and891 if (Loc1 = A.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and 892 892 not((MoveInfo and 3 = gmaSea) and (FromTile and fTerrain >= fGrass)) 893 893 and not((MoveInfo and 3 = gmaAir) and ((FromTile and fCity <> 0) or … … 898 898 end 899 899 else if (ToTile and fTerrain <> fUNKNOWN) and 900 ((Loc1 = a.ToLoc) or (ToTile and (fCity or fOwned) <> fCity))900 ((Loc1 = A.ToLoc) or (ToTile and (fCity or fOwned) <> fCity)) 901 901 // don't move through enemy cities 902 and ((Loc1 = a.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit))902 and ((Loc1 = A.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit)) 903 903 // way is blocked 904 904 and (ToTile and not FromTile and fPeace = 0) and … … 910 910 // calculate move cost, must be identic to GetMoveCost function 911 911 AddDamage := 0; 912 MountainDelay := false;912 MountainDelay := False; 913 913 case MoveInfo of 914 914 … … 956 956 begin 957 957 MoveCost := maxmov; 958 MountainDelay := true;958 MountainDelay := True; 959 959 end; 960 960 end; … … 990 990 if (MoveCost > 0) and not MountainDelay then 991 991 if V8 and 1 <> 0 then 992 inc(MoveCost, MoveCost * 2)992 Inc(MoveCost, MoveCost * 2) 993 993 else 994 inc(MoveCost, MoveCost);994 Inc(MoveCost, MoveCost); 995 995 996 996 if (MoveInfo and 2 <> 0) // ground unit, check transport load/unload … … 1011 1011 if FromTile and (fTerrain or fCity or fRiver or fCanal or 1012 1012 fSpecial1 { Oasis } ) = fDesert then 1013 inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -1013 Inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) - 1014 1014 1) div maxmov + 1) 1015 1015 else if FromTile and (fTerrain or fCity or fRiver or fCanal) = fArctic 1016 1016 then 1017 inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -1017 Inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) - 1018 1018 1) div maxmov + 1); 1019 1019 … … 1037 1037 end; 1038 1038 FreeAndNil(Q); 1039 if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (Loc >= 0) and1039 if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (Loc >= 0) and 1040 1040 (Map[Loc] and fCity <> 0) then 1041 1041 begin 1042 a.MoreTurns := T shr 20;1042 A.MoreTurns := T shr 20; 1043 1043 EndLoc := Loc; 1044 a.nStep := 0;1044 A.nStep := 0; 1045 1045 while Loc <> FromLoc do 1046 1046 begin 1047 1047 if Time[Loc] < $100000 then 1048 inc(a.nStep);1048 Inc(A.nStep); 1049 1049 Loc := From[Loc]; 1050 1050 end; 1051 1051 Loc := EndLoc; 1052 i := a.nStep;1052 I := A.nStep; 1053 1053 while Loc <> FromLoc do 1054 1054 begin 1055 1055 if Time[Loc] < $100000 then 1056 1056 begin 1057 dec(i);1058 if i< 25 then1059 begin 1060 a.dx[i] := ((Loc mod lx * 2 + Loc div lx and 1) -1057 Dec(I); 1058 if I < 25 then 1059 begin 1060 A.dx[I] := ((Loc mod lx * 2 + Loc div lx and 1) - 1061 1061 (From[Loc] mod lx * 2 + From[Loc] div lx and 1) + 3 * lx) 1062 1062 mod (2 * lx) - lx; 1063 a.dy[i] := Loc div lx - From[Loc] div lx;1063 A.dy[I] := Loc div lx - From[Loc] div lx; 1064 1064 end 1065 1065 end; 1066 1066 Loc := From[Loc]; 1067 1067 end; 1068 a.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;1069 if a.nStep > 25 then1070 a.nStep := 25;1071 result := eOK1068 A.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF; 1069 if A.nStep > 25 then 1070 A.nStep := 25; 1071 Result := eOK 1072 1072 end 1073 1073 else 1074 result := eNoWay;1074 Result := eNoWay; 1075 1075 1076 1076 // QueryPerformanceCounter(tt);{time in s is: (tt-tt0)/PerfFreq} 1077 1077 end; 1078 1078 1079 function CanPlaneReturn( p, uix: integer;1080 PlaneReturnData: TPlaneReturnData): boolean;1079 function CanPlaneReturn(P, uix: Integer; 1080 PlaneReturnData: TPlaneReturnData): Boolean; 1081 1081 const 1082 1082 mfEnd = 1; 1083 1083 mfReached = 2; 1084 1084 var 1085 uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: integer;1085 uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: Integer; 1086 1086 Map: ^TTileList; 1087 1087 Q: TIPQ; 1088 1088 Adjacent: TVicinity8Loc; 1089 MapFlags: array [0 .. lxmax * lymax - 1] of byte;1090 begin 1091 Map := @(RW[ p].Map^);1089 MapFlags: array [0 .. lxmax * lymax - 1] of Byte; 1090 begin 1091 Map := @(RW[P].Map^); 1092 1092 1093 1093 // calculate possible return points 1094 1094 FillChar(MapFlags, SizeOf(MapFlags), 0); 1095 if RW[ p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_Glider then1095 if RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_Glider then 1096 1096 begin 1097 1097 for Loc := 0 to MapSize - 1 do … … 1106 1106 (Map[Loc] and (fUnit or fOwned) <> fUnit) then 1107 1107 MapFlags[Loc] := MapFlags[Loc] or mfEnd; 1108 if RW[ p].Model[RW[p].Un[uix].mix].Cap[mcAirTrans] = 0 then1108 if RW[P].Model[RW[P].Un[uix].mix].Cap[mcAirTrans] = 0 then 1109 1109 // plane can land on carriers 1110 for uix1 := 0 to RW[ p].nUn - 1 do1111 with RW[ p].Un[uix1], RW[p].Model[mix] do1110 for uix1 := 0 to RW[P].nUn - 1 do 1111 with RW[P].Un[uix1], RW[P].Model[mix] do 1112 1112 if AirLoad < MTrans * Cap[mcCarrier] then 1113 1113 MapFlags[Loc] := MapFlags[Loc] or mfEnd; 1114 1114 end; 1115 1115 1116 with RW[ p].Un[uix] do1116 with RW[P].Un[uix] do 1117 1117 begin 1118 1118 if Master >= 0 then // can return to same carrier, even if full now 1119 1119 MapFlags[Loc] := MapFlags[Loc] or mfEnd; 1120 maxmov := RW[ p].Model[mix].Speed;1120 maxmov := RW[P].Model[mix].Speed; 1121 1121 end; 1122 1122 1123 result := false;1123 Result := False; 1124 1124 Q := TIPQ.Create(MapSize); 1125 1125 Q.Put(PlaneReturnData.Loc, (maxmov - PlaneReturnData.Movement) shl 8); … … 1129 1129 if T >= (PlaneReturnData.Fuel + 1) shl 20 then 1130 1130 begin 1131 result := false;1131 Result := False; 1132 1132 Break; 1133 1133 end; 1134 1134 if MapFlags[Loc] and mfEnd <> 0 then 1135 1135 begin 1136 result := true;1136 Result := True; 1137 1137 Break; 1138 1138 end; … … 1173 1173 ____________________________________________________________________ 1174 1174 } 1175 function CalculateJobWork( p, Loc, Job: integer; var JobWork: integer): integer;1176 var 1177 TerrType: integer;1178 begin 1179 result := eOK;1175 function CalculateJobWork(P, Loc, Job: Integer; var JobWork: Integer): Integer; 1176 var 1177 TerrType: Integer; 1178 begin 1179 Result := eOK; 1180 1180 TerrType := RealMap[Loc] and fTerrain; 1181 1181 with Terrain[TerrType] do … … 1183 1183 jCity: 1184 1184 if RealMap[Loc] and fCity <> 0 then 1185 result := eInvalid1185 Result := eInvalid 1186 1186 else if IrrEff = 0 then 1187 result := eNoCityTerrain1187 Result := eNoCityTerrain 1188 1188 else 1189 1189 JobWork := CityWork; … … 1193 1193 JobWork := MoveCost * RoadWork; 1194 1194 if RealMap[Loc] and fRiver <> 0 then 1195 if RW[ p].Tech[adBridgeBuilding] >= tsApplicable then1196 inc(JobWork, RoadBridgeWork) { across river }1195 if RW[P].Tech[adBridgeBuilding] >= tsApplicable then 1196 Inc(JobWork, RoadBridgeWork) { across river } 1197 1197 else 1198 result := eNoBridgeBuilding;1198 Result := eNoBridgeBuilding; 1199 1199 end 1200 1200 else 1201 result := eInvalid;1201 Result := eInvalid; 1202 1202 jRR: 1203 1203 if RealMap[Loc] and fRoad = 0 then 1204 result := eNoPreq1204 Result := eNoPreq 1205 1205 else if RealMap[Loc] and fRR <> 0 then 1206 result := eInvalid1206 Result := eInvalid 1207 1207 else 1208 1208 begin 1209 1209 JobWork := MoveCost * RRWork; 1210 1210 if RealMap[Loc] and fRiver <> 0 then 1211 inc(JobWork, RRBridgeWork); { across river }1211 Inc(JobWork, RRBridgeWork); { across river } 1212 1212 end; 1213 1213 jClear: 1214 if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> p)1214 if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> P) 1215 1215 then 1216 result := eInvalid1216 Result := eInvalid 1217 1217 else if ClearTerrain >= 0 then 1218 1218 JobWork := IrrClearWork 1219 1219 else 1220 result := eInvalid;1220 Result := eInvalid; 1221 1221 jIrr: 1222 1222 begin … … 1224 1224 if (IrrEff = 0) or (RealMap[Loc] and fTerImp = tiIrrigation) or 1225 1225 (RealMap[Loc] and fTerImp = tiFarm) then 1226 result := eInvalid;1226 Result := eInvalid; 1227 1227 end; 1228 1228 jFarm: 1229 1229 if RealMap[Loc] and fTerImp <> tiIrrigation then 1230 result := eNoPreq1230 Result := eNoPreq 1231 1231 else 1232 1232 begin 1233 1233 JobWork := IrrClearWork * FarmWork; 1234 1234 if (JobWork <= 0) or (RealMap[Loc] and fTerImp = tiFarm) then 1235 result := eInvalid;1235 Result := eInvalid; 1236 1236 end; 1237 1237 jAfforest: … … 1239 1239 JobWork := MineAfforestWork 1240 1240 else 1241 result := eInvalid;1241 Result := eInvalid; 1242 1242 jMine: 1243 1243 begin 1244 1244 JobWork := MineAfforestWork; 1245 1245 if (MineEff = 0) or (RealMap[Loc] and fTerImp = tiMine) then 1246 result := eInvalid;1246 Result := eInvalid; 1247 1247 end; 1248 1248 jFort: … … 1250 1250 JobWork := MoveCost * FortWork 1251 1251 else 1252 result := eInvalid;1252 Result := eInvalid; 1253 1253 jCanal: 1254 1254 if (RealMap[Loc] and fCanal = 0) and (TerrType in TerrType_Canalable) … … 1256 1256 JobWork := CanalWork 1257 1257 else 1258 result := eInvalid;1258 Result := eInvalid; 1259 1259 jTrans: 1260 1260 begin 1261 1261 JobWork := TransWork; 1262 1262 if JobWork <= 0 then 1263 result := eInvalid;1263 Result := eInvalid; 1264 1264 end; 1265 1265 jPoll: … … 1267 1267 JobWork := PollWork 1268 1268 else 1269 result := eInvalid;1269 Result := eInvalid; 1270 1270 jBase: 1271 1271 if RealMap[Loc] and fTerImp <> tiBase then 1272 1272 JobWork := MoveCost * BaseWork 1273 1273 else 1274 result := eInvalid;1274 Result := eInvalid; 1275 1275 jPillage: 1276 1276 if RealMap[Loc] and (fRoad or fRR or fCanal or fTerImp) <> 0 then 1277 1277 JobWork := PillageWork 1278 1278 else 1279 result := eInvalid;1280 end; 1281 end; 1282 1283 function StartJob( p, uix, NewJob: integer; TestOnly: boolean): integer;1284 var 1285 JobWork, Loc0, p1, uix1, TerrType: integer;1286 begin 1287 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}1288 result := eOK;1289 with RW[ p].Un[uix] do1279 Result := eInvalid; 1280 end; 1281 end; 1282 1283 function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer; 1284 var 1285 JobWork, Loc0, p1, uix1, TerrType: Integer; 1286 begin 1287 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 1288 Result := eOK; 1289 with RW[P].Un[uix] do 1290 1290 begin 1291 1291 if NewJob = Job then 1292 1292 begin 1293 result := eNotChanged;1294 exit;1293 Result := eNotChanged; 1294 Exit; 1295 1295 end; 1296 1296 if NewJob = jNone then … … 1298 1298 if not TestOnly then 1299 1299 Job := jNone; 1300 exit;1300 Exit; 1301 1301 end; 1302 1302 Loc0 := Loc; … … 1304 1304 (NewJob <> jRR) then 1305 1305 begin 1306 result := eDeadLands;1307 exit;1306 Result := eDeadLands; 1307 Exit; 1308 1308 end; 1309 1309 TerrType := RealMap[Loc0] and fTerrain; 1310 1310 if (RealMap[Loc0] and fCity <> 0) or (TerrType < fGrass) or (Master >= 0) or 1311 not((NewJob = jPillage) and (RW[ p].Model[mix].Domain = dGround) or1312 (RW[ p].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and1313 (RW[ p].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner1311 not((NewJob = jPillage) and (RW[P].Model[mix].Domain = dGround) or 1312 (RW[P].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and 1313 (RW[P].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner 1314 1314 >= 0)) then 1315 1315 begin 1316 result := eInvalid;1317 exit;1316 Result := eInvalid; 1317 Exit; 1318 1318 end; 1319 1319 if (JobPreq[NewJob] <> preNone) and 1320 (RW[ p].Tech[JobPreq[NewJob]] < tsApplicable) then1321 begin 1322 result := eNoPreq;1323 exit;1324 end; 1325 1326 result := CalculateJobWork(p, Loc0, NewJob, JobWork);1327 if (Mode = moPlaying) and ( result = eOK) and (NewJob <> jPoll) then1320 (RW[P].Tech[JobPreq[NewJob]] < tsApplicable) then 1321 begin 1322 Result := eNoPreq; 1323 Exit; 1324 end; 1325 1326 Result := CalculateJobWork(P, Loc0, NewJob, JobWork); 1327 if (Mode = moPlaying) and (Result = eOK) and (NewJob <> jPoll) then 1328 1328 begin // not allowed in territory of friendly nation 1329 1329 p1 := RealMap[Loc0] shr 27; // owner of territory 1330 if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then1331 result := eTreaty; // keep peace treaty!1332 end; 1333 if TestOnly or ( result < rExecuted) then1334 exit;1330 if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then 1331 Result := eTreaty; // keep peace treaty! 1332 end; 1333 if TestOnly or (Result < rExecuted) then 1334 Exit; 1335 1335 1336 1336 if (ToWork[Loc0, NewJob] = 0) or (ToWork[Loc0, NewJob] > JobWork) then … … 1338 1338 Job := NewJob; 1339 1339 Flags := Flags and not unFortified; 1340 for uix1 := 0 to RW[ p].nUn - 1 do1341 if (RW[ p].Un[uix1].Loc = Loc) and1342 (RW[ p].Un[uix1].Job in ContraJobs[NewJob]) then1343 RW[ p].Un[uix1].Job := jNone; // stop contradictive jobs1344 if ServerVersion[ p] < $000EF0 then1345 if Work( p, uix) then1346 result := eJobDone;1347 if (NewJob = jCity) and ( result = eJobDone) then1348 begin 1349 RemoveUnit_UpdateMap( p, uix);1350 result := eCity;1340 for uix1 := 0 to RW[P].nUn - 1 do 1341 if (RW[P].Un[uix1].Loc = Loc) and 1342 (RW[P].Un[uix1].Job in ContraJobs[NewJob]) then 1343 RW[P].Un[uix1].Job := jNone; // stop contradictive jobs 1344 if ServerVersion[P] < $000EF0 then 1345 if Work(P, uix) then 1346 Result := eJobDone; 1347 if (NewJob = jCity) and (Result = eJobDone) then 1348 begin 1349 RemoveUnit_UpdateMap(P, uix); 1350 Result := eCity; 1351 1351 end 1352 1352 else if Health <= 0 then 1353 1353 begin // victim of HostileDamage 1354 RemoveUnit_UpdateMap( p, uix);1355 result := result or rUnitRemoved;1354 RemoveUnit_UpdateMap(P, uix); 1355 Result := Result or rUnitRemoved; 1356 1356 end; 1357 1357 if Mode > moLoading_Fast then 1358 1358 begin 1359 if result = eCity then1360 begin 1361 ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * p));1362 Discover21(Loc0, p, lObserveUnhidden, true, true);1359 if Result = eCity then 1360 begin 1361 ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * P)); 1362 Discover21(Loc0, P, lObserveUnhidden, True, True); 1363 1363 // CheckContact; 1364 1364 end; … … 1367 1367 end; 1368 1368 1369 function Work( p, uix: integer): boolean;1370 var 1371 uix1, j0: integer;1372 begin 1373 result := false;1374 with RW[ p].Un[uix] do1369 function Work(P, uix: Integer): Boolean; 1370 var 1371 uix1, j0: Integer; 1372 begin 1373 Result := False; 1374 with RW[P].Un[uix] do 1375 1375 if Movement >= 100 then 1376 1376 begin 1377 assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob1377 Assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob 1378 1378 if Job >= jRoad then 1379 if integer(Movement) >= integer(ToWork[Loc, Job]) then { work complete }1380 begin 1381 result := true;1379 if Integer(Movement) >= Integer(ToWork[Loc, Job]) then { work complete } 1380 begin 1381 Result := True; 1382 1382 if Job <> jIrr then 1383 Health := Health - HostileDamage( p, mix, Loc, ToWork[Loc, Job]);1384 dec(Movement, ToWork[Loc, Job]);1383 Health := Health - HostileDamage(P, mix, Loc, ToWork[Loc, Job]); 1384 Dec(Movement, ToWork[Loc, Job]); 1385 1385 if not(Job in [jCity, jPillage, jPoll]) then 1386 inc(Worked[p], ToWork[Loc, Job]);1386 Inc(Worked[P], ToWork[Loc, Job]); 1387 1387 if Job = jCity then 1388 1388 begin // found new city 1389 FoundCity( p, Loc);1390 inc(Founded[p]);1391 with RW[ p].City[RW[p].nCity - 1] do1389 FoundCity(P, Loc); 1390 Inc(Founded[P]); 1391 with RW[P].City[RW[P].nCity - 1] do 1392 1392 begin 1393 ID := p shl 12 + Founded[p] - 1;1393 ID := P shl 12 + Founded[P] - 1; 1394 1394 Flags := chFounded; 1395 1395 end; 1396 1396 if Mode = moPlaying then 1397 1397 begin 1398 LogCheckBorders( p, RW[p].nCity - 1);1399 RecalcPeaceMap( p);1398 LogCheckBorders(P, RW[P].nCity - 1); 1399 RecalcPeaceMap(P); 1400 1400 end; 1401 1401 {$IFOPT O-} if Mode < moPlaying then 1402 InvalidTreatyMap := not(1 shl p); {$ENDIF}1402 InvalidTreatyMap := not(1 shl P); {$ENDIF} 1403 1403 // territory should not be considered for the rest of the command 1404 1404 // execution, because during loading a game it's incorrect before 1405 1405 // subsequent sIntExpandTerritory is processed 1406 RW[ p].Un[uix].Health := 0; // causes unit to be removed later1406 RW[P].Un[uix].Health := 0; // causes unit to be removed later 1407 1407 end 1408 1408 else 1409 CompleteJob( p, Loc, Job);1409 CompleteJob(P, Loc, Job); 1410 1410 ToWork[Loc, Job] := 0; 1411 1411 j0 := Job; 1412 for uix1 := 0 to RW[ p].nUn - 1 do1413 if (RW[ p].Un[uix1].Loc = Loc) and (RW[p].Un[uix1].Job = j0) then1414 RW[ p].Un[uix1].Job := jNone1412 for uix1 := 0 to RW[P].nUn - 1 do 1413 if (RW[P].Un[uix1].Loc = Loc) and (RW[P].Un[uix1].Job = j0) then 1414 RW[P].Un[uix1].Job := jNone 1415 1415 end 1416 1416 else 1417 1417 begin 1418 dec(ToWork[Loc, Job], Movement);1418 Dec(ToWork[Loc, Job], Movement); 1419 1419 if not(Job in [jCity, jPillage, jPoll]) then 1420 inc(Worked[p], Movement);1421 Health := Health - HostileDamage( p, mix, Loc, Movement);1420 Inc(Worked[P], Movement); 1421 Health := Health - HostileDamage(P, mix, Loc, Movement); 1422 1422 Movement := 0; 1423 1423 end … … 1425 1425 end; 1426 1426 1427 function GetJobProgress( p, Loc: integer;1428 var JobProgressData: TJobProgressData): integer;1429 var 1430 Job, JobResult, uix: integer;1427 function GetJobProgress(P, Loc: Integer; 1428 var JobProgressData: TJobProgressData): Integer; 1429 var 1430 Job, JobResult, uix: Integer; 1431 1431 begin 1432 1432 for Job := 0 to nJob - 1 do 1433 1433 begin 1434 JobResult := CalculateJobWork( p, Loc, Job, JobProgressData[Job].Required);1434 JobResult := CalculateJobWork(P, Loc, Job, JobProgressData[Job].Required); 1435 1435 if JobResult = eOK then 1436 1436 begin … … 1448 1448 JobProgressData[Job].NextTurnPlus := 0; 1449 1449 end; 1450 for uix := 0 to RW[ p].nUn - 1 do1451 if (RW[ p].Un[uix].Loc = Loc) and (RW[p].Un[uix].Movement >= 100) then1452 inc(JobProgressData[RW[p].Un[uix].Job].NextTurnPlus,1453 RW[ p].Un[uix].Movement);1454 result := eOK;1450 for uix := 0 to RW[P].nUn - 1 do 1451 if (RW[P].Un[uix].Loc = Loc) and (RW[P].Un[uix].Movement >= 100) then 1452 Inc(JobProgressData[RW[P].Un[uix].Job].NextTurnPlus, 1453 RW[P].Un[uix].Movement); 1454 Result := eOK; 1455 1455 end; 1456 1456
Note:
See TracChangeset
for help on using the changeset viewer.