- Timestamp:
- Nov 30, 2023, 10:16:14 PM (2 years ago)
- Location:
- branches/highdpi
- Files:
-
- 10 added
- 1 deleted
- 108 edited
- 16 moved
-
AI/StdAI/AI.pas (modified) (133 diffs)
-
AI/StdAI/Barbarina.pas (modified) (75 diffs)
-
AI/StdAI/CustomAI.pas (modified) (47 diffs)
-
AI/StdAI/CustomAI_Reload.pas (modified) (34 diffs)
-
AI/StdAI/Pile.pas (modified) (6 diffs)
-
AI/StdAI/Protocol.pas (modified) (10 diffs)
-
AI/StdAI/StdAI.ai.txt (modified) (1 diff)
-
AI/StdAI/StdAI.lpr (modified) (2 diffs)
-
AI/StdAI/ToolAI.pas (modified) (71 diffs)
-
Back.lfm (modified) (2 diffs)
-
Back.pas (modified) (2 diffs)
-
Brain.pas (moved) (moved from branches/highdpi/UBrain.pas ) (6 diffs)
-
CityProcessing.pas (modified) (78 diffs)
-
CmdList.pas (modified) (17 diffs)
-
Database.pas (modified) (184 diffs)
-
Direct.lfm (modified) (2 diffs)
-
Direct.pas (modified) (14 diffs)
-
GameServer.pas (modified) (233 diffs)
-
Global.pas (modified) (1 diff)
-
Graphics/System2.grs (modified) (1 diff)
-
Help/Help.txt (moved) (moved from branches/highdpi/Help/help.txt )
-
IPQ.pas (modified) (6 diffs)
-
Inp.pas (modified) (2 diffs)
-
Install/rpm/c-evo.spec (modified) (2 diffs)
-
Install/snap/local/build.sh (modified) (1 diff)
-
Install/snap/snapcraft.yaml (modified) (4 diffs)
-
Integrated.lpi (modified) (6 diffs)
-
Integrated.lpr (modified) (2 diffs)
-
Language.txt (modified) (1 diff)
-
LocalPlayer/Battle.pas (modified) (16 diffs)
-
LocalPlayer/CityScreen.pas (modified) (71 diffs)
-
LocalPlayer/CityType.pas (modified) (12 diffs)
-
LocalPlayer/ClientTools.pas (modified) (40 diffs)
-
LocalPlayer/Diagram.pas (modified) (16 diffs)
-
LocalPlayer/Diplomacy.pas (modified) (9 diffs)
-
LocalPlayer/Draft.pas (modified) (11 diffs)
-
LocalPlayer/Enhance.pas (modified) (16 diffs)
-
LocalPlayer/Help.pas (modified) (85 diffs)
-
LocalPlayer/IsoEngine.pas (modified) (66 diffs)
-
LocalPlayer/KeyBindings.pas (moved) (moved from branches/highdpi/LocalPlayer/UKeyBindings.pas ) (7 diffs)
-
LocalPlayer/LocalPlayer.pas (modified) (1 diff)
-
LocalPlayer/MessgEx.lfm (modified) (4 diffs)
-
LocalPlayer/MessgEx.pas (modified) (27 diffs)
-
LocalPlayer/NatStat.pas (modified) (25 diffs)
-
LocalPlayer/Nego.pas (modified) (40 diffs)
-
LocalPlayer/PVSB.pas (modified) (6 diffs)
-
LocalPlayer/Rates.pas (modified) (11 diffs)
-
LocalPlayer/Select.lfm (modified) (7 diffs)
-
LocalPlayer/Select.pas (modified) (86 diffs)
-
LocalPlayer/TechTree.pas (modified) (10 diffs)
-
LocalPlayer/Term.lfm (modified) (23 diffs)
-
LocalPlayer/Term.pas (modified) (350 diffs)
-
LocalPlayer/Tribes.pas (modified) (20 diffs)
-
LocalPlayer/UnitStat.pas (modified) (33 diffs)
-
LocalPlayer/Wonders.pas (modified) (11 diffs)
-
Localization/cs/Help/Help.txt (moved) (moved from branches/highdpi/Localization/cs/Help/help.txt ) (19 diffs)
-
Localization/cs/Language.txt (modified) (12 diffs)
-
Localization/cs/Language2.txt (modified) (2 diffs)
-
Localization/cs/readme!!!.txt (modified) (2 diffs)
-
Localization/de/Help/Help.txt (moved) (moved from branches/highdpi/Localization/de/Help/help.txt ) (11 diffs)
-
Localization/de/Language.txt (modified) (1 diff)
-
Localization/de/Language2.txt (added)
-
Localization/fr (added)
-
Localization/fr/Help (added)
-
Localization/fr/Help/Help.txt (added)
-
Localization/fr/Language.txt (added)
-
Localization/fr/Language2.txt (added)
-
Localization/fr/Tribes (added)
-
Localization/fr/Tribes/StdUnits.txt (added)
-
Localization/it/Help/Help.txt (moved) (moved from branches/highdpi/Localization/it/Help/help.txt ) (10 diffs)
-
Localization/it/Language.txt (modified) (1 diff)
-
Localization/ru/Help/Help.txt (moved) (moved from branches/highdpi/Localization/ru/Help/help.txt ) (7 diffs)
-
Localization/ru/Language.txt (modified) (1 diff)
-
Localization/ru/Language2.txt (added)
-
Localization/zh-Hans/Fonts.txt (moved) (moved from branches/highdpi/Localization/zh-Hans/fonts.txt ) (1 diff)
-
Localization/zh-Hans/Help/Help.txt (moved) (moved from branches/highdpi/Localization/zh-Hans/Help/help.txt ) (6 diffs)
-
Localization/zh-Hans/Language.txt (moved) (moved from branches/highdpi/Localization/zh-Hans/language.txt ) (2 diffs)
-
Localization/zh-Hans/ReadMe.txt (modified) (1 diff)
-
Localization/zh-Hans/Tribes/Americans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Babyl.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/British.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Chinese.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Egyptians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/French.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Germans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Greeks.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Japanese.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Mongols.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Persians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Phoenicians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Romans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Russians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/Spanish.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hans/Tribes/StdUnits.txt (modified) (1 diff)
-
Localization/zh-Hans/Tribes/Vikings.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Help/Help.txt (moved) (moved from branches/highdpi/Localization/zh-Hant/Help/help.txt ) (6 diffs)
-
Localization/zh-Hant/Language.txt (moved) (moved from branches/highdpi/Localization/zh-Hant/language.txt ) (2 diffs)
-
Localization/zh-Hant/ReadMe.txt (modified) (1 diff)
-
Localization/zh-Hant/Tribes/Americans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Babyl.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/British.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Chinese.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Egyptians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/French.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Germans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Greeks.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Japanese.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Mongols.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Persians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Phoenicians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Romans.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Russians.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/Spanish.tribe.txt (modified) (2 diffs)
-
Localization/zh-Hant/Tribes/StdUnits.txt (modified) (1 diff)
-
Localization/zh-Hant/Tribes/Vikings.tribe.txt (modified) (2 diffs)
-
Log.pas (modified) (6 diffs)
-
Messg.pas (modified) (2 diffs)
-
MiniMap.pas (moved) (moved from branches/highdpi/UMiniMap.pas ) (9 diffs)
-
Network/NetworkClient.pas (moved) (moved from branches/highdpi/Network/UNetworkClient.pas ) (4 diffs)
-
Network/NetworkCommon.pas (moved) (moved from branches/highdpi/Network/UNetworkCommon.pas ) (3 diffs)
-
Network/NetworkServer.pas (moved) (moved from branches/highdpi/Network/UNetworkServer.pas ) (7 diffs)
-
NoTerm.pas (modified) (19 diffs)
-
Packages/DpiControls/DpiControls.lpk (modified) (3 diffs)
-
Packages/DpiControls/UDpiControls.pas (modified) (29 diffs)
-
Packages/DpiControls/UPixelPointer2.pas (modified) (1 diff)
-
Platform.pas (modified) (5 diffs)
-
Protocol.pas (modified) (70 diffs)
-
Release notes.txt (added)
-
Settings.lfm (modified) (7 diffs)
-
Settings.pas (modified) (9 diffs)
-
Start.lfm (modified) (1 diff)
-
Start.pas (modified) (77 diffs)
-
ULanguages.pas (deleted)
-
UnitProcessing.pas (modified) (63 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/AI/StdAI/AI.pas
r349 r465 23 23 24 24 nResearchOrder = 46; 25 ResearchOrder: array[0..1, 0..nResearchOrder - 1] of integer =25 ResearchOrder: array[0..1, 0..nResearchOrder - 1] of Integer = 26 26 ((adWheel, adWarriorCode, adHorsebackRiding, adCeremonialBurial, adPolytheism, 27 27 adMonarchy, adMysticism, adPoetry, adAstronomy, adMonotheism, … … 76 76 77 77 // mil research 78 BetterQuality: array[0..nModelCat - 1] of integer = (50, 50, 80, 80);78 BetterQuality: array[0..nModelCat - 1] of Integer = (50, 50, 80, 80); 79 79 MaxBuildWorseThanBestModel = 20; 80 80 MaxExistWorseThanBestModel = 50; … … 85 85 nRequestedTechs = 48; 86 86 87 PlayerHash: array[0..nPl - 1] of integer =87 PlayerHash: array[0..nPl - 1] of Integer = 88 88 (7, 6, 0, 2, 10, 8, 12, 14, 4, 1, 3, 5, 9, 11, 13); 89 89 … … 92 92 93 93 TPersistentData = record 94 LastResearchTech, BehaviorFlags, TheologyPartner: integer;94 LastResearchTech, BehaviorFlags, TheologyPartner: Integer; 95 95 RejectTurn: array[Suggestion, 0..15] of smallint; 96 RequestedTechs: array[0..nRequestedTechs - 1] of integer;96 RequestedTechs: array[0..nRequestedTechs - 1] of Integer; 97 97 // ad + p shl 8 + Turn shl 16 98 98 end; 99 99 100 100 TAI = class(TBarbarina) 101 constructor Create(Nation: integer); override;101 constructor Create(Nation: Integer); override; 102 102 103 103 procedure SetDataDefaults; override; … … 106 106 Data: ^TPersistentData; 107 107 WarNations, BombardingNations, mixSettlers, mixCaravan, mixTownGuard, 108 mixSlaves, mixMilitia, mixCruiser, OceanWithShip: integer;108 mixSlaves, mixMilitia, mixCruiser, OceanWithShip: Integer; 109 109 NegoCause: (Routine, CheckBarbarina); 110 SettlerSurplus: array[0..maxCOD - 1] of integer;111 uixPatrol: array[0..maxCOD - 1] of integer;112 113 ContinentPresence: array[0..maxCOD - 1] of integer;114 OceanPresence: array[0..maxCOD - 1] of integer;115 UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of integer;116 117 TotalPopulation: array[0..nPl - 1] of integer;118 ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of integer;110 SettlerSurplus: array[0..maxCOD - 1] of Integer; 111 uixPatrol: array[0..maxCOD - 1] of Integer; 112 113 ContinentPresence: array[0..maxCOD - 1] of Integer; 114 OceanPresence: array[0..maxCOD - 1] of Integer; 115 UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of Integer; 116 117 TotalPopulation: array[0..nPl - 1] of Integer; 118 ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of Integer; 119 119 // 1 means enemy territory spotted but no city 120 DistrictPopulation: array[0..maxCOD - 1] of integer;121 122 ModelCat: array[0..nMmax - 1] of integer;123 ModelQuality: array[0..nMmax - 1] of integer;124 ModelBestQuality: array[0..nModelCat - 1] of integer;125 126 AdvanceValue: array[0..nAdv - 1] of integer;127 AdvanceValuesSet: boolean;120 DistrictPopulation: array[0..maxCOD - 1] of Integer; 121 122 ModelCat: array[0..nMmax - 1] of Integer; 123 ModelQuality: array[0..nMmax - 1] of Integer; 124 ModelBestQuality: array[0..nModelCat - 1] of Integer; 125 126 AdvanceValue: array[0..nAdv - 1] of Integer; 127 AdvanceValuesSet: Boolean; 128 128 129 129 procedure DoTurn; override; 130 130 procedure DoNegotiation; override; 131 function ChooseResearchAdvance: integer; override;132 function ChooseStealAdvance: integer; override;133 function ChooseGovernment: integer; override;134 function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; override;135 function OnNegoRejected_CancelTreaty: boolean; override;136 137 procedure FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);131 function ChooseResearchAdvance: Integer; override; 132 function ChooseStealAdvance: Integer; override; 133 function ChooseGovernment: Integer; override; 134 function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; override; 135 function OnNegoRejected_CancelTreaty: Boolean; override; 136 137 procedure FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer); 138 138 procedure CheckGender; 139 139 procedure AnalyzeMap; … … 141 141 procedure AttackAndPatrol; 142 142 procedure MoveUnitsHome; 143 procedure CheckAttack(uix: integer);144 procedure Patrol(uix: integer);143 procedure CheckAttack(uix: Integer); 144 procedure Patrol(uix: Integer); 145 145 procedure SetCityProduction; 146 146 procedure SetAdvanceValues; 147 function HavePort: boolean;148 {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: integer);{$ENDIF}147 function HavePort: Boolean; 148 {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: Integer);{$ENDIF} 149 149 150 150 // research 151 procedure RateModel(const mi: TModelInfo; var Category, Quality: integer);152 procedure RateMyModel(mix: integer; var Category, Quality: integer);153 function IsBetterModel(const mi: TModelInfo): boolean;151 procedure RateModel(const mi: TModelInfo; var Category, Quality: Integer); 152 procedure RateMyModel(mix: Integer; var Category, Quality: Integer); 153 function IsBetterModel(const mi: TModelInfo): Boolean; 154 154 155 155 //terraforming 156 procedure TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);156 procedure TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer); 157 157 procedure ProcessSettlers; 158 158 159 159 // diplomacy 160 function MostWanted(Nation, adGiveAway: integer): integer;160 function MostWanted(Nation, adGiveAway: Integer): Integer; 161 161 162 162 end; … … 174 174 175 175 var 176 LeaveOutValue: array[0..nAdv - 1] of integer; 177 178 179 constructor TAI.Create(Nation: integer); 176 LeaveOutValue: array[0..nAdv - 1] of Integer; 177 178 constructor TAI.Create(Nation: Integer); 180 179 begin 181 180 inherited; 182 Data := pointer(RO.Data);181 Data := Pointer(RO.Data); 183 182 {$IFDEF DEBUG} 184 183 if Nation = 1 then … … 193 192 begin 194 193 LastResearchTech := -1; 195 if PlayerHash[ me] > 7 then194 if PlayerHash[Me] > 7 then 196 195 BehaviorFlags := bFemale 197 196 else … … 199 198 DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender)); 200 199 TheologyPartner := -1; 201 fillchar(RejectTurn, sizeof(RejectTurn), $FF);202 Fillchar(RequestedTechs, sizeof(RequestedTechs), $FF);200 FillChar(RejectTurn, SizeOf(RejectTurn), $FF); 201 Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF); 203 202 end; 204 203 end; 205 204 206 function TAI.OnNegoRejected_CancelTreaty: boolean;205 function TAI.OnNegoRejected_CancelTreaty: Boolean; 207 206 begin 208 207 Data.RejectTurn[suContact, Opponent] := RO.Turn; … … 210 209 end; 211 210 212 213 211 //------------------------------- 214 212 // RESEARCH 215 213 //------------------------------- 216 214 217 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: integer);215 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: Integer); 218 216 var 219 EffectiveTransport: integer;217 EffectiveTransport: Integer; 220 218 begin 221 219 if mi.Kind >= mkScout then 222 220 begin 223 221 Category := mctNone; 224 exit;222 Exit; 225 223 end; 226 224 case mi.Domain of … … 294 292 end; 295 293 296 procedure TAI.RateMyModel(mix: integer; var Category, Quality: integer);294 procedure TAI.RateMyModel(mix: Integer; var Category, Quality: Integer); 297 295 var 298 296 mi: TModelInfo; 299 297 begin 300 MakeModelInfo( me, mix, MyModel[mix], mi);298 MakeModelInfo(Me, mix, MyModel[mix], mi); 301 299 RateModel(mi, Category, Quality); 302 300 end; 303 301 304 function TAI.IsBetterModel(const mi: TModelInfo): boolean;302 function TAI.IsBetterModel(const mi: TModelInfo): Boolean; 305 303 var 306 mix, Cat, Quality, Cat1, Quality1: integer;304 mix, Cat, Quality, Cat1, Quality1: Integer; 307 305 begin 308 306 RateModel(mi, Cat, Quality); … … 314 312 begin 315 313 Result := False; 316 exit;314 Exit; 317 315 end; 318 316 end; … … 320 318 end; 321 319 322 function TAI.ChooseResearchAdvance: integer;320 function TAI.ChooseResearchAdvance: Integer; 323 321 var 324 adNext, iad, i, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,325 NewResearch, StateOfArt, mix: integer;322 adNext, iad, I, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut, 323 NewResearch, StateOfArt, mix: Integer; 326 324 mi: TModelInfo; 327 Entry: array[0..nAdv - 1] of boolean;328 ok: boolean;329 330 function MarkEntry(ad: integer): boolean;325 Entry: array[0..nAdv - 1] of Boolean; 326 ok: Boolean; 327 328 function MarkEntry(ad: Integer): Boolean; 331 329 begin 332 330 if RO.Tech[ad] >= tsApplicable then … … 375 373 end; 376 374 377 procedure OptimizeDevModel(OptimizeCaps: integer);375 procedure OptimizeDevModel(OptimizeCaps: Integer); 378 376 var 379 f, Cat, OriginalCat, Quality, BestQuality, Best: integer;377 F, Cat, OriginalCat, Quality, BestQuality, Best: Integer; 380 378 mi: TModelInfo; 381 379 begin 382 MakeModelInfo( me, 0, RO.DevModel, mi);380 MakeModelInfo(Me, 0, RO.DevModel, mi); 383 381 RateModel(mi, OriginalCat, BestQuality); 384 382 repeat 385 383 Best := -1; 386 for f:= 0 to nFeature - 1 do387 if (1 shl fand OptimizeCaps <> 0) and388 ((Feature[ f].Preq < 0) or IsResearched(Feature[f].Preq)) // check prerequisite389 and (RO.DevModel.Weight + Feature[ f].Weight <= RO.DevModel.MaxWeight) and390 not (( f >= mcFirstNonCap) and (RO.DevModel.Cap[f] > 0)) then391 begin 392 if SetNewModelFeature( f, RO.DevModel.Cap[f] + 1) >= rExecuted then384 for F := 0 to nFeature - 1 do 385 if (1 shl F and OptimizeCaps <> 0) and 386 ((Feature[F].Preq < 0) or IsResearched(Feature[F].Preq)) // check prerequisite 387 and (RO.DevModel.Weight + Feature[F].Weight <= RO.DevModel.MaxWeight) and 388 not ((F >= mcFirstNonCap) and (RO.DevModel.Cap[F] > 0)) then 389 begin 390 if SetNewModelFeature(F, RO.DevModel.Cap[F] + 1) >= rExecuted then 393 391 begin 394 MakeModelInfo( me, 0, RO.DevModel, mi);392 MakeModelInfo(Me, 0, RO.DevModel, mi); 395 393 RateModel(mi, Cat, Quality); 396 assert(Cat = OriginalCat);394 Assert(Cat = OriginalCat); 397 395 if Quality > BestQuality then 398 396 begin 399 Best := f;397 Best := F; 400 398 BestQuality := Quality; 401 399 end; 402 SetNewModelFeature( f, RO.DevModel.Cap[f] - 1);400 SetNewModelFeature(F, RO.DevModel.Cap[F] - 1); 403 401 end; 404 402 end; … … 408 406 end; 409 407 410 function LeaveOutsMissing(ad: integer): boolean;408 function LeaveOutsMissing(ad: Integer): Boolean; 411 409 var 412 i: integer;410 I: Integer; 413 411 begin 414 412 Result := False; … … 424 422 Result := True 425 423 else 426 for i:= 0 to 1 do427 if AdvPreq[ad, i] >= 0 then428 Result := Result or LeaveOutsMissing(AdvPreq[ad, i]);424 for I := 0 to 1 do 425 if AdvPreq[ad, I] >= 0 then 426 Result := Result or LeaveOutsMissing(AdvPreq[ad, I]); 429 427 end; 430 428 … … 434 432 Result := Barbarina_ChooseResearchAdvance; 435 433 if Result >= 0 then 436 exit;434 Exit; 437 435 end; 438 436 … … 446 444 Result := ad; 447 445 if Result >= 0 then 448 exit;446 Exit; 449 447 450 448 if Data.BehaviorFlags and bBarbarina = 0 then … … 462 460 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl 463 461 mcMob + 1 shl mcLongRange + 1 shl mcFanatic); 464 MakeModelInfo( me, 0, RO.DevModel, mi);462 MakeModelInfo(Me, 0, RO.DevModel, mi); 465 463 if IsBetterModel(mi) then 466 464 begin 467 465 Result := adMilitary; 468 exit;466 Exit; 469 467 end; 470 468 … … 473 471 SetNewModelFeature(mcOffense, 1); 474 472 OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl mcFanatic); 475 MakeModelInfo( me, 0, RO.DevModel, mi);473 MakeModelInfo(Me, 0, RO.DevModel, mi); 476 474 if IsBetterModel(mi) then 477 475 begin 478 476 Result := adMilitary; 479 exit;477 Exit; 480 478 end; 481 479 end; … … 493 491 SetNewModelFeature(mcWeapons, 0); 494 492 SetNewModelFeature(mcDefense, 3); 495 exit;493 Exit; 496 494 end; 497 495 end; … … 508 506 OptimizeDevModel(1 shl mcDefense+1 shl mcSeaTrans+1 shl mcTurbines 509 507 +1 shl mcAirDef); 510 MakeModelInfo( me,0,RO.DevModel,mi);508 MakeModelInfo(Me,0,RO.DevModel,mi); 511 509 if IsBetterModel(mi) then 512 begin result:=adMilitary; exit end;510 begin Result:=adMilitary; Exit end; 513 511 end; 514 512 … … 521 519 OptimizeDevModel(1 shl mcOffense+1 shl mcDefense 522 520 +1 shl mcLongRange+1 shl mcAirDef+1 shl mcRadar); 523 MakeModelInfo( me,0,RO.DevModel,mi);521 MakeModelInfo(Me,0,RO.DevModel,mi); 524 522 if IsBetterModel(mi) then 525 begin result:=adMilitary; exit end;523 begin Result:=adMilitary; Exit end; 526 524 end 527 525 end; … … 547 545 begin 548 546 ok := True; 549 break;547 Break; 550 548 end; 551 549 if not ok then … … 590 588 begin // 2 of 3 required 591 589 Count := 0; 592 for i:= 0 to 2 do593 if RO.Tech[AdvPreq[ad, i]] >= tsApplicable then590 for I := 0 to 2 do 591 if RO.Tech[AdvPreq[ad, I]] >= tsApplicable then 594 592 Inc(Count); 595 593 if Count >= 2 then 596 594 begin 597 595 Result := ad; 598 exit;596 Exit; 599 597 end; 600 598 end … … 604 602 begin 605 603 Result := ad; 606 exit;604 Exit; 607 605 end; 608 606 end; … … 620 618 begin // go for future techs 621 619 Result := -1; 622 i:= 0;620 I := 0; 623 621 for ad := nAdv - 4 to nAdv - 1 do 624 622 if (RO.Tech[ad] < MaxFutureTech) and (RO.Tech[AdvPreq[ad, 0]] >= 625 623 tsApplicable) then 626 624 begin 627 Inc( i);628 if random( i) = 0 then625 Inc(I); 626 if random(I) = 0 then 629 627 Result := ad; 630 628 end; 631 assert((Result < 0) or AdvanceResearchable(Result));632 exit;633 end; 634 635 assert(NewResearch >= 0);636 fillchar(Entry, sizeof(Entry), False);629 Assert((Result < 0) or AdvanceResearchable(Result)); 630 Exit; 631 end; 632 633 Assert(NewResearch >= 0); 634 FillChar(Entry, SizeOf(Entry), False); 637 635 MarkEntry(NewResearch); 638 636 Result := -1; … … 640 638 if Entry[ad] and ((Result < 0) or (Advancedness[ad] > Advancedness[Result])) then 641 639 Result := ad; 642 assert(Result >= 0);640 Assert(Result >= 0); 643 641 end; 644 642 645 function TAI.ChooseStealAdvance: integer;643 function TAI.ChooseStealAdvance: Integer; 646 644 var 647 ad: integer;645 ad: Integer; 648 646 begin 649 647 Result := -1; … … 654 652 end; 655 653 656 657 654 //------------------------------- 658 655 // TERRAFORMING … … 662 659 twpAllowFarmland = $0001; 663 660 664 procedure TAI.TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);661 procedure TAI.TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer); 665 662 var 666 OldTile, TerrType: cardinal;663 OldTile, TerrType: Cardinal; 667 664 TileInfo: TTileInfo; 668 665 begin … … 672 669 begin 673 670 Value := 3 * 8 - 1; 674 exit;671 Exit; 675 672 end; // better than any tile with 2 food 676 673 … … 693 690 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 694 691 TerrType := fGrass; 695 Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);692 Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5); 696 693 end 697 694 else if IsResearched(adExplosives) and … … 704 701 Map[Loc] := Map[Loc] and not fTerrain or fGrass; 705 702 TerrType := fGrass; 706 Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);703 Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5); 707 704 end; 708 705 if (Terrain[TerrType].MineEff > 0) and (RO.Government <> gDespotism) then … … 767 764 end; 768 765 end; 769 Server(sGetTileInfo, me, Loc, TileInfo);766 Server(sGetTileInfo, Me, Loc, TileInfo); 770 767 Value := TileInfo.Food * 8 + TileInfo.Prod * 2 + TileInfo.Trade; 771 768 Map[Loc] := OldTile; … … 775 772 procedure TAI.ProcessSettlers; 776 773 var 777 i, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,774 I, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade, 778 775 CityFood, Happy, TestScore, BestNearCityScore, BestUnusedValue, 779 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: integer;780 Tile: cardinal;781 FoodOk, Started: boolean;776 BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: Integer; 777 Tile: Cardinal; 778 FoodOk, Started: Boolean; 782 779 Radius: TVicinity21Loc; 783 780 CityAreaInfo: TCityAreaInfo; 784 TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of integer;785 786 procedure AddJob(Loc, Job, Score: integer);781 TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of Integer; 782 783 procedure AddJob(Loc, Job, Score: Integer); 787 784 // set Score=1 for low-priority jobs 788 785 begin … … 792 789 end; 793 790 794 procedure ReserveCityRadius(Loc: integer);791 procedure ReserveCityRadius(Loc: Integer); 795 792 var 796 V21, RadiusLoc: integer;793 V21, RadiusLoc: Integer; 797 794 Radius: TVicinity21Loc; 798 795 begin … … 811 808 procedure ScoreRoadConnections; 812 809 var 813 V8, nFragments, Loc, Loc1, History, RoadScore, a, b, FullyDeveloped,814 ConnectMask: integer;815 BridgeOk: boolean;810 V8, nFragments, Loc, Loc1, History, RoadScore, A, B, FullyDeveloped, 811 ConnectMask: Integer; 812 BridgeOk: Boolean; 816 813 Adjacent: TVicinity8Loc; 817 814 begin … … 824 821 if ((1 shl (Map[Loc] and fTerrain)) and (1 shl fOcean or 1 shl 825 822 fShore or 1 shl fDesert or 1 shl fArctic or 1 shl fUNKNOWN) = 0) and 826 (RO.Territory[Loc] = me) and (Map[Loc] and FullyDeveloped = 0) and823 (RO.Territory[Loc] = Me) and (Map[Loc] and FullyDeveloped = 0) and 827 824 (BridgeOk or (Map[Loc] and fRiver = 0)) then 828 825 begin … … 838 835 Loc1 := Adjacent[V8 and 7]; 839 836 History := History shl 1; 840 if (Loc1 >= 0) and (RO.Territory[Loc1] = me) and837 if (Loc1 >= 0) and (RO.Territory[Loc1] = Me) and 841 838 (Map[Loc1] and ConnectMask <> 0) then 842 839 begin … … 854 851 else if History and 4 <> 0 then 855 852 begin 856 V8_to_ab((V8 - 1) and 7, a, b);857 ab_to_Loc(Loc, a shl 1, bshl 1, Loc1);853 V8_to_ab((V8 - 1) and 7, A, B); 854 ab_to_Loc(Loc, A shl 1, B shl 1, Loc1); 858 855 if (Loc1 >= 0) and (Map[Loc1] and ConnectMask <> 0) then 859 856 Dec(nFragments); … … 879 876 880 877 begin 881 fillchar(SettlerSurplus, sizeof(SettlerSurplus), 0);878 FillChar(SettlerSurplus, SizeOf(SettlerSurplus), 0); 882 879 JobAssignment_Initialize; 883 880 884 881 if (Data.BehaviorFlags and bBarbarina = 0) or (RO.nCity < 3) then 885 882 begin 886 fillchar(TileFood, sizeof(TileFood), 0);887 fillchar(ResourceScore, sizeof(ResourceScore), 0);883 FillChar(TileFood, SizeOf(TileFood), 0); 884 FillChar(ResourceScore, SizeOf(ResourceScore), 0); 888 885 for Loc := 0 to MapSize - 1 do 889 886 if Map[Loc] and fTerrain <> fUNKNOWN then … … 926 923 927 924 // rate possible new cities 928 fillchar(CityScore, MapSize * sizeof(integer), 0);925 FillChar(CityScore, MapSize * SizeOf(Integer), 0); 929 926 for Loc := 0 to MapSize - 1 do 930 927 begin … … 933 930 ((RO.Government <> gDespotism) or (Map[Loc] and fSpecial = fSpecial1)) or 934 931 (Map[Loc] and (fTerrain or fSpecial) = fPrairie or fSpecial1)); 935 if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = me)) then932 if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = Me)) then 936 933 begin 937 934 TestScore := 0; … … 953 950 if CityFood >= MinCityFood then // city is worth founding 954 951 begin 955 TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor me) * 4567) mod 251;952 TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor Me) * 4567) mod 251; 956 953 // some unexactness, random but always the same for this tile 957 954 if TestScore > BestNearCityScore then … … 991 988 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 992 989 begin 993 assert(RadiusLoc >= 0);990 Assert(RadiusLoc >= 0); 994 991 TileWorkPlan(RadiusLoc, cix, Value, NextJob, TotalWork); 995 992 if (NextJob = jRoad) and (Built[imPalace] + … … 1003 1000 begin // tile could be exploited 1004 1001 RadiusLoc := Radius[V21]; 1005 assert(RadiusLoc >= 0);1002 Assert(RadiusLoc >= 0); 1006 1003 if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then 1007 1004 begin … … 1027 1024 if Data.BehaviorFlags and bBarbarina = 0 then // low priority jobs 1028 1025 for Loc := 0 to MapSize - 1 do 1029 if RO.Territory[Loc] = me then1026 if RO.Territory[Loc] = Me then 1030 1027 begin 1031 1028 Tile := Map[Loc]; … … 1051 1048 begin 1052 1049 for part := 0 to nShipPart - 1 do 1053 for i:= 0 to ColonyShipPlan[part].nLocFoundCity - 1 do1054 begin 1055 Loc := ColonyShipPlan[part].LocFoundCity[ i];1050 for I := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do 1051 begin 1052 Loc := ColonyShipPlan[part].LocFoundCity[I]; 1056 1053 Started := False; 1057 1054 for uix := 0 to RO.nUn - 1 do … … 1059 1056 begin 1060 1057 Started := True; 1061 break;1058 Break; 1062 1059 end; 1063 1060 if not Started then … … 1122 1119 begin // settlers could be added to this city 1123 1120 Happy := BasicHappy; 1124 for i:= 0 to nWonder - 1 do1125 if Built[ i] > 0 then1121 for I := 0 to nWonder - 1 do 1122 if Built[I] > 0 then 1126 1123 Inc(Happy); 1127 1124 if Built[imTemple] > 0 then … … 1130 1127 begin 1131 1128 Inc(Happy, 2); 1132 if RO.Wonder[woBach].EffectiveOwner = me then1129 if RO.Wonder[woBach].EffectiveOwner = Me then 1133 1130 Inc(Happy, 1); 1134 1131 end; … … 1145 1142 end; 1146 1143 end; 1147 end; // ProcessSettlers 1148 1144 end; 1149 1145 1150 1146 //------------------------------- … … 1154 1150 procedure TAI.DoTurn; 1155 1151 var 1156 emix, i, p1, TaxSum, ScienceSum, NewTaxRate: integer;1157 AllHateMe: boolean;1152 emix, I, p1, TaxSum, ScienceSum, NewTaxRate: Integer; 1153 AllHateMe: Boolean; 1158 1154 {$IFDEF PERF} 1159 1155 PF, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9: int64; … … 1161 1157 begin 1162 1158 {$IFDEF DEBUG} 1163 fillchar(DebugMap, sizeof(DebugMap), 0);1159 FillChar(DebugMap, SizeOf(DebugMap), 0); 1164 1160 {$ENDIF} 1165 1161 … … 1173 1169 WarNations := PresenceUnknown; 1174 1170 for p1 := 0 to nPl - 1 do 1175 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then1171 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then 1176 1172 Inc(WarNations, 1 shl p1); 1177 1173 BombardingNations := 0; … … 1189 1185 CheckGender; 1190 1186 1191 if G.Difficulty[ me] < MaxDiff then // not on beginner level1187 if G.Difficulty[Me] < MaxDiff then // not on beginner level 1192 1188 begin 1193 1189 if (Data.LastResearchTech = adHorsebackRiding) and (RO.ResearchTech < 0) and 1194 1190 (random(6) = 0) and (HavePort or (ContinentPresence[0] and not 1195 (1 shl me or PresenceUnknown) <> 0)) then1191 (1 shl Me or PresenceUnknown) <> 0)) then 1196 1192 begin 1197 1193 Data.BehaviorFlags := Data.BehaviorFlags or bBarbarina_Hide; … … 1210 1206 begin 1211 1207 AllHateMe := False; 1212 break;1208 Break; 1213 1209 end; 1214 1210 if AllHateMe then … … 1306 1302 else 1307 1303 begin 1308 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[ me] - 4) * 2) then1304 if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[Me] - 4) * 2) then 1309 1305 NewTaxRate := RO.TaxRate // don't check decreasing tax 1310 1306 else … … 1313 1309 begin 1314 1310 SumCities(NewTaxRate, TaxSum, ScienceSum); 1315 if RO.Money + TaxSum >= (TotalPopulation[ me] - 4) then1316 break; // enough1311 if RO.Money + TaxSum >= (TotalPopulation[Me] - 4) then 1312 Break; // enough 1317 1313 Inc(NewTaxRate, 10); 1318 1314 end; … … 1328 1324 // research completed 1329 1325 for p1 := 0 to nPl - 1 do 1330 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1326 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1331 1327 (RO.EnemyReport[p1].TurnOfCivilReport + TechReportOutdated > RO.Turn) and 1332 1328 (RO.EnemyReport[p1].Tech[Data.LastResearchTech] < tsSeen) then 1333 1329 begin // latest researched advance might be of interest to this nation 1334 for i:= 0 to nRequestedTechs - 1 do1335 if (Data.RequestedTechs[ i] >= 0) and1336 (Data.RequestedTechs[ i] shr 8 and $F = p1) then1337 Data.RequestedTechs[ i] := -1;1330 for I := 0 to nRequestedTechs - 1 do 1331 if (Data.RequestedTechs[I] >= 0) and 1332 (Data.RequestedTechs[I] shr 8 and $F = p1) then 1333 Data.RequestedTechs[I] := -1; 1338 1334 end; 1339 1335 if RO.ResearchTech = adMilitary then … … 1341 1337 else 1342 1338 Data.LastResearchTech := RO.ResearchTech; 1343 for i:= 0 to nRequestedTechs - 1 do1344 if (Data.RequestedTechs[ i] >= 0) and1345 (RO.Tech[Data.RequestedTechs[ i] and $FF] >= tsSeen) then1346 Data.RequestedTechs[ i] := -1;1339 for I := 0 to nRequestedTechs - 1 do 1340 if (Data.RequestedTechs[I] >= 0) and 1341 (RO.Tech[Data.RequestedTechs[I] and $FF] >= tsSeen) then 1342 Data.RequestedTechs[I] := -1; 1347 1343 1348 1344 // prepare negotiation … … 1350 1346 SetAdvanceValues; 1351 1347 1352 1353 1348 {$IFDEF DEBUG} 1354 1349 (*for p1:=0 to nPl-1 do 1355 if (p1<> me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace)1350 if (p1<>Me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace) 1356 1351 and (RO.EnemyReport[p1].TurnOfCivilReport>=0) then 1357 1352 TraceAdvanceValues(p1);*) … … 1368 1363 1369 1364 {$IFDEF DEBUG} 1370 procedure TAI.TraceAdvanceValues(Nation: integer);1365 procedure TAI.TraceAdvanceValues(Nation: Integer); 1371 1366 var 1372 ad: integer;1367 ad: Integer; 1373 1368 begin 1374 1369 for ad := 0 to nAdv - 1 do … … 1380 1375 end; 1381 1376 end; 1382 1383 1377 {$ENDIF} 1384 1385 1378 1386 1379 procedure TAI.CheckGender; 1387 1380 var 1388 p1, NewGender: integer;1381 p1, NewGender: Integer; 1389 1382 begin 1390 1383 NewGender := -1; 1391 1384 for p1 := 0 to nPl - 1 do 1392 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and1385 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and 1393 1386 (RO.Treaty[p1] >= trFriendlyContact) then 1394 if PlayerHash[ me] > PlayerHash[p1] then1387 if PlayerHash[Me] > PlayerHash[p1] then 1395 1388 begin 1396 1389 if NewGender = bMale then 1397 1390 begin 1398 1391 NewGender := -2; 1399 break;1392 Break; 1400 1393 end; // ambiguous, don't change gender 1401 1394 NewGender := bFemale; … … 1406 1399 begin 1407 1400 NewGender := -2; 1408 break;1401 Break; 1409 1402 end; // ambiguous, don't change gender 1410 1403 NewGender := bMale; … … 1417 1410 end; 1418 1411 1419 1420 1412 procedure TAI.SetAdvanceValues; 1421 1413 1422 procedure RateResearchAdv(ad, Time: integer);1414 procedure RateResearchAdv(ad, Time: Integer); 1423 1415 var 1424 Value: integer;1416 Value: Integer; 1425 1417 begin 1426 1418 if Time = 0 then … … 1432 1424 end; 1433 1425 1434 procedure SetPreqValues(ad, Value: integer);1426 procedure SetPreqValues(ad, Value: Integer); 1435 1427 begin 1436 1428 if (RO.Tech[ad] < tsSeen) and (ad <> RO.ResearchTech) then … … 1455 1447 end; 1456 1448 1457 procedure RateImpPreq(iix, Value: integer);1449 procedure RateImpPreq(iix, Value: Integer); 1458 1450 begin 1459 1451 if (Value > 0) and (Imp[iix].Preq >= 0) then … … 1462 1454 1463 1455 var 1464 emix, cix, adMissing, iad, ad, Count, i, Time, d, CurrentCost,1465 CurrentStrength, MaxSize, MaxTrade: integer;1466 PreView, Emergency, Bombarded: boolean;1456 emix, cix, adMissing, iad, ad, Count, I, Time, D, CurrentCost, 1457 CurrentStrength, MaxSize, MaxTrade: Integer; 1458 PreView, Emergency, Bombarded: Boolean; 1467 1459 begin 1468 1460 if AdvanceValuesSet then 1469 exit;1461 Exit; 1470 1462 AdvanceValuesSet := True; 1471 1463 1472 fillchar(AdvanceValue, sizeof(AdvanceValue), 0);1464 FillChar(AdvanceValue, SizeOf(AdvanceValue), 0); 1473 1465 1474 1466 // rate techs to ensure research progress … … 1490 1482 begin // 2 of 3 required 1491 1483 Count := 0; 1492 for i:= 0 to 2 do1493 if (AdvPreq[ad, i] = RO.ResearchTech) or1494 (RO.Tech[AdvPreq[ad, i]] >= tsSeen) then1484 for I := 0 to 2 do 1485 if (AdvPreq[ad, I] = RO.ResearchTech) or 1486 (RO.Tech[AdvPreq[ad, I]] >= tsSeen) then 1495 1487 Inc(Count); 1496 1488 if Count >= 2 then … … 1500 1492 if ad <> adMassProduction then // don't score third preq for MP 1501 1493 begin 1502 for i:= 0 to 2 do1503 if (AdvPreq[ad, i] <> RO.ResearchTech) and1504 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then1505 RateResearchAdv(AdvPreq[ad, i], Time);1494 for I := 0 to 2 do 1495 if (AdvPreq[ad, I] <> RO.ResearchTech) and 1496 (RO.Tech[AdvPreq[ad, I]] < tsSeen) then 1497 RateResearchAdv(AdvPreq[ad, I], Time); 1506 1498 end; 1507 1499 Inc(Time, 2 - Count); … … 1511 1503 begin 1512 1504 Count := 0; 1513 for i:= 0 to 1 do1514 if (AdvPreq[ad, i] <> preNone) and (AdvPreq[ad, i] <> RO.ResearchTech) and1515 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then1505 for I := 0 to 1 do 1506 if (AdvPreq[ad, I] <> preNone) and (AdvPreq[ad, I] <> RO.ResearchTech) and 1507 (RO.Tech[AdvPreq[ad, I]] < tsSeen) then 1516 1508 begin 1517 RateResearchAdv(AdvPreq[ad, i], Time);1509 RateResearchAdv(AdvPreq[ad, I], Time); 1518 1510 Inc(Count); 1519 1511 end; … … 1544 1536 1545 1537 // rate military techs 1546 for d:= 0 to nDomains - 1 do1538 for D := 0 to nDomains - 1 do 1547 1539 begin 1548 1540 CurrentCost := 0; 1549 1541 CurrentStrength := 0; 1550 1542 for PreView := True downto False do 1551 for i:= 0 to nUpgrade - 1 do1552 with Upgrade[ d, i] do1543 for I := 0 to nUpgrade - 1 do 1544 with Upgrade[D, I] do 1553 1545 if (Preq >= 0) and not (Preq in FutureTech) then 1554 1546 if ((Ro.ResearchTech = Preq) or (RO.Tech[Preq] >= tsSeen)) = PreView then … … 1561 1553 else 1562 1554 begin // rate 1563 if ( i> 0) and (Trans > 0) then1555 if (I > 0) and (Trans > 0) then 1564 1556 Inc(AdvanceValue[Preq], $400); 1565 1557 if Cost <= CurrentCost then 1566 Inc(AdvanceValue[Preq], (4 - d) * Strength * $400 div1567 (CurrentStrength + Upgrade[ d, 0].Strength))1558 Inc(AdvanceValue[Preq], (4 - D) * Strength * $400 div 1559 (CurrentStrength + Upgrade[D, 0].Strength)) 1568 1560 else 1569 Inc(AdvanceValue[Preq], (4 - d) * Strength * $200 div1570 (CurrentStrength + Upgrade[ d, 0].Strength));1561 Inc(AdvanceValue[Preq], (4 - D) * Strength * $200 div 1562 (CurrentStrength + Upgrade[D, 0].Strength)); 1571 1563 end; 1572 1564 end; … … 1648 1640 procedure TAI.AnalyzeMap; 1649 1641 var 1650 cix, Loc, Loc1, V8, f1, p1: integer;1642 cix, Loc, Loc1, V8, f1, p1: Integer; 1651 1643 Adjacent: TVicinity8Loc; 1652 1644 begin … … 1654 1646 1655 1647 // collect nation presence information for continents and oceans 1656 fillchar(ContinentPresence, sizeof(ContinentPresence), 0);1657 fillchar(OceanPresence, sizeof(OceanPresence), 0);1648 FillChar(ContinentPresence, SizeOf(ContinentPresence), 0); 1649 FillChar(OceanPresence, SizeOf(OceanPresence), 0); 1658 1650 for Loc := 0 to MapSize - 1 do 1659 1651 begin … … 1707 1699 end; 1708 1700 1709 fillchar(TotalPopulation, sizeof(TotalPopulation), 0);1710 fillchar(ContinentPopulation, sizeof(ContinentPopulation), 0);1711 fillchar(DistrictPopulation, 4 * nDistrict, 0);1701 FillChar(TotalPopulation, SizeOf(TotalPopulation), 0); 1702 FillChar(ContinentPopulation, SizeOf(ContinentPopulation), 0); 1703 FillChar(DistrictPopulation, 4 * nDistrict, 0); 1712 1704 1713 1705 // count population … … 1724 1716 if Loc >= 0 then 1725 1717 begin 1726 Inc(TotalPopulation[ me], Size);1727 assert(District[Loc] >= 0);1718 Inc(TotalPopulation[Me], Size); 1719 Assert(District[Loc] >= 0); 1728 1720 if District[Loc] < maxCOD then 1729 1721 Inc(DistrictPopulation[District[Loc]], Size); … … 1733 1725 procedure TAI.CollectModelCatStat; 1734 1726 var 1735 i, uix, Cat, mix, Quality: integer;1727 I, uix, Cat, mix, Quality: Integer; 1736 1728 begin 1737 1729 // categorize models … … 1779 1771 if (Loc >= 0) and (mix = mixCruiser) and (Map[Loc] and fTerrain < fGrass) then 1780 1772 begin 1781 i:= Formation[Loc];1782 if ( i >= 0) and (i< maxCOD) then1783 OceanWithShip := OceanWithShip or (1 shl i);1773 I := Formation[Loc]; 1774 if (I >= 0) and (I < maxCOD) then 1775 OceanWithShip := OceanWithShip or (1 shl I); 1784 1776 end; 1785 1777 end; 1786 1787 1778 1788 1779 procedure TAI.MoveUnitsHome; 1789 1780 const 1790 1781 PatrolDestination = lxmax * lymax; 1791 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of integer = (2, 1);1782 FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of Integer = (2, 1); 1792 1783 var 1793 Cat, i, mix, cix, uix, Loop, nModelOrder: integer;1784 Cat, I, mix, cix, uix, Loop, nModelOrder: Integer; 1794 1785 Adjacent: TVicinity8Loc; 1795 LocNeed: array[0..lxmax * lymax - 1] of shortint;1796 Destination: array[0..nUmax - 1] of integer;1797 DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of integer;1798 ModelOrder: array[0..nMmax - 1] of integer;1799 complete, Fortified: boolean;1800 1801 function IsBombarded(cix: integer): boolean;1786 LocNeed: array[0..lxmax * lymax - 1] of ShortInt; 1787 Destination: array[0..nUmax - 1] of Integer; 1788 DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of Integer; 1789 ModelOrder: array[0..nMmax - 1] of Integer; 1790 complete, Fortified: Boolean; 1791 1792 function IsBombarded(cix: Integer): Boolean; 1802 1793 var 1803 Loc1, V8: integer;1794 Loc1, V8: Integer; 1804 1795 Adjacent: TVicinity8Loc; 1805 1796 begin … … 1818 1809 begin 1819 1810 Result := True; 1820 exit;1811 Exit; 1821 1812 end; 1822 1813 end; … … 1824 1815 end; 1825 1816 1826 procedure TryUtilize(uix: integer);1817 procedure TryUtilize(uix: Integer); 1827 1818 var 1828 cix, ProdCost, UtilizeCost: integer;1819 cix, ProdCost, UtilizeCost: Integer; 1829 1820 begin 1830 1821 if (MyUnit[uix].Health = 100) and (Map[MyUnit[uix].Loc] and … … 1838 1829 UtilizeCost := MyModel[MyUnit[uix].mix].Cost; 1839 1830 if Prod < (ProdCost - UtilizeCost * 2 div 3) * 1840 BuildCostMod[G.Difficulty[ me]] div 12 then1831 BuildCostMod[G.Difficulty[Me]] div 12 then 1841 1832 Unit_Disband(uix); 1842 1833 end; … … 1844 1835 end; 1845 1836 1846 procedure FindDestination(uix: integer);1837 procedure FindDestination(uix: Integer); 1847 1838 var 1848 MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: integer;1849 Reached: array[0..lxmax * lymax - 1] of boolean;1850 begin 1851 fillchar(Reached, MapSize, False);1839 MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: Integer; 1840 Reached: array[0..lxmax * lymax - 1] of Boolean; 1841 begin 1842 FillChar(Reached, MapSize, False); 1852 1843 Pile.Create(MapSize); 1853 1844 with MyUnit[uix] do … … 1863 1854 if (District[Loc1] >= 0) and (District[Loc1] < maxCOD) then 1864 1855 begin 1865 assert(DistrictNeed[District[Loc1]] > 0);1856 Assert(DistrictNeed[District[Loc1]] > 0); 1866 1857 Dec(DistrictNeed[District[Loc1]]); 1867 1858 end; 1868 1859 Destination[uix] := Loc1; 1869 break;1860 Break; 1870 1861 end; 1871 1862 Reached[Loc1] := True; … … 1874 1865 begin 1875 1866 NextLoc := Adjacent[V8]; 1876 if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = me) then1867 if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = Me) then 1877 1868 case CheckStep(MoveStyle, Time, V8 and 1, NextTime, RecoverTurns, 1878 1869 Map[Loc1], Map[NextLoc], False) of … … 1882 1873 Reached[NextLoc] := True; // don't check moving there again 1883 1874 csCheckTerritory: 1884 assert(False);1875 Assert(False); 1885 1876 end; 1886 1877 end; … … 1896 1887 Unit_Disband(uix); 1897 1888 1898 fillchar(UnitLack, sizeof(UnitLack), 0);1899 fillchar(Destination, 4 * RO.nUn, $FF);1900 for i:= 0 to maxCOD - 1 do1901 if uixPatrol[ i] >= 0 then1902 Destination[uixPatrol[ i]] := PatrolDestination;1889 FillChar(UnitLack, SizeOf(UnitLack), 0); 1890 FillChar(Destination, 4 * RO.nUn, $FF); 1891 for I := 0 to maxCOD - 1 do 1892 if uixPatrol[I] >= 0 then 1893 Destination[uixPatrol[I]] := PatrolDestination; 1903 1894 for uix := 0 to RO.nUn - 1 do 1904 1895 if (MyUnit[uix].mix = mixMilitia) or (MyUnit[uix].mix = mixCruiser) then … … 1912 1903 if ModelCat[mix] = Cat then 1913 1904 begin 1914 i:= nModelOrder;1915 while ( i > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[i- 1]]) do1916 begin 1917 ModelOrder[ i] := ModelOrder[i- 1];1918 Dec( i);1919 end; 1920 ModelOrder[ i] := mix;1905 I := nModelOrder; 1906 while (I > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[I - 1]]) do 1907 begin 1908 ModelOrder[I] := ModelOrder[I - 1]; 1909 Dec(I); 1910 end; 1911 ModelOrder[I] := mix; 1921 1912 Inc(nModelOrder); 1922 1913 end; … … 1931 1922 TryUtilize(uix); 1932 1923 1933 fillchar(LocNeed, MapSize, 0);1934 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1924 FillChar(LocNeed, MapSize, 0); 1925 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 1935 1926 1936 1927 for cix := 0 to RO.nCity - 1 do … … 1955 1946 for uix := 0 to RO.nUn - 1 do 1956 1947 with MyUnit[uix] do 1957 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = me) then1948 if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = Me) then 1958 1949 begin 1959 1950 LocNeed[Loc] := 1; … … 1963 1954 1964 1955 complete := Loop >= FirstSurplusLoop[Cat]; 1965 for i:= nModelOrder - 1 downto 0 do1956 for I := nModelOrder - 1 downto 0 do 1966 1957 begin 1967 1958 for Fortified := True downto False do 1968 1959 for uix := 0 to RO.nUn - 1 do 1969 1960 with MyUnit[uix] do 1970 if (mix = ModelOrder[ i]) and (Loc >= 0) and1961 if (mix = ModelOrder[I]) and (Loc >= 0) and 1971 1962 (Destination[uix] < 0) and (Master < 0) and 1972 1963 ((Flags and unFortified <> 0) = Fortified) and (LocNeed[Loc] > 0) then … … 1981 1972 for uix := 0 to RO.nUn - 1 do 1982 1973 with MyUnit[uix] do 1983 if (mix = ModelOrder[ i]) and (Loc >= 0) and (Destination[uix] < 0) and1974 if (mix = ModelOrder[I]) and (Loc >= 0) and (Destination[uix] < 0) and 1984 1975 (Master < 0) then 1985 1976 if (District[Loc] >= 0) and (District[Loc] < maxCOD) and … … 1998 1989 // distribute obsolete settlers 1999 1990 repeat 2000 fillchar(LocNeed, MapSize, 0);2001 fillchar(DistrictNeed, sizeof(DistrictNeed), 0);1991 FillChar(LocNeed, MapSize, 0); 1992 FillChar(DistrictNeed, SizeOf(DistrictNeed), 0); 2002 1993 2003 1994 for cix := 0 to RO.nCity - 1 do … … 2049 2040 for uix := 0 to RO.nUn - 1 do 2050 2041 with MyUnit[uix] do 2051 if (Loc >= 0) and (RO.Territory[Loc] = me) and (District[Loc] >= 0) and2042 if (Loc >= 0) and (RO.Territory[Loc] = Me) and (District[Loc] >= 0) and 2052 2043 (District[Loc] < maxCOD) and (ModelQuality[mix] > 0) then 2053 2044 case ModelCat[mix] of … … 2055 2046 Dec(UnitLack[District[Loc], ModelCat[mix]]) 2056 2047 end; 2057 end; // MoveUnitsHome 2058 2059 2060 procedure TAI.CheckAttack(uix: integer); 2048 end; 2049 2050 procedure TAI.CheckAttack(uix: Integer); 2061 2051 var 2062 2052 AttackScore, BestCount, AttackLoc, TestLoc, NextLoc, TestTime, V8, 2063 2053 TestScore, euix, MyDamage, EnemyDamage, OldLoc, AttackForecast, 2064 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: integer;2065 Tile: cardinal;2066 Exhausted: boolean;2054 MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: Integer; 2055 Tile: Cardinal; 2056 Exhausted: Boolean; 2067 2057 Adjacent: TVicinity8Loc; 2068 Reached: array[0..lxmax * lymax - 1] of boolean;2058 Reached: array[0..lxmax * lymax - 1] of Boolean; 2069 2059 2070 2060 begin … … 2075 2065 AttackScore := -999999; 2076 2066 AttackLoc := -1; 2077 fillchar(Reached, MapSize, False);2067 FillChar(Reached, MapSize, False); 2078 2068 Pile.Create(MapSize); 2079 2069 Pile.Put(Loc, $800 - Movement); … … 2087 2077 if ((Tile and fUnit) <> 0) and ((Tile and fOwned) = 0) then 2088 2078 begin // enemy unit 2089 assert(TestTime < $1000);2079 Assert(TestTime < $1000); 2090 2080 Unit_FindEnemyDefender(TestLoc, euix); 2091 2081 if RO.Treaty[RO.EnemyUn[euix].Owner] < trPeace then … … 2176 2166 until Exhausted; 2177 2167 end; 2178 end; // CheckAttack 2179 2180 2181 procedure TAI.Patrol(uix: integer); 2168 end; 2169 2170 procedure TAI.Patrol(uix: Integer); 2182 2171 const 2183 2172 DistanceScore = 4; 2184 2173 var 2185 2174 PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8, 2186 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: integer;2187 Tile: cardinal;2188 Exhausted, CaptureOnly: boolean;2175 TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: Integer; 2176 Tile: Cardinal; 2177 Exhausted, CaptureOnly: Boolean; 2189 2178 Adjacent: TVicinity8Loc; 2190 AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;2179 AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt; 2191 2180 2192 2181 begin … … 2207 2196 // assume a score of 50 is the best achievable 2208 2197 or CaptureOnly and (TestTime >= $1000) then 2209 break;2198 Break; 2210 2199 2211 2200 TestScore := 0; … … 2282 2271 until Exhausted; 2283 2272 end; 2284 end; // Patrol2273 end; 2285 2274 2286 2275 procedure TAI.AttackAndPatrol; 2287 2276 const 2288 2277 nAttackCatOrder = 3; 2289 AttackCatOrder: array[0..nAttackCatOrder - 1] of integer =2278 AttackCatOrder: array[0..nAttackCatOrder - 1] of Integer = 2290 2279 (mctGroundAttacker, mctCruiser, mctGroundDefender); 2291 2280 var 2292 iCat, uix, uix1: integer;2293 IsPatrolUnit, Fortified: boolean;2281 iCat, uix, uix1: Integer; 2282 IsPatrolUnit, Fortified: Boolean; 2294 2283 begin 2295 2284 for uix := 0 to RO.nUn - 1 do … … 2310 2299 CheckAttack(uix); 2311 2300 2312 fillchar(uixPatrol, sizeof(uixPatrol), $FF);2301 FillChar(uixPatrol, SizeOf(uixPatrol), $FF); 2313 2302 for uix := 0 to RO.nUn - 1 do 2314 2303 with MyUnit[uix], MyModel[mix] do … … 2342 2331 Patrol(uix); 2343 2332 end; 2344 end; // AttackAndPatrol 2345 2346 2347 function TAI.HavePort: boolean; 2333 end; 2334 2335 function TAI.HavePort: Boolean; 2348 2336 var 2349 V8, cix, AdjacentLoc, f: integer;2337 V8, cix, AdjacentLoc, F: Integer; 2350 2338 Adjacent: TVicinity8Loc; 2351 2339 begin … … 2361 2349 if (AdjacentLoc >= 0) and ((Map[AdjacentLoc] and fTerrain) < fGrass) then 2362 2350 begin 2363 f:= Formation[AdjacentLoc];2364 if ( f >= 0) and (f < maxCOD) and (OceanPresence[f] and2365 not (1 shl me) <> 0) then2351 F := Formation[AdjacentLoc]; 2352 if (F >= 0) and (F < maxCOD) and (OceanPresence[F] and 2353 not (1 shl Me) <> 0) then 2366 2354 Result := True; 2367 2355 end; … … 2369 2357 end; 2370 2358 end; 2371 2372 2359 2373 2360 procedure TAI.SetCityProduction; 2374 2361 var 2375 2362 uix, cix, iix, dtr, V8, V21, NewImprovement, AdjacentLoc, MaxSettlers, 2376 maxcount, cixMilAcademy: integer;2377 TerrType: cardinal;2363 maxcount, cixMilAcademy: Integer; 2364 TerrType: Cardinal; 2378 2365 IsPort, IsNavalBase, NeedCruiser, CheckProd, Destructed, ProduceSettlers, 2379 ProduceMil: boolean;2366 ProduceMil: Boolean; 2380 2367 Adjacent: TVicinity8Loc; 2381 2368 Radius: TVicinity21Loc; 2382 2369 Report: TCityReport; 2383 HomeCount, CityProdRep: array[0..nCmax - 1] of integer;2384 MilProdCity: array[0..nCmax - 1] of boolean;2385 2386 procedure TryBuild(Improvement: integer);2370 HomeCount, CityProdRep: array[0..nCmax - 1] of Integer; 2371 MilProdCity: array[0..nCmax - 1] of Boolean; 2372 2373 procedure TryBuild(Improvement: Integer); 2387 2374 begin 2388 2375 if (NewImprovement = imTrGoods) // not already improvement of higher priority found … … 2394 2381 end; 2395 2382 2396 procedure TryDestruct(Improvement: integer);2383 procedure TryDestruct(Improvement: Integer); 2397 2384 begin 2398 2385 if Destructed or (MyCity[cix].Built[Improvement] = 0) then 2399 exit;2386 Exit; 2400 2387 if City_CurrentImprovementProject(cix) >= 0 then 2401 2388 City_RebuildImprovement(cix, Improvement) … … 2405 2392 and (Imp[CurrentImprovementProject].Kind in [ikCommon,ikNatGlobal,ikNatLocal]) 2406 2393 and ((Imp[CurrentImprovementProject].Cost*3-Imp[Improvement].Cost*2) 2407 *BuildCostMod[G.Difficulty[ me]]>MyCity[cix].Prod*(12*3)) then}2394 *BuildCostMod[G.Difficulty[Me]]>MyCity[cix].Prod*(12*3)) then} 2408 2395 Destructed := True; 2409 2396 end; 2410 2397 2411 function ChooseBuildModel(Cat: integer): integer;2398 function ChooseBuildModel(Cat: Integer): Integer; 2412 2399 var 2413 Count, mix: integer;2400 Count, mix: Integer; 2414 2401 begin 2415 2402 Count := 0; … … 2422 2409 Result := mix; 2423 2410 end; 2424 assert(Count > 0);2411 Assert(Count > 0); 2425 2412 end; 2426 2413 … … 2428 2415 // find military production cities 2429 2416 var 2430 cix, Total, d, Threshold, NewThreshold, Share, SharePlus, cixWorst: integer;2431 begin 2432 fillchar(MilProdCity, RO.nCity, 0);2417 cix, Total, D, Threshold, NewThreshold, Share, SharePlus, cixWorst: Integer; 2418 begin 2419 FillChar(MilProdCity, RO.nCity, 0); 2433 2420 GetCityProdPotential; 2434 for d:= 0 to maxCOD - 1 do2421 for D := 0 to maxCOD - 1 do 2435 2422 begin 2436 2423 Total := 0; 2437 2424 for cix := 0 to RO.nCity - 1 do 2438 2425 with MyCity[cix] do 2439 if (Loc >= 0) and (District[Loc] = d) then2426 if (Loc >= 0) and (District[Loc] = D) then 2440 2427 Total := Total + CityResult[cix]; 2441 2428 if Total = 0 then … … 2446 2433 for cix := 0 to RO.nCity - 1 do 2447 2434 with MyCity[cix] do 2448 if (Loc >= 0) and (District[Loc] = d) and2435 if (Loc >= 0) and (District[Loc] = D) and 2449 2436 (Built[imBarracks] + Built[imMilAcademy] > 0) then 2450 2437 begin … … 2461 2448 for cix := 0 to RO.nCity - 1 do 2462 2449 with MyCity[cix] do 2463 if (Loc >= 0) and (District[Loc] = d) and2450 if (Loc >= 0) and (District[Loc] = D) and 2464 2451 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2465 2452 (Built[imObservatory] = 0) and (CityResult[cix] < Threshold) and … … 2478 2465 for cix := 0 to RO.nCity - 1 do 2479 2466 with MyCity[cix] do 2480 if (Loc >= 0) and (District[Loc] = d) and2467 if (Loc >= 0) and (District[Loc] = D) and 2481 2468 (Built[imBarracks] + Built[imMilAcademy] = 0) and 2482 2469 (CityResult[cix] >= Threshold) then … … 2484 2471 { if (cixWorst>=0) 2485 2472 and (Share-CityResult[cixWorst]*2>=Total*MilProdShare div 100) then 2486 MilProdCity[cixWorst]:= false;}2473 MilProdCity[cixWorst]:=False;} 2487 2474 end; 2488 2475 … … 2491 2478 if cixStateImp[imPalace] >= 0 then 2492 2479 begin 2493 d:= District[MyCity[cixStateImp[imPalace]].Loc];2494 if ( d >= 0) and (d< maxCOD) then2480 D := District[MyCity[cixStateImp[imPalace]].Loc]; 2481 if (D >= 0) and (D < maxCOD) then 2495 2482 begin 2496 2483 cixMilAcademy := -1; 2497 2484 for cix := 0 to RO.nCity - 1 do 2498 2485 with MyCity[cix] do 2499 if (Loc >= 0) and (District[Loc] = d) and2486 if (Loc >= 0) and (District[Loc] = D) and 2500 2487 (Built[imObservatory] + Built[imPalace] = 0) and 2501 2488 ((cixMilAcademy < 0) or (CityResult[cix] > CityResult[cixMilAcademy])) then … … 2513 2500 procedure ChangeHomeCities; 2514 2501 var 2515 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: integer;2502 uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: Integer; 2516 2503 begin 2517 2504 if RO.Government in [gAnarchy, gFundamentalism] then 2518 exit;2505 Exit; 2519 2506 for uix := 0 to RO.nUn - 1 do 2520 2507 with MyUnit[uix] do … … 2564 2551 2565 2552 begin 2566 fillchar(HomeCount, 4 * RO.nCity, 0);2553 FillChar(HomeCount, 4 * RO.nCity, 0); 2567 2554 for uix := 0 to RO.nUn - 1 do 2568 2555 with MyUnit[uix] do … … 2757 2744 begin 2758 2745 TryBuild(imHarbor); 2759 break;2746 Break; 2760 2747 end; 2761 2748 end; … … 2775 2762 TryBuild(imRecycling); 2776 2763 if (Report.Trade - Report.Corruption >= 11) and 2777 (RO.Money < TotalPopulation[ me] * 2) then2764 (RO.Money < TotalPopulation[Me] * 2) then 2778 2765 TryBuild(imBank); 2779 2766 if (RO.NatBuilt[imStockEx] = 0) and … … 2812 2799 2813 2800 // rebuild imps no longer needed 2814 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[ me] * 4) then2801 if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[Me] * 4) then 2815 2802 TryDestruct(imBank) 2816 2803 else if Report.Happy * 2 >= Size + 6 then … … 2836 2823 2837 2824 ChangeHomeCities; 2838 end; // SetCityProduction 2839 2840 2841 function TAI.ChooseGovernment: integer; 2825 end; 2826 2827 function TAI.ChooseGovernment: Integer; 2842 2828 begin 2843 2829 if Data.BehaviorFlags and bBarbarina <> 0 then … … 2856 2842 end; 2857 2843 2858 2859 2844 //------------------------------- 2860 2845 // DIPLOMACY 2861 2846 //------------------------------- 2862 2847 2863 function TAI.MostWanted(Nation, adGiveAway: integer): integer;2848 function TAI.MostWanted(Nation, adGiveAway: Integer): Integer; 2864 2849 var 2865 ad: integer;2850 ad: Integer; 2866 2851 begin 2867 2852 Result := -1; … … 2891 2876 end; 2892 2877 2893 procedure TAI.FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);2878 procedure TAI.FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer); 2894 2879 var 2895 i, ad, ead, adTestGiveAway: integer;2880 I, ad, ead, adTestGiveAway: Integer; 2896 2881 begin 2897 2882 adWanted := -1; … … 2903 2888 begin 2904 2889 adTestGiveAway := -1; 2905 for i:= 0 to nRequestedTechs - 1 do2906 if (Data.RequestedTechs[ i] >= 0) and2907 (Data.RequestedTechs[ i] and $FFFF = Nation shl 8 + ead) then2890 for I := 0 to nRequestedTechs - 1 do 2891 if (Data.RequestedTechs[I] >= 0) and 2892 (Data.RequestedTechs[I] and $FFFF = Nation shl 8 + ead) then 2908 2893 adTestGiveAway := -2; // already requested before 2909 2894 if adTestGiveAway = -1 then … … 2928 2913 end; 2929 2914 2930 2931 function TAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; 2915 function TAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; 2932 2916 var 2933 p1, Count, adWanted, adGiveAway: integer;2917 p1, Count, adWanted, adGiveAway: Integer; 2934 2918 begin 2935 2919 if Data.BehaviorFlags and bBarbarina = bBarbarina then 2936 2920 begin 2937 2921 Result := Barbarina_WantNegotiation(Nation, NegoTime); 2938 exit;2922 Exit; 2939 2923 end; 2940 2924 … … 2944 2928 begin 2945 2929 Result := False; 2946 exit;2930 Exit; 2947 2931 end; 2948 2932 Count := 0; 2949 2933 for p1 := 0 to nPl - 1 do 2950 if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then2934 if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then 2951 2935 Inc(Count); 2952 2936 if Count >= 3 then // enough peace made 2953 2937 begin 2954 2938 Result := False; 2955 exit;2939 Exit; 2956 2940 end; 2957 2941 end; … … 2994 2978 procedure TAI.DoNegotiation; 2995 2979 var 2996 i, adWanted, adGiveAway, adToGet, Slot: integer;2997 BuildFreeOffer: boolean;2980 I, adWanted, adGiveAway, adToGet, Slot: Integer; 2981 BuildFreeOffer: Boolean; 2998 2982 begin 2999 2983 if MyLastAction = scDipOffer then … … 3026 3010 begin 3027 3011 Barbarina_DoNegotiation; 3028 exit;3012 Exit; 3029 3013 end; 3030 3014 … … 3032 3016 begin 3033 3017 Barbarina_DoCheckNegotiation; 3034 exit;3018 Exit; 3035 3019 end; 3036 3020 … … 3047 3031 (OppoOffer.nDeliver + OppoOffer.nCost = 1) and 3048 3032 (OppoOffer.Price[0] and opMask = opTreaty) and 3049 ( integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and3033 (Integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and 3050 3034 ((OppoOffer.Price[0] - opTreaty < trAlliance) or 3051 3035 (RO.Tech[adScience] >= tsSeen)) then 3052 3036 MyAction := scDipAccept // accept all treaties 3053 3037 else if (RO.Treaty[Opponent] >= trPeace) and (OppoOffer.nDeliver = 1) and 3054 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + cardinal(Opponent) shl 16) and3038 (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + Cardinal(Opponent) shl 16) and 3055 3039 (OppoOffer.nCost = 1) and (OppoOffer.Price[1] and $FFFF0000 = 3056 opCivilReport + cardinal(me) shl 16) then3040 opCivilReport + Cardinal(Me) shl 16) then 3057 3041 MyAction := scDipAccept // accept exchange of civil reports 3058 3042 else if (OppoOffer.nDeliver = 1) and (OppoOffer.nCost = 1) and … … 3084 3068 adWanted := MostWanted(Opponent, OppoOffer.Price[1] - opTech); 3085 3069 if (OppoOffer.Price[0] and opMask = opTech) and 3086 ( cardinal(adWanted) = OppoOffer.Price[0] - opTech) then3070 (Cardinal(adWanted) = OppoOffer.Price[0] - opTech) then 3087 3071 MyAction := scDipAccept // opponent's offer is already perfect 3088 3072 else if adWanted >= 0 then … … 3140 3124 MyOffer.Price[1] := opTech + adWanted; 3141 3125 MyAction := scDipOffer; 3142 for i:= 0 to nRequestedTechs - 1 do3143 if Data.RequestedTechs[ i] < 0 then3126 for I := 0 to nRequestedTechs - 1 do 3127 if Data.RequestedTechs[I] < 0 then 3144 3128 begin 3145 Slot := i;3146 break;3129 Slot := I; 3130 Break; 3147 3131 end 3148 else if ( i = 0) or (Data.RequestedTechs[i] shr 16 <3132 else if (I = 0) or (Data.RequestedTechs[I] shr 16 < 3149 3133 Data.RequestedTechs[Slot] shr 16) then // find most outdated entry 3150 Slot := i;3134 Slot := I; 3151 3135 Data.RequestedTechs[Slot] := RO.Turn shl 16 + Opponent shl 8 + adWanted; 3152 3136 end; 3153 3137 end; 3154 3138 end; 3155 end; // Negotiation 3156 3139 end; 3157 3140 3158 3141 procedure SetLeaveOutValue; 3159 3142 3160 procedure Process(ad: integer);3143 procedure Process(ad: Integer); 3161 3144 var 3162 i: integer;3145 I: Integer; 3163 3146 begin 3164 3147 if LeaveOutValue[ad] < 0 then 3165 3148 begin 3166 3149 LeaveOutValue[ad] := 0; 3167 for i:= 0 to 1 do3168 if AdvPreq[ad, i] >= 0 then3169 begin 3170 Process(AdvPreq[ad, i]);3171 if AdvPreq[ad, i] in LeaveOutTechs then3172 Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, i]] + 1);3150 for I := 0 to 1 do 3151 if AdvPreq[ad, I] >= 0 then 3152 begin 3153 Process(AdvPreq[ad, I]); 3154 if AdvPreq[ad, I] in LeaveOutTechs then 3155 Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, I]] + 1); 3173 3156 end; 3174 3157 end; … … 3176 3159 3177 3160 var 3178 ad: integer;3161 ad: Integer; 3179 3162 begin 3180 3163 FillChar(LeaveOutValue, SizeOf(LeaveOutValue), $FF); … … 3185 3168 3186 3169 initialization 3187 RWDataSize := sizeof(TPersistentData);3170 RWDataSize := SizeOf(TPersistentData); 3188 3171 SetLeaveOutValue; 3189 3172 -
branches/highdpi/AI/StdAI/Barbarina.pas
r349 r465 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 … … 833 833 if Result then 834 834 Moved[uix] := True; 835 end; // ProcessMove835 end; 836 836 837 837 procedure TBarbarina.AttackAndPatrol; … … 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; 1207 end; // AttackAndPatrol1207 end; 1208 1208 1209 1209 procedure TBarbarina.Barbarina_SetCityProduction; … … 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; -
branches/highdpi/AI/StdAI/CustomAI.pas
r303 r465 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 -
branches/highdpi/AI/StdAI/CustomAI_Reload.pas
r210 r465 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 -
branches/highdpi/AI/StdAI/Pile.pas
r303 r465 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} -
branches/highdpi/AI/StdAI/Protocol.pas
r349 r465 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; -
branches/highdpi/AI/StdAI/StdAI.ai.txt
r124 r465 5 5 #PATH_WIN32 StdAI-win32.dll 6 6 #PATH_WIN64 StdAI-win64.dll 7 #PATH_LINUX32 libstdai-i386.so 8 #PATH_LINUX64 libstdai-amd64.so 7 #PATH_LINUX_I386 libstdai-i386.so 8 #PATH_LINUX_AMD64 libstdai-amd64.so 9 #PATH_LINUX_ARM32 libstdai-arm32.so 10 #PATH_LINUX_ARM64 libstdai-arm64.so 9 11 #CREDITS Standard AI by Steffen Gerlach. -
branches/highdpi/AI/StdAI/StdAI.lpr
r303 r465 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: -
branches/highdpi/AI/StdAI/ToolAI.pas
r349 r465 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; 106 end; 107 105 function CurrentMStrength(Domain: Integer): Integer; 106 end; 108 107 109 108 const … … 132 131 mxAdjacent = $00000001; 133 132 134 135 var 136 nContinent, nOcean, nDistrict: integer; 137 Formation: array[0..lxmax * lymax - 1] of integer; 133 var 134 nContinent, nOcean, nDistrict: Integer; 135 Formation: array[0..lxmax * lymax - 1] of Integer; 138 136 // water: ocean index, land: continent index, sorted by size 139 137 // territory unpassable due to peace treaty divides a continent 140 District: array[0..lxmax * lymax - 1] of integer;138 District: array[0..lxmax * lymax - 1] of Integer; 141 139 // index of coherent own territory, sorted by size 142 CityResult: array[0..nCmax - 1] of integer;143 144 Advancedness: array[0..nAdv - 1] of integer;140 CityResult: array[0..nCmax - 1] of Integer; 141 142 Advancedness: array[0..nAdv - 1] of Integer; 145 143 // total number of prerequisites for each advance 146 147 144 148 145 implementation … … 152 149 153 150 type 154 pinteger = ^ integer;151 pinteger = ^Integer; 155 152 156 153 var 157 154 // for JobAssignment 158 MaxScore: integer;159 TileJob, TileJobScore: array[0..lxmax * lymax - 1] of byte;160 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 161 158 162 159 // for Transport 163 TransportMoveStyle, TransportCapacity, nTransportLoad: integer; 164 InitComplete, HaveDestinations: boolean; 165 uixTransportLoad, TransportAvailable: array[0..nUmax - 1] of integer; 166 TurnsAfterLoad: array[0..lxmax * lymax - 1] of shortint; 167 168 169 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); 170 166 begin 171 167 while Start <> Stop do … … 177 173 end; 178 174 179 function NextZero(Start, Stop: pinteger; Mask: cardinal): pinteger;175 function NextZero(Start, Stop: pinteger; Mask: Cardinal): pinteger; 180 176 begin 181 177 while (Start <> Stop) and (Start^ and Mask <> 0) do … … 184 180 end; 185 181 186 187 function TToolAI.CenterOfEmpire: integer; 188 var 189 cix, Loc, x, y, sy, n: integer; 190 a, su, sv: double; 191 begin 192 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; 193 188 sy := 0; 194 189 su := 0; … … 199 194 if Loc >= 0 then 200 195 begin 201 y:= Loc div G.lx;202 x := Loc - y* G.lx;203 Inc(sy, y);204 a := 2 * pi * x/ G.lx;205 su := su + cos( a);206 sv := sv + sin( a);207 Inc( n);208 end; 209 end; 210 a:= arctan2(sv, su);211 x := round(G.lx * a/ (2 * pi));212 while x>= G.lx do213 Dec( x, G.lx);214 while x< 0 do215 Inc( x, G.lx);216 Result := ((2 * sy + n) div (2 * n)) * G.lx + x;217 end; 218 219 function TToolAI.CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;220 var 221 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; 222 217 begin 223 218 Result := 0; … … 234 229 Inc(Result, CityReport.FoodRep - CityReport.Eaten); 235 230 end; 236 for i:= nWonder to nImp - 1 do237 if MyCity[cix].Built[ i] > 0 then238 Dec(Result, Imp[ i].Maint);239 end; 240 241 procedure TToolAI.SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);242 var 243 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; 244 239 CityReport: TCityReport; 245 240 begin … … 247 242 ScienceSum := 0; 248 243 if RO.Government = gAnarchy then 249 exit;244 Exit; 250 245 for p1 := 0 to nPl - 1 do 251 246 if RO.Tribute[p1] <= RO.TributePaid[p1] then … … 263 258 end; 264 259 265 266 260 //------------------------------------------------------------------------------ 267 261 // City Tiles Processing … … 274 268 procedure TToolAI.OptimizeCityTiles; 275 269 var 276 cix: integer;270 cix: Integer; 277 271 begin 278 272 for cix := 0 to RO.nCity - 1 do … … 284 278 procedure TToolAI.GetCityProdPotential; 285 279 var 286 cix: integer;280 cix: Integer; 287 281 Advice: TCityTileAdviceData; 288 282 begin … … 292 286 begin 293 287 Advice.ResourceWeights := rwMaxProd; 294 Server(sGetCityTileAdvice, me, cix, Advice);288 Server(sGetCityTileAdvice, Me, cix, Advice); 295 289 CityResult[cix] := Advice.CityReport.ProdRep; // considers factory, but shouldn't 296 290 end; … … 299 293 procedure TToolAI.GetCityTradePotential; 300 294 var 301 cix: integer;295 cix: Integer; 302 296 Advice: TCityTileAdviceData; 303 297 begin … … 307 301 begin 308 302 Advice.ResourceWeights := rwMaxScience; 309 Server(sGetCityTileAdvice, me, cix, Advice);303 Server(sGetCityTileAdvice, Me, cix, Advice); 310 304 CityResult[cix] := Advice.CityReport.Trade; 311 305 end; 312 306 end; 313 314 307 315 308 //------------------------------------------------------------------------------ … … 321 314 procedure TToolAI.JobAssignment_Initialize; 322 315 begin 323 fillchar(JobLocOfSettler, RO.nUn * sizeof(integer), $FF); // -1324 fillchar(TileJob, MapSize, jNone);325 fillchar(TileJobScore, MapSize, 0);316 FillChar(JobLocOfSettler, RO.nUn * SizeOf(Integer), $FF); // -1 317 FillChar(TileJob, MapSize, jNone); 318 FillChar(TileJobScore, MapSize, 0); 326 319 MaxScore := 0; 327 320 end; 328 321 329 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: integer);322 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: Integer); 330 323 begin 331 324 if Score > 255 then … … 340 333 end; 341 334 342 procedure TToolAI.JobAssignment_AddUnit(uix: integer);343 begin 344 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]); 345 338 JobLocOfSettler[uix] := ToAssign; 346 339 end; 347 340 348 function TToolAI.JobAssignment_GotJob(uix: integer): boolean;341 function TToolAI.JobAssignment_GotJob(uix: Integer): Boolean; 349 342 begin 350 343 Result := JobLocOfSettler[uix] >= 0; … … 354 347 const 355 348 DistanceScore = 4; 356 StepSizeByTerrain: array[0..11] of integer =349 StepSizeByTerrain: array[0..11] of Integer = 357 350 (0, 0, 1, 2, 1, 1, 0, 1, 0, 1, 1, 2); 358 351 //Oc-Sh-Gr-De-Pr-Tu-Ar-Sw-XX-Fo-Hi-Mo 359 352 var 360 353 uix, BestScore, BestCount, BestLoc, BestJob, BestDistance, TestLoc, 361 NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: integer;362 UnitsToAssign: boolean;354 NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: Integer; 355 UnitsToAssign: Boolean; 363 356 Adjacent: TVicinity8Loc; 364 357 SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of smallint; 365 358 // DistToLoc is only defined where SettlerOfJobLoc>=0 366 TileChecked: array[0..lxmax * lymax - 1] of boolean;367 begin 368 fillchar(SettlerOfJobLoc, MapSize * 2, $FF); // -1359 TileChecked: array[0..lxmax * lymax - 1] of Boolean; 360 begin 361 FillChar(SettlerOfJobLoc, MapSize * 2, $FF); // -1 369 362 370 363 // keep up jobs that are already started … … 387 380 BestJob := jNone; 388 381 BestScore := -999999; 389 FillChar(TileChecked, MapSize * sizeof(boolean), False);382 FillChar(TileChecked, MapSize * SizeOf(Boolean), False); 390 383 Pile.Create(MapSize); 391 384 Pile.Put(MyUnit[uix].Loc, 0); // start search for new job at current location … … 406 399 and (Map[NextLoc] and (fUnit or fOwned) <> fUnit) // no foreign unit 407 400 and ((RO.Territory[NextLoc] < 0) or 408 (RO.Territory[NextLoc] = me)) // no foreign territory401 (RO.Territory[NextLoc] = Me)) // no foreign territory 409 402 and (Map[TestLoc] and Map[NextLoc] and fInEnemyZoC = 0) then 410 403 // move not prevented by ZoC … … 421 414 ((SettlerOfJobLoc[TestLoc] < 0) or (DistToLoc[TestLoc] > TestDistance)) then 422 415 begin 423 TestScore := integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;416 TestScore := Integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance; 424 417 if TestScore > BestScore then 425 418 BestCount := 0; … … 469 462 Unit_StartJob(uix, TileJob[JobLocOfSettler[uix]]); 470 463 end; 471 end; // JobAssignment_Go 472 464 end; 473 465 474 466 //------------------------------------------------------------------------------ … … 477 469 procedure TToolAI.AnalyzeMap; 478 470 var 479 i, j, Loc, Loc1, V8, Count, Kind, MostIndex: integer;471 I, J, Loc, Loc1, V8, Count, Kind, MostIndex: Integer; 480 472 Adjacent: TVicinity8Loc; 481 473 IndexOfID: array[0..lxmax * lymax - 1] of smallint; 482 474 IDOfIndex: array[0..lxmax * lymax div 2 - 1] of smallint; 483 475 begin 484 fillchar(District, MapSize * 4, $FF);476 FillChar(District, MapSize * 4, $FF); 485 477 for Loc := 0 to MapSize - 1 do 486 478 if Map[Loc] and fTerrain = fUNKNOWN then … … 508 500 Formation[Loc], Formation[Loc1]); 509 501 end; 510 if (RO.Territory[Loc] = me) and (Map[Loc] and fTerrain >= fGrass) then502 if (RO.Territory[Loc] = Me) and (Map[Loc] and fTerrain >= fGrass) then 511 503 begin 512 504 District[Loc] := Loc; … … 553 545 Inc(Count); 554 546 end; 555 for i:= 0 to Count - 2 do556 begin 557 MostIndex := i;558 for j := i+ 1 to Count - 1 do559 if IndexOfID[IDOfIndex[ j]] > IndexOfID[IDOfIndex[MostIndex]] then560 MostIndex := j;561 if MostIndex <> ithen562 begin 563 j := IDOfIndex[i];564 IDOfIndex[ i] := IDOfIndex[MostIndex];565 IDOfIndex[MostIndex] := j;566 end; 567 end; 568 for i:= 0 to Count - 1 do569 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; 570 562 571 563 case Kind of … … 594 586 end; 595 587 end; 596 597 588 598 589 //------------------------------------------------------------------------------ … … 614 605 // other: | Basic | 0| Speed | X X X | MaxTerrType | 615 606 616 function TToolAI.GetMyMoveStyle(mix, Health: integer): integer;607 function TToolAI.GetMyMoveStyle(mix, Health: Integer): Integer; 617 608 begin 618 609 with MyModel[mix] do … … 623 614 begin 624 615 Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); //HeavyCost 625 if RO.Wonder[woShinkansen].EffectiveOwner <> me then616 if RO.Wonder[woShinkansen].EffectiveOwner <> Me then 626 617 Inc(Result, Speed * (4 * 1311) shr 17); // RailCost 627 if (RO.Wonder[woGardens].EffectiveOwner <> me) or618 if (RO.Wonder[woGardens].EffectiveOwner <> Me) or 628 619 (Kind = mkSettler) and (Speed >= 200) then 629 620 Inc(Result, msHostile); … … 640 631 begin 641 632 Result := Speed; 642 if RO.Wonder[woMagellan].EffectiveOwner = me then633 if RO.Wonder[woMagellan].EffectiveOwner = Me then 643 634 Inc(Result, 200); 644 635 if Health < 100 then … … 655 646 end; 656 647 657 function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;658 var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;659 IsCapture: boolean): integer;660 var 661 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; 662 653 begin 663 654 //IsCapture:=true; 664 assert(((FromTile and fTerrain <= fMountains) or (FromTile and655 Assert(((FromTile and fTerrain <= fMountains) or (FromTile and 665 656 fTerrain = fUNKNOWN)) and ((ToTile and fTerrain <= fMountains) or 666 657 (ToTile and fTerrain = fUNKNOWN))); … … 710 701 if ToTile and fPeace <> 0 then 711 702 Result := csCheckTerritory; 712 exit;703 Exit; 713 704 end; 714 705 end; … … 829 820 begin 830 821 Result := csForbiddenTile; 831 exit;822 Exit; 832 823 end; 833 824 end … … 878 869 // must wait for next turn 879 870 Result := csOk; 880 exit;871 Exit; 881 872 end; 882 873 end; … … 898 889 Result := csForbiddenTile; 899 890 end; 900 end; // CheckStep891 end; 901 892 902 893 (* 903 894 -------- Pathfinding Reference Implementation -------- 904 895 var 905 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: integer;896 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: Integer; 906 897 Adjacent: TVicinity8Loc; 907 Reached: array[0..lxmax*lymax-1] of boolean;908 begin 909 fillchar(Reached, MapSize, false);898 Reached: array[0..lxmax*lymax-1] of Boolean; 899 begin 900 FillChar(Reached, MapSize, False); 910 901 MoveStyle:=GetMyMoveStyle(MyUnit[uix].mix, MyUnit[uix].Health); 911 902 Pile.Create(MapSize); … … 915 906 // todo: check exit condition, e.g. whether destination reached 916 907 917 Reached[Loc]:= true;908 Reached[Loc]:=True; 918 909 V8_to_Loc(Loc, Adjacent); 919 910 for V8:=0 to 7 do … … 925 916 Pile.Put(NextLoc, NextTime+RecoverTurns*$1000); 926 917 csForbiddenTile: 927 Reached[NextLoc]:= true; // don't check moving there again918 Reached[NextLoc]:=True; // don't check moving there again 928 919 csCheckTerritory: 929 920 if RO.Territory[NextLoc]=RO.Territory[Loc] then … … 936 927 *) 937 928 938 function TToolAI.Unit_MoveEx(uix, ToLoc: integer; Options: integer): integer;929 function TToolAI.Unit_MoveEx(uix, ToLoc: Integer; Options: Integer): Integer; 939 930 var 940 931 Loc, NextLoc, Temp, FromLoc, EndLoc, Time, V8, MoveResult, RecoverTurns, 941 NextTime, MoveStyle: integer;932 NextTime, MoveStyle: Integer; 942 933 Adjacent: TVicinity8Loc; 943 PreLoc: array[0..lxmax * lymax - 1] of integer;944 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; 945 936 begin 946 937 Result := eOk; 947 938 FromLoc := MyUnit[uix].Loc; 948 939 if FromLoc = ToLoc then 949 exit;940 Exit; 950 941 951 942 FillChar(Reached, MapSize, False); … … 1012 1003 begin 1013 1004 Result := MoveResult; 1014 break;1005 Break; 1015 1006 end; 1016 1007 end; … … 1020 1011 end; 1021 1012 1022 1023 1013 //------------------------------------------------------------------------------ 1024 1014 // Oversea Transport … … 1026 1016 procedure TToolAI.SeaTransport_BeginInitialize; 1027 1017 begin 1028 fillchar(TransportAvailable, RO.nUn * sizeof(integer), $FF); // -11018 FillChar(TransportAvailable, RO.nUn * SizeOf(Integer), $FF); // -1 1029 1019 InitComplete := False; 1030 1020 HaveDestinations := False; … … 1035 1025 end; 1036 1026 1037 procedure TToolAI.SeaTransport_AddLoad(uix: integer);1038 var 1039 i: integer;1040 begin 1041 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! 1042 1032 if Map[MyUnit[uix].Loc] and fTerrain < fGrass then 1043 exit;1044 for i:= 0 to nTransportLoad - 1 do1045 if uix = uixTransportLoad[ i] then1046 exit;1033 Exit; 1034 for I := 0 to nTransportLoad - 1 do 1035 if uix = uixTransportLoad[I] then 1036 Exit; 1047 1037 uixTransportLoad[nTransportLoad] := uix; 1048 1038 Inc(nTransportLoad); 1049 1039 end; 1050 1040 1051 procedure TToolAI.SeaTransport_AddTransport(uix: integer);1052 var 1053 MoveStyle: integer;1054 begin 1055 assert(not InitComplete); // call order violation!1056 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); 1057 1047 TransportAvailable[uix] := 1; 1058 1048 with MyModel[MyUnit[uix].mix] do … … 1068 1058 end; 1069 1059 1070 procedure TToolAI.SeaTransport_AddDestination(Loc: integer);1071 begin 1072 assert(not InitComplete); // call order violation!1060 procedure TToolAI.SeaTransport_AddDestination(Loc: Integer); 1061 begin 1062 Assert(not InitComplete); // call order violation! 1073 1063 Pile.Put(Loc, $800); 1074 1064 HaveDestinations := True; … … 1077 1067 procedure TToolAI.SeaTransport_EndInitialize; 1078 1068 var 1079 Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: integer;1069 Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: Integer; 1080 1070 Adjacent: TVicinity8Loc; 1081 1071 begin 1082 assert(not InitComplete); // call order violation!1072 Assert(not InitComplete); // call order violation! 1083 1073 InitComplete := True; 1084 1074 if HaveDestinations then 1085 1075 begin // calculate TurnsAfterLoad from destination locs 1086 fillchar(TurnsAfterLoad, MapSize, $FF); // -11076 FillChar(TurnsAfterLoad, MapSize, $FF); // -1 1087 1077 while Pile.Get(Loc0, Time0) do 1088 1078 begin // search backward … … 1109 1099 end; 1110 1100 1111 1112 1101 function TToolAI.SeaTransport_MakeGroupPlan( 1113 var TransportPlan: TGroupTransportPlan): boolean;1114 var 1115 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, 1116 1105 TurnsLoaded, TurnCount, tuix, tuix1, ArriveTime, TotalDelay, 1117 1106 BestTotalDelay, GroupCount, BestGroupCount, BestLoadLoc, FullMovementLoc, 1118 nSelectedLoad, f, OriginContinent, a, b: integer;1119 CompleteFlag, NotReachedFlag, ContinueUnit: cardinal;1120 IsComplete, ok, IsFirstLoc: boolean;1107 nSelectedLoad, F, OriginContinent, A, B: Integer; 1108 CompleteFlag, NotReachedFlag, ContinueUnit: Cardinal; 1109 IsComplete, ok, IsFirstLoc: Boolean; 1121 1110 StartLocPtr, ArrivedEnd: pinteger; 1122 1111 Adjacent: TVicinity8Loc; 1123 uixSelectedLoad: array[0..15] of integer;1124 tuixSelectedLoad: array[0..15] of integer;1125 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; 1126 1115 ResponsibleTransport: array[0..lxmax * lymax - 1] of smallint; 1127 TurnsBeforeLoad: array[0..lxmax * lymax - 1] of shortint;1128 GroupComplete: array[0..lxmax * lymax - 1] of boolean;1129 begin 1130 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! 1131 1120 1132 1121 if HaveDestinations and (nTransportLoad > 0) then … … 1139 1128 for tuix := 0 to nTransportLoad - 1 do 1140 1129 begin 1141 Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);1142 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 1143 1132 begin 1144 assert((a <> 0) or (b<> 0));1133 Assert((A <> 0) or (B <> 0)); 1145 1134 Inc(GroupCount); 1146 1135 end; … … 1156 1145 for tuix := nTransportLoad - 1 downto 0 do 1157 1146 begin 1158 Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);1159 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 1160 1149 begin 1161 1150 TransportPlan.uixLoad[TransportPlan.nLoad] := uixTransportLoad[tuix]; … … 1164 1153 Inc(TransportPlan.nLoad); 1165 1154 if TransportPlan.nLoad = TransportCapacity then 1166 break;1155 Break; 1167 1156 end; 1168 1157 end; 1169 1158 Result := True; 1170 exit;1159 Exit; 1171 1160 end; 1172 1161 end; … … 1176 1165 begin 1177 1166 // select units from same continent 1178 fillchar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter1167 FillChar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter 1179 1168 for tuix := 0 to nTransportLoad - 1 do 1180 1169 begin 1181 assert(Map[MyUnit[uixTransportLoad[tuix]].Loc] and fTerrain >= fGrass);1182 f:= Formation[MyUnit[uixTransportLoad[tuix]].Loc];1183 if f>= 0 then1184 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]); 1185 1174 end; 1186 1175 OriginContinent := 0; 1187 for f:= 1 to nContinent - 1 do1188 if Arrived[ f] > Arrived[OriginContinent] then1189 OriginContinent := f;1176 for F := 1 to nContinent - 1 do 1177 if Arrived[F] > Arrived[OriginContinent] then 1178 OriginContinent := F; 1190 1179 nSelectedLoad := 0; 1191 1180 for tuix := 0 to nTransportLoad - 1 do … … 1196 1185 Inc(nSelectedLoad); 1197 1186 if nSelectedLoad = 16 then 1198 break;1187 Break; 1199 1188 end; 1200 1189 1201 1190 Pile.Create(MapSize); 1202 fillchar(ResponsibleTransport, MapSize * 2, $FF); // -11203 fillchar(TurnsBeforeLoad, MapSize, $FF); // -11191 FillChar(ResponsibleTransport, MapSize * 2, $FF); // -1 1192 FillChar(TurnsBeforeLoad, MapSize, $FF); // -1 1204 1193 ok := False; 1205 1194 for uix := 0 to RO.nUn - 1 do … … 1214 1203 Result := False; 1215 1204 Pile.Free; 1216 exit;1205 Exit; 1217 1206 end; 1218 1207 while Pile.Get(Loc0, Time0) do … … 1235 1224 end; 1236 1225 1237 fillchar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles1238 fillchar(GroupComplete, MapSize, False);1226 FillChar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles 1227 FillChar(GroupComplete, MapSize, False); 1239 1228 BestLoadLoc := -1; 1240 1229 … … 1243 1232 begin 1244 1233 uix := uixSelectedLoad[tuix]; 1245 if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then1234 if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then 1246 1235 begin 1247 1236 NotReachedFlag := 1 shl (2 * tuix); … … 1257 1246 if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then 1258 1247 begin 1259 i:= 1;1248 I := 1; 1260 1249 GroupCount := 0; 1261 1250 for tuix1 := 0 to nSelectedLoad - 1 do 1262 1251 begin 1263 if Arrived[loc1] and i= 0 then1252 if Arrived[loc1] and I = 0 then 1264 1253 Inc(GroupCount); 1265 i := ishl 2;1254 I := I shl 2; 1266 1255 end; 1267 assert(GroupCount <= TransportCapacity);1256 Assert(GroupCount <= TransportCapacity); 1268 1257 if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then 1269 1258 GroupComplete[loc1] := True; … … 1303 1292 begin 1304 1293 Pile.Put(MyUnit[uix].Loc, $1800 - MyUnit[uix].Movement); 1305 if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then1294 if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then 1306 1295 FullMovementLoc := MyUnit[uix].Loc; 1307 1296 // surrounding tiles can be loaded immediately … … 1319 1308 if StartLocPtr <> ArrivedEnd then 1320 1309 begin 1321 Loc0 := ( integer(StartLocPtr) - integer(@Arrived)) shr 2;1310 Loc0 := (Integer(StartLocPtr) - Integer(@Arrived)) shr 2; 1322 1311 Inc(StartLocPtr); 1323 1312 Time0 := $800; … … 1327 1316 if IsFirstLoc then 1328 1317 ContinueUnit := ContinueUnit and not (1 shl tuix); 1329 break;1318 Break; 1330 1319 end; 1331 1320 IsFirstLoc := False; … … 1334 1323 if not GroupComplete[Loc0] and (Map[Loc0] and fTerrain <> fMountains) then 1335 1324 begin // check whether group complete -- no mountains because complete flag might be faked there 1336 i:= 1;1325 I := 1; 1337 1326 GroupCount := 0; 1338 1327 for tuix1 := 0 to nSelectedLoad - 1 do 1339 1328 begin 1340 if Arrived[Loc0] and i= 0 then1329 if Arrived[Loc0] and I = 0 then 1341 1330 Inc(GroupCount); 1342 i := ishl 2;1331 I := I shl 2; 1343 1332 end; 1344 assert(GroupCount <= TransportCapacity);1333 Assert(GroupCount <= TransportCapacity); 1345 1334 if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then 1346 1335 GroupComplete[Loc0] := True; … … 1364 1353 if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then 1365 1354 begin 1366 i:= 1;1355 I := 1; 1367 1356 GroupCount := 0; 1368 1357 for tuix1 := 0 to nSelectedLoad - 1 do 1369 1358 begin 1370 if Arrived[loc1] and i= 0 then1359 if Arrived[loc1] and I = 0 then 1371 1360 Inc(GroupCount); 1372 i := ishl 2;1361 I := I shl 2; 1373 1362 end; 1374 assert(GroupCount <= TransportCapacity);1363 Assert(GroupCount <= TransportCapacity); 1375 1364 if (GroupCount = TransportCapacity) or 1376 1365 (GroupCount = nSelectedLoad) then … … 1447 1436 if 1 shl (2 * tuix) and Arrived[BestLoadLoc] = 0 then 1448 1437 begin 1449 assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);1438 Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]); 1450 1439 TransportPlan.uixLoad[TransportPlan.nLoad] := uixSelectedLoad[tuix]; 1451 1440 uixTransportLoad[tuixSelectedLoad[tuix]] := … … 1455 1444 end; 1456 1445 Result := True; 1457 exit;1446 Exit; 1458 1447 end; 1459 1448 … … 1462 1451 for tuix := nSelectedLoad - 1 downto 0 do 1463 1452 begin 1464 assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);1453 Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]); 1465 1454 uixTransportLoad[tuixSelectedLoad[tuix]] := 1466 1455 uixTransportLoad[nTransportLoad - 1]; … … 1472 1461 end; 1473 1462 1474 1475 1463 //------------------------------------------------------------------------------ 1476 1464 // Misc 1477 1465 1478 function TToolAI.CurrentMStrength(Domain: integer): integer;1479 var 1480 i: integer;1466 function TToolAI.CurrentMStrength(Domain: Integer): Integer; 1467 var 1468 I: Integer; 1481 1469 begin 1482 1470 Result := 0; 1483 for i:= 0 to nUpgrade - 1 do1484 with upgrade[Domain, i] do1471 for I := 0 to nUpgrade - 1 do 1472 with upgrade[Domain, I] do 1485 1473 if (Preq = preNone) or (Preq >= 0) and 1486 1474 ((RO.Tech[Preq] >= tsApplicable) or (Preq in FutureTech) and … … 1494 1482 end; 1495 1483 1496 1497 1484 //------------------------------------------------------------------------------ 1498 1485 1499 1486 procedure SetAdvancedness; 1500 1487 var 1501 ad, j, Reduction, AgeThreshold: integer;1502 known: array[0..nAdv - 1] of integer;1503 1504 procedure MarkPreqs(ad: integer);1488 ad, J, Reduction, AgeThreshold: Integer; 1489 known: array[0..nAdv - 1] of Integer; 1490 1491 procedure MarkPreqs(ad: Integer); 1505 1492 var 1506 i: integer;1493 I: Integer; 1507 1494 begin 1508 1495 if known[ad] = 0 then 1509 1496 begin 1510 1497 known[ad] := 1; 1511 for i:= 0 to 2 do1512 if AdvPreq[ad, i] >= 0 then1513 MarkPreqs(AdvPreq[ad, i]);1498 for I := 0 to 2 do 1499 if AdvPreq[ad, I] >= 0 then 1500 MarkPreqs(AdvPreq[ad, I]); 1514 1501 end; 1515 1502 end; … … 1521 1508 FillChar(known, SizeOf(known), 0); 1522 1509 MarkPreqs(ad); 1523 for j:= 0 to nAdv - 1 do1524 if known[ j] > 0 then1510 for J := 0 to nAdv - 1 do 1511 if known[J] > 0 then 1525 1512 Inc(Advancedness[ad]); 1526 1513 end; -
branches/highdpi/Back.lfm
r246 r465 8 8 Caption = 'C-evo' 9 9 Color = clBlack 10 DesignTimePPI = 144 10 11 Font.Color = clWindowText 11 Font.Height = - 1312 Font.Height = -30 12 13 Font.Name = 'MS Sans Serif' 13 14 OnClose = FormClose … … 16 17 OnPaint = FormPaint 17 18 OnShow = FormShow 18 LCLVersion = '1.6.2.0' 19 WindowState = wsMaximized 20 PixelsPerInch = 96 19 ShowInTaskBar = stNever 20 LCLVersion = '2.2.0.4' 21 21 Scaled = False 22 WindowState = wsFullScreen 22 23 end -
branches/highdpi/Back.pas
r349 r465 51 51 begin 52 52 if Assigned(Img) then 53 DpiBit Canvas(Canvas, DpiScreen.Width - Img.Width - (DpiScreen.Width - 800) *53 DpiBitBltCanvas(Canvas, DpiScreen.Width - Img.Width - (DpiScreen.Width - 800) * 54 54 3 div 8, (DpiScreen.Height - 600) div 3, Img.Width, Img.Height, 55 55 Img.Canvas, 0, 0); … … 70 70 if FileExists(FileName) then begin 71 71 Img := TDpiBitmap.Create; 72 LoadGraphicFile(img, FileName); 72 LoadGraphicFile(Img, FileName); 73 Repaint; 73 74 end; 74 75 end; -
branches/highdpi/Brain.pas
r464 r465 1 unit UBrain; 2 3 {$mode delphi} 1 unit Brain; 4 2 5 3 interface 6 4 7 5 uses 8 UDpiControls, Classes, SysUtils, fgl, Graphics, Protocol, LazFileUtils, dynlibs; 6 UDpiControls, Classes, SysUtils, Generics.Collections, Graphics, Protocol, LazFileUtils, 7 dynlibs, Types; 9 8 10 9 const … … 35 34 Picture: TDpiBitmap; 36 35 Beginner: Boolean; 36 procedure LoadPicture; 37 37 procedure LoadFromFile(AIFileName: string); 38 38 constructor Create; … … 42 42 { TBrains } 43 43 44 TBrains = class(T FPGObjectList<TBrain>)44 TBrains = class(TObjectList<TBrain>) 45 45 function AddNew: TBrain; 46 46 function GetKindCount(Kind: TBrainType): Integer; 47 47 procedure GetByKind(Kind: TBrainType; Brains: TBrains); 48 48 function GetBeginner: TBrain; 49 procedure LoadPictures; 49 50 end; 50 51 … … 53 54 54 55 uses 55 ScreenTools ;56 ScreenTools, Directories; 56 57 57 58 { TBrain } 59 60 procedure TBrain.LoadPicture; 61 var 62 TextSize: TSize; 63 begin 64 if not LoadGraphicFile(Picture, GetAiDir + DirectorySeparator + 65 FileName + DirectorySeparator + FileName + '.png', [gfNoError]) then begin 66 with Picture.Canvas do begin 67 Brush.Color := $904830; 68 FillRect(Rect(0, 0, 64, 64)); 69 Font.Assign(UniFont[ftTiny]); 70 Font.Style := []; 71 Font.Color := $5FDBFF; 72 TextSize := TextExtent(FileName); 73 TextOut(32 - TextSize.Width div 2, 32 - TextSize.Height div 2, FileName); 74 end; 75 end; 76 end; 58 77 59 78 procedure TBrain.LoadFromFile(AIFileName: string); … … 106 125 DLLName := BasePath + DirectorySeparator + Value 107 126 {$ENDIF}{$ENDIF} 108 {$IFDEF LINUX}{$IFDEF CPU32} 109 else if Key = '#PATH_LINUX32' then 110 DLLName := BasePath + DirectorySeparator + Value 111 {$ENDIF}{$ENDIF} 112 {$IFDEF LINUX}{$IFDEF CPU64} 113 else if Key = '#PATH_LINUX64' then 127 {$IFDEF UNIX}{$IFDEF CPUI386} 128 else if Key = '#PATH_LINUX_I386' then 129 DLLName := BasePath + DirectorySeparator + Value 130 {$ENDIF}{$ENDIF} 131 {$IFDEF UNIX}{$IFDEF CPUAMD64} 132 else if Key = '#PATH_LINUX_AMD64' then 133 DLLName := BasePath + DirectorySeparator + Value 134 {$ENDIF}{$ENDIF} 135 {$IFDEF UNIX}{$IFDEF CPUARM} 136 else if Key = '#PATH_LINUX_ARM32' then 137 DLLName := BasePath + DirectorySeparator + Value 138 {$ENDIF}{$ENDIF} 139 {$IFDEF UNIX}{$IFDEF CPUAARCH64} 140 else if Key = '#PATH_LINUX_ARM64' then 114 141 DLLName := BasePath + DirectorySeparator + Value 115 142 {$ENDIF}{$ENDIF} … … 177 204 end; 178 205 206 procedure TBrains.LoadPictures; 207 var 208 I: Integer; 209 begin 210 for I := 0 to Count - 1 do 211 with Items[I] do LoadPicture; 212 end; 213 179 214 end. 180 215 216 217 -
branches/highdpi/CityProcessing.pas
r349 r465 8 8 9 9 // Reporting 10 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);11 function CanCityGrow( p, cix: integer): boolean;12 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;13 function GetCityReportNew( p, cix: integer;14 var CityReportNew: TCityReportNew): integer;10 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 11 function CanCityGrow(P, cix: Integer): Boolean; 12 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 13 function GetCityReportNew(P, cix: Integer; 14 var CityReportNew: TCityReportNew): Integer; 15 15 16 16 // Internal Tile Picking 17 function AddBestCityTile( p, cix: integer): boolean;18 procedure CityGrowth( p, cix: integer);19 procedure CityShrink( p, cix: integer);20 procedure Pollute( p, cix: integer);17 function AddBestCityTile(P, cix: Integer): Boolean; 18 procedure CityGrowth(P, cix: Integer); 19 procedure CityShrink(P, cix: Integer); 20 procedure Pollute(P, cix: Integer); 21 21 22 22 // Turn Processing 23 procedure PayCityMaintenance( p, cix: integer);24 procedure CollectCityResources( p, cix: integer);25 function CityTurn( p, cix: integer): boolean;23 procedure PayCityMaintenance(P, cix: Integer); 24 procedure CollectCityResources(P, cix: Integer); 25 function CityTurn(P, cix: Integer): Boolean; 26 26 27 27 // Tile Access 28 function SetCityTiles( p, cix, NewTiles: integer;29 TestOnly: boolean = false): integer;30 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);28 function SetCityTiles(P, cix, NewTiles: Integer; 29 TestOnly: Boolean = False): Integer; 30 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 31 31 32 32 // Start/End Game … … 34 34 procedure ReleaseGame; 35 35 36 36 37 implementation 37 38 38 39 type 39 40 TTradeProcessing = record 40 TaxBonus, LuxBonus, ScienceBonus, FutResBonus, ScienceDoubling, 41 HappyBase: integer; 42 RelCorr: single; 43 FlexibleLuxury: boolean; 41 TaxBonus: Integer; 42 LuxBonus: Integer; 43 ScienceBonus: Integer; 44 FutResBonus: Integer; 45 ScienceDoubling: Integer; 46 HappyBase: Integer; 47 RelCorr: Single; 48 FlexibleLuxury: Boolean; 44 49 end; 45 50 46 51 TProdProcessing = record 47 ProdBonus, PollBonus, FutProdBonus, PollThreshold: integer; 52 ProdBonus: Integer; 53 PollBonus: Integer; 54 FutProdBonus: Integer; 55 PollThreshold: Integer; 48 56 end; 49 57 … … 51 59 52 60 TCityReportEx = record 53 BaseHappiness, BaseControl, Material: integer; 61 BaseHappiness: Integer; 62 BaseControl: Integer; 63 Material: Integer; 54 64 ProdProcessing: TProdProcessing; 55 65 TradeProcessing: TTradeProcessing; … … 57 67 58 68 var 59 MaxDist: integer;60 61 {62 Reporting63 ____________________________________________________________________64 }65 procedure GetCityAreaInfo( p, Loc: integer; var CityAreaInfo: TCityAreaInfo);66 var 67 V21, Loc1, p1: integer;69 MaxDist: Integer; 70 71 { 72 Reporting 73 ____________________________________________________________________ 74 } 75 procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo); 76 var 77 V21, Loc1, p1: Integer; 68 78 Radius: TVicinity21Loc; 69 79 begin 70 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}80 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 71 81 with CityAreaInfo do 72 82 begin … … 80 90 begin 81 91 p1 := RealMap[Loc1] shr 27; 82 if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then92 if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then 83 93 Available[V21] := faTreaty 84 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> p) and85 (RW[ p].Treaty[Occupant[Loc1]] < trAlliance) then94 else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> P) and 95 (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then 86 96 Available[V21] := faSiege 87 97 else if (UsedByCity[Loc1] <> -1) and (UsedByCity[Loc1] <> Loc) then 88 98 Available[V21] := faNotAvailable 89 99 else 90 Available[V21] := faAvailable 91 end 92 end; 93 end 94 end; 95 96 function CanCityGrow( p, cix: integer): boolean;97 begin 98 with RW[ p].City[cix] do99 result := (Size < MaxCitySize) and100 Available[V21] := faAvailable; 101 end; 102 end; 103 end; 104 end; 105 106 function CanCityGrow(P, cix: Integer): Boolean; 107 begin 108 with RW[P].City[cix] do 109 Result := (Size < MaxCitySize) and 100 110 ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and 101 111 (Size < NeedSewerSize) or (Built[imSewer] = 1)); 102 112 end; 103 113 104 procedure DetermineCityProdProcessing( p, cix: integer;114 procedure DetermineCityProdProcessing(P, cix: Integer; 105 115 var ProdProcessing: TProdProcessing); 106 116 begin 107 with RW[ p].City[cix], ProdProcessing do117 with RW[P].City[cix], ProdProcessing do 108 118 begin 109 119 ProdBonus := 0; 110 120 PollBonus := 0; 111 121 if Built[imFactory] = 1 then 112 inc(ProdBonus);122 Inc(ProdBonus); 113 123 if Built[imMfgPlant] = 1 then 114 inc(ProdBonus);124 Inc(ProdBonus); 115 125 if (Built[imPower] = 1) or (Built[imHydro] = 1) or (Built[imNuclear] = 1) or 116 (GWonder[woHoover].EffectiveOwner = p) then126 (GWonder[woHoover].EffectiveOwner = P) then 117 127 ProdBonus := ProdBonus * 2; 118 128 if Built[imFactory] = 1 then 119 inc(PollBonus);129 Inc(PollBonus); 120 130 if Built[imMfgPlant] = 1 then 121 inc(PollBonus);131 Inc(PollBonus); 122 132 if (Built[imFactory] + Built[imMfgPlant] > 0) then 123 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = p) then124 dec(PollBonus)133 if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = P) then 134 Dec(PollBonus) 125 135 else if (Built[imNuclear] = 0) and (Built[imPower] = 1) then 126 inc(PollBonus);127 if (RW[ p].Government <= gDespotism) or (Built[imRecycling] = 1) then136 Inc(PollBonus); 137 if (RW[P].Government <= gDespotism) or (Built[imRecycling] = 1) then 128 138 PollBonus := -2; // no pollution 129 139 PollThreshold := Size; 130 140 FutProdBonus := 0; 131 if RW[ p].Tech[futProductionTechnology] > 0 then141 if RW[P].Tech[futProductionTechnology] > 0 then 132 142 begin // future tech benefits 133 143 if Built[imFactory] = 1 then 134 inc(FutProdBonus, FactoryFutureBonus * RW[p].Tech144 Inc(FutProdBonus, FactoryFutureBonus * RW[P].Tech 135 145 [futProductionTechnology]); 136 146 if Built[imMfgPlant] = 1 then 137 inc(FutProdBonus, MfgPlantFutureBonus * RW[p].Tech147 Inc(FutProdBonus, MfgPlantFutureBonus * RW[P].Tech 138 148 [futProductionTechnology]); 139 149 end; … … 141 151 end; 142 152 143 procedure BoostProd(BaseProd: integer; ProdProcessing: TProdProcessing;144 var Prod, Poll: integer);153 procedure BoostProd(BaseProd: Integer; ProdProcessing: TProdProcessing; 154 var Prod, Poll: Integer); 145 155 begin 146 156 Poll := BaseProd * (2 + ProdProcessing.PollBonus) shr 1; … … 148 158 Poll := 0 149 159 else 150 dec(Poll, ProdProcessing.PollThreshold);160 Dec(Poll, ProdProcessing.PollThreshold); 151 161 if ProdProcessing.FutProdBonus > 0 then 152 162 Prod := BaseProd * (100 + ProdProcessing.ProdBonus * 50 + … … 156 166 end; 157 167 158 procedure DetermineCityTradeProcessing( p, cix, HappinessBeforeLux: integer;168 procedure DetermineCityTradeProcessing(P, cix, HappinessBeforeLux: Integer; 159 169 var TradeProcessing: TTradeProcessing); 160 170 var 161 i, Dist: integer;162 begin 163 with RW[ p].City[cix], TradeProcessing do171 I, Dist: Integer; 172 begin 173 with RW[P].City[cix], TradeProcessing do 164 174 begin 165 175 TaxBonus := 0; 166 176 ScienceBonus := 0; 167 177 if Built[imMarket] = 1 then 168 inc(TaxBonus, 2);178 Inc(TaxBonus, 2); 169 179 if Built[imBank] = 1 then 170 180 begin 171 inc(TaxBonus, 3);172 if RW[ p].NatBuilt[imStockEx] = 1 then173 inc(TaxBonus, 3);181 Inc(TaxBonus, 3); 182 if RW[P].NatBuilt[imStockEx] = 1 then 183 Inc(TaxBonus, 3); 174 184 end; 175 185 LuxBonus := TaxBonus; 176 186 if Built[imLibrary] = 1 then 177 inc(ScienceBonus, 2);187 Inc(ScienceBonus, 2); 178 188 if Built[imUniversity] = 1 then 179 inc(ScienceBonus, 3);189 Inc(ScienceBonus, 3); 180 190 if Built[imResLab] = 1 then 181 inc(ScienceBonus, 3);191 Inc(ScienceBonus, 3); 182 192 ScienceDoubling := 0; 183 193 if Built[imNatObs] > 0 then 184 inc(ScienceDoubling);185 if RW[ p].Government = gFundamentalism then186 dec(ScienceDoubling)187 else if (GWonder[woNewton].EffectiveOwner = p) and188 (RW[ p].Government = gMonarchy) then189 inc(ScienceDoubling);190 FlexibleLuxury := ((ServerVersion[ p] >= $0100F1) and191 (GWonder[woLiberty].EffectiveOwner = p) or (ServerVersion[p] < $0100F1)192 and (GWonder[woMich].EffectiveOwner = p)) and193 (RW[ p].Government <> gAnarchy);194 Inc(ScienceDoubling); 195 if RW[P].Government = gFundamentalism then 196 Dec(ScienceDoubling) 197 else if (GWonder[woNewton].EffectiveOwner = P) and 198 (RW[P].Government = gMonarchy) then 199 Inc(ScienceDoubling); 200 FlexibleLuxury := ((ServerVersion[P] >= $0100F1) and 201 (GWonder[woLiberty].EffectiveOwner = P) or (ServerVersion[P] < $0100F1) 202 and (GWonder[woMich].EffectiveOwner = P)) and 203 (RW[P].Government <> gAnarchy); 194 204 FutResBonus := 0; 195 if RW[ p].Tech[futResearchTechnology] > 0 then205 if RW[P].Tech[futResearchTechnology] > 0 then 196 206 begin // future tech benefits 197 207 if Built[imUniversity] = 1 then 198 inc(FutResBonus, UniversityFutureBonus * RW[p].Tech208 Inc(FutResBonus, UniversityFutureBonus * RW[P].Tech 199 209 [futResearchTechnology]); 200 210 if Built[imResLab] = 1 then 201 inc(FutResBonus, ResLabFutureBonus * RW[p].Tech[futResearchTechnology]);202 end; 203 if (RW[ p].NatBuilt[imPalace] > 0) or (ServerVersion[p] < $010000) then211 Inc(FutResBonus, ResLabFutureBonus * RW[P].Tech[futResearchTechnology]); 212 end; 213 if (RW[P].NatBuilt[imPalace] > 0) or (ServerVersion[P] < $010000) then 204 214 begin // calculate corruption 205 215 Dist := MaxDist; 206 for i := 0 to RW[p].nCity - 1 do207 if (RW[ p].City[i].Loc >= 0) and (RW[p].City[i].Built[imPalace] = 1) then208 Dist := Distance(Loc, RW[ p].City[i].Loc);209 if (Dist = 0) or (CorrLevel[RW[ p].Government] = 0) then216 for I := 0 to RW[P].nCity - 1 do 217 if (RW[P].City[I].Loc >= 0) and (RW[P].City[I].Built[imPalace] = 1) then 218 Dist := Distance(Loc, RW[P].City[I].Loc); 219 if (Dist = 0) or (CorrLevel[RW[P].Government] = 0) then 210 220 RelCorr := 0.0 211 221 else 212 222 begin 213 223 RelCorr := Dist / MaxDist; 214 if CorrLevel[RW[ p].Government] > 1 then215 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[ p].Government]);224 if CorrLevel[RW[P].Government] > 1 then 225 RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[P].Government]); 216 226 if Built[imCourt] = 1 then 217 227 RelCorr := RelCorr / 2; … … 224 234 RelCorr := 1.0; 225 235 HappyBase := Size + HappinessBeforeLux; 226 end 227 end; 228 229 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: integer;236 end; 237 end; 238 239 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: Integer; 230 240 TradeProcessing: TTradeProcessing; var Corruption, Tax, Lux, 231 Science: integer);232 var 233 plus: integer;241 Science: Integer); 242 var 243 plus: Integer; 234 244 begin 235 245 Corruption := Trunc(Trade * TradeProcessing.RelCorr); … … 266 276 end; 267 277 268 function GetProjectCost( p, cix: integer): integer;269 var 270 i: integer;271 begin 272 with RW[ p].City[cix] do278 function GetProjectCost(P, cix: Integer): Integer; 279 var 280 I: Integer; 281 begin 282 with RW[P].City[cix] do 273 283 begin 274 284 if Project and cpImp = 0 then 275 285 begin 276 result := RW[p].Model[Project and cpIndex].Cost; { unit project }286 Result := RW[P].Model[Project and cpIndex].Cost; { unit project } 277 287 if Project and cpConscripts <> 0 then 278 288 begin 279 i := RW[p].Model[Project and cpIndex].MCost;280 result := result - 3 * i;281 if result <= 0 then282 result := i289 I := RW[P].Model[Project and cpIndex].MCost; 290 Result := Result - 3 * I; 291 if Result <= 0 then 292 Result := I; 283 293 end 284 else if RW[ p].Model[Project and cpIndex].Cap[mcLine] > 0 then294 else if RW[P].Model[Project and cpIndex].Cap[mcLine] > 0 then 285 295 if Project0 and (not cpAuto or cpRepeat) = Project and not cpAuto or cpRepeat 286 296 then 287 result := result shr 1297 Result := Result shr 1 288 298 else 289 result := result * 2299 Result := Result * 2; 290 300 end 291 301 else 292 302 begin { improvement project } 293 result := Imp[Project and cpIndex].Cost;294 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = p)303 Result := Imp[Project and cpIndex].Cost; 304 if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = P) 295 305 then 296 result := result * ColossusEffect div 100;297 end; 298 result := result * BuildCostMod[Difficulty[p]] div 12;299 end 300 end; 301 302 function GetSmallCityReport( p, cix: integer; var CityReport: TCityReport;303 PCityReportEx: PCityReportEx = nil): integer;304 var 305 i, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: integer;306 Result := Result * ColossusEffect div 100; 307 end; 308 Result := Result * BuildCostMod[Difficulty[P]] div 12; 309 end; 310 end; 311 312 function GetSmallCityReport(P, cix: Integer; var CityReport: TCityReport; 313 PCityReportEx: PCityReportEx = nil): Integer; 314 var 315 I, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: Integer; 306 316 ProdProcessing: TProdProcessing; 307 317 TradeProcessing: TTradeProcessing; 308 318 Radius: TVicinity21Loc; 309 319 UnitReport: TUnitReport; 310 RareOK: array [0 .. 3] of integer;320 RareOK: array [0 .. 3] of Integer; 311 321 TileInfo: TTileInfo; 312 322 begin 313 with RW[ p].City[cix], CityReport do323 with RW[P].City[cix], CityReport do 314 324 begin 315 325 if HypoTiles <= 0 then 316 326 HypoTiles := Tiles; 317 327 if HypoTax < 0 then 318 HypoTax := RW[ p].TaxRate;328 HypoTax := RW[P].TaxRate; 319 329 if HypoLux < 0 then 320 HypoLux := RW[ p].LuxRate;321 322 if (Flags and chCaptured <> 0) or (RW[ p].Government = gAnarchy) then330 HypoLux := RW[P].LuxRate; 331 332 if (Flags and chCaptured <> 0) or (RW[P].Government = gAnarchy) then 323 333 begin 324 334 Working := 0; 325 335 for V21 := 1 to 26 do 326 336 if HypoTiles and (1 shl V21) <> 0 then 327 inc(Working); // for backward compatibility328 329 if RW[ p].Government = gFundamentalism then337 Inc(Working); // for backward compatibility 338 339 if RW[P].Government = gFundamentalism then 330 340 begin 331 341 Happy := Size; 332 Control := Size 342 Control := Size; 333 343 end // !!! old bug, kept for compatibility 334 344 else 335 345 begin 336 346 Happy := 0; 337 Control := 0 347 Control := 0; 338 348 end; 339 349 … … 370 380 BaseHappiness := Size; 371 381 end; 372 for i:= 0 to nWonder - 1 do373 if Built[ i] = 1 then382 for I := 0 to nWonder - 1 do 383 if Built[I] = 1 then 374 384 begin 375 inc(Happy);376 inc(BaseHappiness, 2)385 Inc(Happy); 386 Inc(BaseHappiness, 2); 377 387 end; 378 388 if Built[imTemple] = 1 then 379 389 begin 380 inc(Happy);381 inc(BaseHappiness, 2)390 Inc(Happy); 391 Inc(BaseHappiness, 2); 382 392 end; 383 393 if Built[imCathedral] = 1 then 384 394 begin 385 inc(Happy, 2);386 inc(BaseHappiness, 4);387 if GWonder[woBach].EffectiveOwner = pthen395 Inc(Happy, 2); 396 Inc(BaseHappiness, 4); 397 if GWonder[woBach].EffectiveOwner = P then 388 398 begin 389 inc(Happy);390 inc(BaseHappiness, 2)399 Inc(Happy); 400 Inc(BaseHappiness, 2); 391 401 end; 392 402 end; 393 403 if Built[imTheater] > 0 then 394 404 begin 395 inc(Happy, 2);396 inc(BaseHappiness, 4)405 Inc(Happy, 2); 406 Inc(BaseHappiness, 4); 397 407 end; 398 408 399 409 // calculate unit support 400 {$IFOPT O-} assert(InvalidTreatyMap = 0); {$ENDIF}410 {$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF} 401 411 Support := 0; 402 412 ForcedSupport := 0; 403 413 Eaten := Size * 2; 404 414 Deployed := 0; 405 for uix := 0 to RW[ p].nUn - 1 do406 with RW[ p].Un[uix] do415 for uix := 0 to RW[P].nUn - 1 do 416 with RW[P].Un[uix] do 407 417 if (Loc >= 0) and (Home = cix) then 408 418 begin 409 GetUnitReport( p, uix, UnitReport);410 inc(Eaten, UnitReport.FoodSupport);419 GetUnitReport(P, uix, UnitReport); 420 Inc(Eaten, UnitReport.FoodSupport); 411 421 if UnitReport.ReportFlags and urfAlwaysSupport <> 0 then 412 inc(ForcedSupport, UnitReport.ProdSupport)422 Inc(ForcedSupport, UnitReport.ProdSupport) 413 423 else 414 inc(Support, UnitReport.ProdSupport);424 Inc(Support, UnitReport.ProdSupport); 415 425 if UnitReport.ReportFlags and urfDeployed <> 0 then 416 inc(Deployed);426 Inc(Deployed); 417 427 end; 418 428 if Deployed >= Happy then 419 429 Happy := 0 420 430 else 421 dec(Happy, Deployed);422 dec(Support, Size * SupportFree[RW[p].Government] shr 1);431 Dec(Happy, Deployed); 432 Dec(Support, Size * SupportFree[RW[P].Government] shr 1); 423 433 if Support < 0 then 424 434 Support := 0; 425 inc(Support, ForcedSupport);435 Inc(Support, ForcedSupport); 426 436 427 437 { control } 428 case RW[ p].Government of438 case RW[P].Government of 429 439 gDespotism: 430 for uix := 0 to RW[ p].nUn - 1 do431 if (RW[ p].Un[uix].Loc = Loc) and432 (RW[ p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_TownGuard) then440 for uix := 0 to RW[P].nUn - 1 do 441 if (RW[P].Un[uix].Loc = Loc) and 442 (RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_TownGuard) then 433 443 begin 434 inc(Happy);435 inc(Control, 2)444 Inc(Happy); 445 Inc(Control, 2); 436 446 end; 437 447 gFundamentalism: … … 439 449 BaseHappiness := 0; // done by control 440 450 Happy := Size; 441 Control := Size 451 Control := Size; 442 452 end; 443 453 end; 444 454 445 455 // collect processing parameters 446 DetermineCityProdProcessing( p, cix, ProdProcessing);447 DetermineCityTradeProcessing( p, cix, BaseHappiness + Control - 2 *456 DetermineCityProdProcessing(P, cix, ProdProcessing); 457 DetermineCityTradeProcessing(P, cix, BaseHappiness + Control - 2 * 448 458 Deployed, TradeProcessing); 449 459 … … 462 472 // HypoTiles go beyond map border! 463 473 begin 464 result := eInvalid;465 exit474 Result := eInvalid; 475 Exit; 466 476 end; 467 GetTileInfo( p, cix, Loc1, TileInfo);468 inc(FoodRep, TileInfo.Food);469 inc(ProdRep, TileInfo.Prod);470 inc(Trade, TileInfo.Trade);477 GetTileInfo(P, cix, Loc1, TileInfo); 478 Inc(FoodRep, TileInfo.Food); 479 Inc(ProdRep, TileInfo.Prod); 480 Inc(Trade, TileInfo.Trade); 471 481 if (RealMap[Loc1] and fModern <> 0) and 472 (RW[ p].Tech[adMassProduction] >= tsApplicable) then473 inc(RareOK[RealMap[Loc1] shr 25 and 3]);474 inc(Working)482 (RW[P].Tech[adMassProduction] >= tsApplicable) then 483 Inc(RareOK[RealMap[Loc1] shr 25 and 3]); 484 Inc(Working); 475 485 end; 476 486 if Built[imAlgae] = 1 then 477 inc(FoodRep, 12);487 Inc(FoodRep, 12); 478 488 479 489 if PCityReportEx <> nil then … … 500 510 end; 501 511 end; 502 result := eOk;503 end; { GetSmallCityReport }504 505 function GetCityReport( p, cix: integer; var CityReport: TCityReport): integer;506 begin 507 result := GetSmallCityReport(p, cix, CityReport);508 CityReport.Storage := StorageSize[Difficulty[ p]];509 CityReport.ProdCost := GetProjectCost( p, cix);510 end; 511 512 function GetCityReportNew( p, cix: integer;513 var CityReportNew: TCityReportNew): integer;512 Result := eOk; 513 end; 514 515 function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer; 516 begin 517 Result := GetSmallCityReport(P, cix, CityReport); 518 CityReport.Storage := StorageSize[Difficulty[P]]; 519 CityReport.ProdCost := GetProjectCost(P, cix); 520 end; 521 522 function GetCityReportNew(P, cix: Integer; 523 var CityReportNew: TCityReportNew): Integer; 514 524 var 515 525 CityReport: TCityReport; … … 521 531 CityReport.HypoTax := HypoTaxRate; 522 532 CityReport.HypoLux := HypoLuxuryRate; 523 result := GetSmallCityReport(p, cix, CityReport, @CityReportEx);524 FoodSupport := CityReport.Eaten - 2 * RW[ p].City[cix].Size;533 Result := GetSmallCityReport(P, cix, CityReport, @CityReportEx); 534 FoodSupport := CityReport.Eaten - 2 * RW[P].City[cix].Size; 525 535 MaterialSupport := CityReport.Support; 526 ProjectCost := GetProjectCost( p, cix);527 Storage := StorageSize[Difficulty[ p]];536 ProjectCost := GetProjectCost(P, cix); 537 Storage := StorageSize[Difficulty[P]]; 528 538 Deployed := CityReport.Deployed; 529 539 Morale := CityReportEx.BaseHappiness; 530 540 CollectedControl := CityReportEx.BaseControl + 531 (RW[ p].City[cix].Size - CityReport.Working) * 2;541 (RW[P].City[cix].Size - CityReport.Working) * 2; 532 542 CollectedFood := CityReport.FoodRep; 533 543 CollectedMaterial := CityReportEx.Material; … … 541 551 Luxury := CityReport.Lux; 542 552 FoodSurplus := CityReport.FoodRep - CityReport.Eaten; 543 HappinessBalance := Morale + Luxury + CollectedControl - RW[ p].City[cix]553 HappinessBalance := Morale + Luxury + CollectedControl - RW[P].City[cix] 544 554 .Size - 2 * Deployed; 545 555 end; … … 550 560 ____________________________________________________________________ 551 561 } 552 procedure NextBest( p, cix: integer; var SelectedLoc, SelectedV21: integer);562 procedure NextBest(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 553 563 { best tile unused but available by city cix } 554 564 var 555 Resources, Most, Loc1, p1, V21: integer;565 Resources, Most, Loc1, p1, V21: Integer; 556 566 TileInfo: TTileInfo; 557 567 Radius: TVicinity21Loc; 558 568 begin 559 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}569 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 560 570 Most := 0; 561 571 SelectedLoc := -1; 562 572 SelectedV21 := -1; 563 with RW[ p].City[cix] do573 with RW[P].City[cix] do 564 574 begin 565 575 V21_to_Loc(Loc, Radius); … … 570 580 begin 571 581 p1 := RealMap[Loc1] shr 27; 572 if ((p1 = nPl) or (p1 = p) or (RW[p].Treaty[p1] < trPeace)) and573 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = p) or574 (RW[ p].Treaty[Occupant[Loc1]] = trAlliance)) then582 if ((p1 = nPl) or (p1 = P) or (RW[P].Treaty[p1] < trPeace)) and 583 ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = P) or 584 (RW[P].Treaty[Occupant[Loc1]] = trAlliance)) then 575 585 begin 576 GetTileInfo( p, cix, Loc1, TileInfo);586 GetTileInfo(P, cix, Loc1, TileInfo); 577 587 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 578 588 TileInfo.Trade; … … 582 592 SelectedLoc := Loc1; 583 593 SelectedV21 := V21; 584 Most := Resources 585 end 586 end 587 end 588 end; 589 end; 590 end; 591 592 procedure NextWorst( p, cix: integer; var SelectedLoc, SelectedV21: integer);594 Most := Resources; 595 end; 596 end; 597 end; 598 end; 599 end; 600 end; 601 602 procedure NextWorst(P, cix: Integer; var SelectedLoc, SelectedV21: Integer); 593 603 { worst tile used by city cix } 594 604 var 595 Resources, Least, Loc1, V21: integer;605 Resources, Least, Loc1, V21: Integer; 596 606 Radius: TVicinity21Loc; 597 607 TileInfo: TTileInfo; … … 600 610 SelectedLoc := -1; 601 611 SelectedV21 := -1; 602 with RW[ p].City[cix] do612 with RW[P].City[cix] do 603 613 begin 604 614 V21_to_Loc(Loc, Radius); … … 609 619 if (Loc1 >= 0) and (Loc1 < MapSize) and (1 shl V21 and Tiles <> 0) then 610 620 begin 611 GetTileInfo( p, cix, Loc1, TileInfo);621 GetTileInfo(P, cix, Loc1, TileInfo); 612 622 Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 + 613 623 TileInfo.Trade; … … 617 627 SelectedLoc := Loc1; 618 628 SelectedV21 := V21; 619 Least := Resources 620 end 621 end; 622 end 623 end 624 end; 625 626 function NextPoll( p, cix: integer): integer;627 var 628 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: integer;629 Least := Resources; 630 end; 631 end; 632 end; 633 end; 634 end; 635 636 function NextPoll(P, cix: Integer): Integer; 637 var 638 Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: Integer; 629 639 Radius: TVicinity21Loc; 630 640 TileInfo: TTileInfo; 631 641 begin 632 642 BestDist := MaxInt; 633 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}643 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 634 644 Best := 0; 635 result := -1;636 with RW[ p].City[cix] do645 Result := -1; 646 with RW[P].City[cix] do 637 647 begin 638 648 V21_to_Loc(Loc, Radius); … … 646 656 begin 647 657 pTerr := RealMap[Loc1] shr 27; 648 if (pTerr = nPl) or (pTerr = p) or (RW[p].Treaty[pTerr] < trPeace)658 if (pTerr = nPl) or (pTerr = P) or (RW[P].Treaty[pTerr] < trPeace) 649 659 then 650 660 begin 651 GetTileInfo( p, cix, Loc1, TileInfo);661 GetTileInfo(P, cix, Loc1, TileInfo); 652 662 Resources := TileInfo.Prod shl 16 + TileInfo.Trade shl 8 + 653 663 TileInfo.Food; … … 659 669 then 660 670 begin 661 result := Loc1;671 Result := Loc1; 662 672 Best := Resources; 663 673 BestDist := Dist; … … 669 679 end; 670 680 671 function AddBestCityTile( p, cix: integer): boolean;672 var 673 TileLoc, V21: integer;674 begin 675 NextBest( p, cix, TileLoc, V21);676 result := TileLoc >= 0;677 if result then678 with RW[ p].City[cix] do679 begin 680 assert(1 shl V21 and Tiles = 0);681 function AddBestCityTile(P, cix: Integer): Boolean; 682 var 683 TileLoc, V21: Integer; 684 begin 685 NextBest(P, cix, TileLoc, V21); 686 Result := TileLoc >= 0; 687 if Result then 688 with RW[P].City[cix] do 689 begin 690 Assert(1 shl V21 and Tiles = 0); 681 691 Tiles := Tiles or (1 shl V21); 682 UsedByCity[TileLoc] := Loc 683 end 684 end; 685 686 procedure CityGrowth( p, cix: integer);687 var 688 TileLoc, V21: integer;692 UsedByCity[TileLoc] := Loc; 693 end; 694 end; 695 696 procedure CityGrowth(P, cix: Integer); 697 var 698 TileLoc, V21: Integer; 689 699 AltCityReport: TCityReport; 690 700 begin 691 with RW[ p].City[cix] do701 with RW[P].City[cix] do 692 702 begin 693 inc(Size);694 NextBest( p, cix, TileLoc, V21);703 Inc(Size); 704 NextBest(P, cix, TileLoc, V21); 695 705 if TileLoc >= 0 then 696 706 begin { test whether exploitation of tile would lead to disorder } … … 698 708 AltCityReport.HypoTax := -1; 699 709 AltCityReport.HypoLux := -1; 700 GetSmallCityReport( p, cix, AltCityReport);710 GetSmallCityReport(P, cix, AltCityReport); 701 711 if AltCityReport.Working - AltCityReport.Happy <= Size shr 1 then 702 712 // !!! change to new style disorder 703 713 begin { no disorder -- exploit tile } 704 assert(1 shl V21 and Tiles = 0);714 Assert(1 shl V21 and Tiles = 0); 705 715 Tiles := Tiles or (1 shl V21); 706 UsedByCity[TileLoc] := Loc 707 end 708 end; 709 end 710 end; 711 712 procedure CityShrink( p, cix: integer);713 var 714 TileLoc, V21, Working: integer;716 UsedByCity[TileLoc] := Loc; 717 end; 718 end; 719 end; 720 end; 721 722 procedure CityShrink(P, cix: Integer); 723 var 724 TileLoc, V21, Working: Integer; 715 725 AltCityReport: TCityReport; 716 726 begin 717 with RW[ p].City[cix] do727 with RW[P].City[cix] do 718 728 begin 719 729 Working := 0; 720 730 for V21 := 1 to 26 do 721 731 if Tiles and (1 shl V21) <> 0 then 722 inc(Working);723 dec(Size);724 if Food > StorageSize[Difficulty[ p]] then725 Food := StorageSize[Difficulty[ p]];726 NextWorst( p, cix, TileLoc, V21);732 Inc(Working); 733 Dec(Size); 734 if Food > StorageSize[Difficulty[P]] then 735 Food := StorageSize[Difficulty[P]]; 736 NextWorst(P, cix, TileLoc, V21); 727 737 if Working > Size then 728 738 begin { all citizens were working -- worst tile no longer exploited } 729 assert(1 shl V21 and Tiles <> 0);739 Assert(1 shl V21 and Tiles <> 0); 730 740 Tiles := Tiles and not(1 shl V21); 731 UsedByCity[TileLoc] := -1 741 UsedByCity[TileLoc] := -1; 732 742 end 733 743 else { test whether exploitation of tile would lead to disorder } … … 736 746 AltCityReport.HypoTax := -1; 737 747 AltCityReport.HypoLux := -1; 738 GetSmallCityReport( p, cix, AltCityReport);748 GetSmallCityReport(P, cix, AltCityReport); 739 749 if AltCityReport.Working - AltCityReport.Happy > Size shr 1 then 740 750 // !!! change to new style disorder 741 751 begin { disorder -- don't exploit tile } 742 assert(1 shl V21 and Tiles <> 0);752 Assert(1 shl V21 and Tiles <> 0); 743 753 Tiles := Tiles and not(1 shl V21); 744 UsedByCity[TileLoc] := -1 745 end 746 end; 747 end 748 end; 749 750 procedure Pollute( p, cix: integer);751 var 752 PollutionLoc: integer;753 begin 754 with RW[ p].City[cix] do754 UsedByCity[TileLoc] := -1; 755 end; 756 end; 757 end; 758 end; 759 760 procedure Pollute(P, cix: Integer); 761 var 762 PollutionLoc: Integer; 763 begin 764 with RW[P].City[cix] do 755 765 begin 756 766 Pollution := Pollution - MaxPollution; 757 PollutionLoc := NextPoll( p, cix);767 PollutionLoc := NextPoll(P, cix); 758 768 if PollutionLoc >= 0 then 759 769 begin 760 inc(Flags, chPollution);770 Inc(Flags, chPollution); 761 771 RealMap[PollutionLoc] := RealMap[PollutionLoc] or fPoll; 762 end 772 end; 763 773 end; 764 774 end; … … 768 778 ____________________________________________________________________ 769 779 } 770 procedure PayCityMaintenance( p, cix: integer);771 var 772 i: integer;773 begin 774 with RW[ p], City[cix] do775 for i:= nWonder to nImp - 1 do776 if (Built[ i] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or i))780 procedure PayCityMaintenance(P, cix: Integer); 781 var 782 I: Integer; 783 begin 784 with RW[P], City[cix] do 785 for I := nWonder to nImp - 1 do 786 if (Built[I] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or I)) 777 787 then // don't pay maintenance when just completed 778 788 begin 779 dec(Money, Imp[i].Maint);789 Dec(Money, Imp[I].Maint); 780 790 if Money < 0 then 781 791 begin { out of money - sell improvement } 782 inc(Money, Imp[i].Cost * BuildCostMod[Difficulty[p]] div 12);783 Built[ i] := 0;784 if Imp[ i].Kind <> ikCommon then792 Inc(Money, Imp[I].Cost * BuildCostMod[Difficulty[P]] div 12); 793 Built[I] := 0; 794 if Imp[I].Kind <> ikCommon then 785 795 begin 786 assert(i<> imSpacePort);796 Assert(I <> imSpacePort); 787 797 // never sell automatically! (solution: no maintenance) 788 NatBuilt[ i] := 0;789 if i= imGrWall then790 GrWallContinent[ p] := -1;798 NatBuilt[I] := 0; 799 if I = imGrWall then 800 GrWallContinent[P] := -1; 791 801 end; 792 inc(Flags, chImprovementLost)793 end 794 end; 795 end; 796 797 procedure CollectCityResources( p, cix: integer);798 var 799 CityStorage, CityProjectCost: integer;802 Inc(Flags, chImprovementLost); 803 end; 804 end; 805 end; 806 807 procedure CollectCityResources(P, cix: Integer); 808 var 809 CityStorage, CityProjectCost: Integer; 800 810 CityReport: TCityReportNew; 801 Disorder: boolean;802 begin 803 with RW[ p], City[cix], CityReport do811 Disorder: Boolean; 812 begin 813 with RW[P], City[cix], CityReport do 804 814 if Flags and chCaptured <> 0 then 805 815 begin 806 816 Flags := Flags and not chDisorder; 807 dec(Flags, $10000);817 Dec(Flags, $10000); 808 818 if Flags and chCaptured = 0 then 809 819 Flags := Flags or chAfterCapture; … … 816 826 HypoTaxRate := -1; 817 827 HypoLuxuryRate := -1; 818 GetCityReportNew( p, cix, CityReport);819 CityStorage := StorageSize[Difficulty[ p]];820 CityProjectCost := GetProjectCost( p, cix);828 GetCityReportNew(P, cix, CityReport); 829 CityStorage := StorageSize[Difficulty[P]]; 830 CityProjectCost := GetProjectCost(P, cix); 821 831 822 832 Disorder := (HappinessBalance < 0); … … 830 840 if not Disorder and ((Government = gFuture) or (Size >= NeedAqueductSize) 831 841 and (FoodSurplus < 2)) and (FoodSurplus > 0) then 832 inc(Money, FoodSurplus)842 Inc(Money, FoodSurplus) 833 843 else if not(Disorder and (FoodSurplus > 0)) then 834 844 begin { calculate new food storage } … … 839 849 (Project and (cpImp + cpIndex) <> cpImp + imAqueduct) and 840 850 (Project and (cpImp + cpIndex) <> cpImp + imSewer) and 841 not CanCityGrow( p, cix) then842 inc(Flags, chNoGrowthWarning);851 not CanCityGrow(P, cix) then 852 Inc(Flags, chNoGrowthWarning); 843 853 end; 844 854 845 855 if Prod > CityProjectCost then 846 856 begin 847 inc(Money, Prod - CityProjectCost);848 Prod := CityProjectCost 857 Inc(Money, Prod - CityProjectCost); 858 Prod := CityProjectCost; 849 859 end; 850 860 if Production < 0 then … … 852 862 else if not Disorder and (Flags and chProductionSabotaged = 0) then 853 863 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 854 inc(Money, Production)864 Inc(Money, Production) 855 865 else 856 inc(Prod, Production);866 Inc(Prod, Production); 857 867 858 868 if not Disorder then 859 869 begin 860 870 { sum research points and taxes } 861 inc(Research, Science);862 inc(Money, Tax);871 Inc(Research, Science); 872 Inc(Money, Tax); 863 873 Pollution := Pollution + AddPollution; 864 874 end; … … 866 876 end; 867 877 868 function CityTurn( p, cix: integer): boolean;878 function CityTurn(P, cix: Integer): Boolean; 869 879 // return value: whether city keeps existing 870 880 var 871 i, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,872 TestDet: integer;873 LackOfMaterial, CheckGrow, DoProd, IsActive: boolean;874 begin 875 with RW[ p], City[cix] do881 I, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det, 882 TestDet: Integer; 883 LackOfMaterial, CheckGrow, DoProd, IsActive: Boolean; 884 begin 885 with RW[P], City[cix] do 876 886 begin 877 887 SizeMod := 0; 878 CityStorage := StorageSize[Difficulty[ p]];879 CityProjectCost := GetProjectCost( p, cix);888 CityStorage := StorageSize[Difficulty[P]]; 889 CityProjectCost := GetProjectCost(P, cix); 880 890 881 891 LackOfMaterial := Flags and chUnitLost <> 0; … … 887 897 if CheckGrow and (GTestFlags and tfImmGrow <> 0) then { fast growth } 888 898 begin 889 if CanCityGrow( p, cix) then890 inc(SizeMod)899 if CanCityGrow(P, cix) then 900 Inc(SizeMod); 891 901 end 892 902 else if CheckGrow and (Food >= CityStorage) then { normal growth } 893 903 begin 894 if CanCityGrow( p, cix) then904 if CanCityGrow(P, cix) then 895 905 begin 896 906 if Built[imGranary] = 1 then 897 dec(Food, CityStorage shr 1)907 Dec(Food, CityStorage shr 1) 898 908 else 899 dec(Food, CityStorage);900 inc(SizeMod)901 end 909 Dec(Food, CityStorage); 910 Inc(SizeMod); 911 end; 902 912 end 903 913 else if Food < 0 then { famine } … … 906 916 // check if settlers or conscripts there to disband 907 917 uix := -1; 908 for i:= 0 to nUn - 1 do909 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) and910 ((Model[Un[ i].mix].Kind = mkSettler)918 for I := 0 to nUn - 1 do 919 if (Un[I].Loc >= 0) and (Un[I].Home = cix) and 920 ((Model[Un[I].mix].Kind = mkSettler) 911 921 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } 912 or (Un[ i].Flags and unConscripts <> 0)) and913 ((uix = -1) or (Model[Un[ i].mix].Cost < Model[Un[uix].mix].Cost) or914 (Model[Un[ i].mix].Cost = Model[Un[uix].mix].Cost) and915 (Un[ i].Exp < Un[uix].Exp)) then916 uix := i;922 or (Un[I].Flags and unConscripts <> 0)) and 923 ((uix = -1) or (Model[Un[I].mix].Cost < Model[Un[uix].mix].Cost) or 924 (Model[Un[I].mix].Cost = Model[Un[uix].mix].Cost) and 925 (Un[I].Exp < Un[uix].Exp)) then 926 uix := I; 917 927 918 928 if uix >= 0 then 919 929 begin 920 RemoveUnit_UpdateMap( p, uix);921 inc(Flags, chUnitLost);930 RemoveUnit_UpdateMap(P, uix); 931 Inc(Flags, chUnitLost); 922 932 end 923 933 else 924 934 begin 925 dec(SizeMod);926 inc(Flags, chPopDecrease)935 Dec(SizeMod); 936 Inc(Flags, chPopDecrease); 927 937 end 928 938 end; … … 936 946 uix := -1; 937 947 Det := MaxInt; 938 for i:= 0 to nUn - 1 do939 if (Un[ i].Loc >= 0) and (Un[i].Home = cix) then940 with Model[Un[ i].mix] do948 for I := 0 to nUn - 1 do 949 if (Un[I].Loc >= 0) and (Un[I].Home = cix) then 950 with Model[Un[I].mix] do 941 951 begin 942 952 if Kind = mkSpecial_TownGuard then 943 TestDet := Un[ i].Health + Un[i].Exp shl 8953 TestDet := Un[I].Health + Un[I].Exp shl 8 944 954 // disband townguards first 945 955 else 946 956 begin 947 TestDet := Un[ i].Health + Un[i].Exp shl 8 + Cost shl 16;957 TestDet := Un[I].Health + Un[I].Exp shl 8 + Cost shl 16; 948 958 // value of unit 949 959 if Flags and mdDoubleSupport <> 0 then … … 953 963 if TestDet < Det then 954 964 begin 955 uix := i;956 Det := TestDet 965 uix := I; 966 Det := TestDet; 957 967 end; 958 968 end; 959 969 if uix >= 0 then 960 970 begin 961 RemoveUnit_UpdateMap( p, uix);962 inc(Flags, chUnitLost);963 end 964 end 971 RemoveUnit_UpdateMap(P, uix); 972 Inc(Flags, chUnitLost); 973 end; 974 end; 965 975 end; 966 976 … … 974 984 (GWonder[Project and cpIndex].CityID <> WonderNotBuiltYet) then 975 985 begin 976 inc(Flags, chOldWonder);977 DoProd := false;986 Inc(Flags, chOldWonder); 987 DoProd := False; 978 988 end; 979 989 … … 985 995 (Project and cpConscripts <> 0))) then 986 996 begin 987 inc(Flags, chNoSettlerProd);988 DoProd := false;997 Inc(Flags, chNoSettlerProd); 998 DoProd := False; 989 999 end; 990 1000 991 1001 if DoProd then 992 1002 begin { project complete } 993 dec(Prod, CityProjectCost);1003 Dec(Prod, CityProjectCost); 994 1004 if Project and cpImp = 0 then { produce unit } 995 1005 begin 996 1006 if nUn < numax then 997 1007 begin 998 CreateUnit( p, Project and cpIndex);1008 CreateUnit(P, Project and cpIndex); 999 1009 Un[nUn - 1].Loc := Loc; 1000 1010 with Un[nUn - 1] do … … 1008 1018 Exp := ExpCost * 2; { vet } 1009 1019 if Project and cpConscripts <> 0 then 1010 Flags := Flags or unConscripts 1020 Flags := Flags or unConscripts; 1011 1021 end; 1012 PlaceUnit( p, nUn - 1);1022 PlaceUnit(P, nUn - 1); 1013 1023 UpdateUnitMap(Loc); 1014 1024 if Model[Project and cpIndex].Kind = mkSettler then 1015 dec(SizeMod, 2) { settler produced - city shrink }1025 Dec(SizeMod, 2) { settler produced - city shrink } 1016 1026 else if (Model[Project and cpIndex].Kind = mkSlaves) or 1017 1027 (Project and cpConscripts <> 0) then 1018 dec(SizeMod); { slaves/conscripts produced - city shrink }1028 Dec(SizeMod); { slaves/conscripts produced - city shrink } 1019 1029 end; 1020 1030 Project0 := Project or cpRepeat or cpCompleted; … … 1022 1032 else if Imp[Project and cpIndex].Kind = ikShipPart then 1023 1033 begin { produce ship parts } 1024 inc(GShip[p].Parts[Project and cpIndex - imShipComp]);1034 Inc(GShip[P].Parts[Project and cpIndex - imShipComp]); 1025 1035 Project0 := Project or cpCompleted; 1026 1036 end … … 1028 1038 begin 1029 1039 NewImp := Project and cpIndex; 1030 inc(Money, Prod); { change rest to money }1040 Inc(Money, Prod); { change rest to money } 1031 1041 Project0 := Project or cpCompleted; 1032 1042 Project := cpImp + imTrGoods; … … 1035 1045 if Imp[NewImp].Kind in [ikNatLocal, ikNatGlobal] then 1036 1046 begin // nat. project 1037 for i:= 0 to nCity - 1 do1038 if (City[ i].Loc >= 0) and (City[i].Built[NewImp] = 1) then1047 for I := 0 to nCity - 1 do 1048 if (City[I].Loc >= 0) and (City[I].Built[NewImp] = 1) then 1039 1049 begin { allowed only once } 1040 inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[p]] div 12);1041 City[ i].Built[NewImp] := 0;1050 Inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[P]] div 12); 1051 City[I].Built[NewImp] := 0; 1042 1052 end; 1043 1053 NatBuilt[NewImp] := 1; … … 1046 1056 case NewImp of 1047 1057 imGrWall: 1048 GrWallContinent[ p] := Continent[Loc];1058 GrWallContinent[P] := Continent[Loc]; 1049 1059 end; 1050 1060 end; … … 1053 1063 begin // wonder 1054 1064 GWonder[NewImp].CityID := ID; 1055 GWonder[NewImp].EffectiveOwner := p;1065 GWonder[NewImp].EffectiveOwner := P; 1056 1066 CheckExpiration(NewImp); 1057 1067 … … 1060 1070 woEiffel: 1061 1071 begin // reactivate wonders 1062 for i:= 0 to nWonder - 1 do1063 if Imp[ i].Expiration >= 0 then1072 for I := 0 to nWonder - 1 do 1073 if Imp[I].Expiration >= 0 then 1064 1074 for cix2 := 0 to nCity - 1 do 1065 if (City[cix2].Loc >= 0) and (City[cix2].Built[ i] = 1)1075 if (City[cix2].Loc >= 0) and (City[cix2].Built[I] = 1) 1066 1076 then 1067 GWonder[ i].EffectiveOwner := p1077 GWonder[I].EffectiveOwner := P; 1068 1078 end; 1069 1079 woLighthouse: 1070 CheckSpecialModels( p, preLighthouse);1080 CheckSpecialModels(P, preLighthouse); 1071 1081 woLeo: 1072 1082 begin 1073 inc(Research, TechBaseCost(nTech[p], Difficulty[p]) +1074 TechBaseCost(nTech[ p] + 2, Difficulty[p]));1075 CheckSpecialModels( p, preLeo);1083 Inc(Research, TechBaseCost(nTech[P], Difficulty[P]) + 1084 TechBaseCost(nTech[P] + 2, Difficulty[P])); 1085 CheckSpecialModels(P, preLeo); 1076 1086 end; 1077 1087 woPyramids: 1078 CheckSpecialModels( p, preBuilder);1088 CheckSpecialModels(P, preBuilder); 1079 1089 woMir: 1080 1090 begin 1081 1091 for p1 := 0 to nPl - 1 do 1082 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1092 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1083 1093 begin 1084 if RW[ p].Treaty[p1] = trNoContact then1085 IntroduceEnemy( p, p1);1086 GiveCivilReport( p, p1);1087 GiveMilReport( p, p1)1094 if RW[P].Treaty[p1] = trNoContact then 1095 IntroduceEnemy(P, p1); 1096 GiveCivilReport(P, p1); 1097 GiveMilReport(P, p1); 1088 1098 end; 1089 end 1099 end; 1090 1100 end; 1091 1101 end; 1092 1102 1093 for i:= 0 to nImpReplacement - 1 do // sell obsolete buildings1094 if (ImpReplacement[ i].NewImp = NewImp) and1095 (Built[ImpReplacement[ i].OldImp] > 0) then1103 for I := 0 to nImpReplacement - 1 do // sell obsolete buildings 1104 if (ImpReplacement[I].NewImp = NewImp) and 1105 (Built[ImpReplacement[I].OldImp] > 0) then 1096 1106 begin 1097 inc(RW[p].Money, Imp[ImpReplacement[i].OldImp].Cost * BuildCostMod1098 [Difficulty[ p]] div 12);1099 Built[ImpReplacement[ i].OldImp] := 0;1107 Inc(RW[P].Money, Imp[ImpReplacement[I].OldImp].Cost * BuildCostMod 1108 [Difficulty[P]] div 12); 1109 Built[ImpReplacement[I].OldImp] := 0; 1100 1110 end; 1101 1111 1102 1112 if NewImp in [imPower, imHydro, imNuclear] then 1103 for i:= 0 to nImp - 1 do1104 if ( i <> NewImp) and (iin [imPower, imHydro, imNuclear]) and1105 (Built[ i] > 0) then1113 for I := 0 to nImp - 1 do 1114 if (I <> NewImp) and (I in [imPower, imHydro, imNuclear]) and 1115 (Built[I] > 0) then 1106 1116 begin // sell obsolete power plant 1107 inc(RW[p].Money, Imp[i].Cost * BuildCostMod[Difficulty[p]1117 Inc(RW[P].Money, Imp[I].Cost * BuildCostMod[Difficulty[P] 1108 1118 ] div 12); 1109 Built[ i] := 0;1119 Built[I] := 0; 1110 1120 end; 1111 1121 … … 1113 1123 end; 1114 1124 Prod0 := Prod; 1115 inc(Flags, chProduction)1125 Inc(Flags, chProduction); 1116 1126 end 1117 1127 else … … 1125 1135 if SizeMod > 0 then 1126 1136 begin 1127 CityGrowth( p, cix);1128 inc(Flags, chPopIncrease);1129 end; 1130 result := Size + SizeMod >= 2;1131 if result then1137 CityGrowth(P, cix); 1138 Inc(Flags, chPopIncrease); 1139 end; 1140 Result := Size + SizeMod >= 2; 1141 if Result then 1132 1142 while SizeMod < 0 do 1133 1143 begin 1134 CityShrink( p, cix);1135 inc(SizeMod)1136 end; 1137 end 1138 end; // CityTurn1144 CityShrink(P, cix); 1145 Inc(SizeMod); 1146 end; 1147 end; 1148 end; 1139 1149 1140 1150 { … … 1142 1152 ____________________________________________________________________ 1143 1153 } 1144 function SetCityTiles( p, cix, NewTiles: integer;1145 TestOnly: boolean = false): integer;1146 var 1147 V21, Working, ChangeTiles, AddTiles, Loc1: integer;1154 function SetCityTiles(P, cix, NewTiles: Integer; 1155 TestOnly: Boolean = False): Integer; 1156 var 1157 V21, Working, ChangeTiles, AddTiles, Loc1: Integer; 1148 1158 CityAreaInfo: TCityAreaInfo; 1149 1159 Radius: TVicinity21Loc; 1150 1160 begin 1151 with RW[ p].City[cix] do1161 with RW[P].City[cix] do 1152 1162 begin 1153 ChangeTiles := NewTiles xor integer(Tiles);1163 ChangeTiles := NewTiles xor Integer(Tiles); 1154 1164 AddTiles := NewTiles and not Tiles; 1155 1165 if Mode = moPlaying then … … 1157 1167 if NewTiles and not $67F7F76 <> 0 then 1158 1168 begin 1159 result := eInvalid;1160 exit1169 Result := eInvalid; 1170 Exit 1161 1171 end; // invalid tile index included 1162 1172 if NewTiles and (1 shl 13) = 0 then 1163 1173 begin 1164 result := eViolation;1165 exit1174 Result := eViolation; 1175 Exit 1166 1176 end; // city tile must be exploited 1167 1177 if ChangeTiles = 0 then 1168 1178 begin 1169 result := eNotChanged;1170 exit1179 Result := eNotChanged; 1180 Exit 1171 1181 end; 1172 1182 if AddTiles <> 0 then 1173 1183 begin 1174 1184 // check if new tiles possible 1175 GetCityAreaInfo( p, Loc, CityAreaInfo);1185 GetCityAreaInfo(P, Loc, CityAreaInfo); 1176 1186 for V21 := 1 to 26 do 1177 1187 if AddTiles and (1 shl V21) <> 0 then 1178 1188 if CityAreaInfo.Available[V21] <> faAvailable then 1179 1189 begin 1180 result := eTileNotAvailable;1181 exit1190 Result := eTileNotAvailable; 1191 Exit; 1182 1192 end; 1183 1193 // not more tiles than inhabitants … … 1185 1195 for V21 := 1 to 26 do 1186 1196 if NewTiles and (1 shl V21) <> 0 then 1187 inc(Working);1197 Inc(Working); 1188 1198 if Working > Size then 1189 1199 begin 1190 result := eNoWorkerAvailable;1191 exit1192 end; 1193 end; 1194 end; 1195 result := eOk;1200 Result := eNoWorkerAvailable; 1201 Exit; 1202 end; 1203 end; 1204 end; 1205 Result := eOk; 1196 1206 if not TestOnly then 1197 1207 begin … … 1201 1211 begin 1202 1212 Loc1 := Radius[V21]; 1203 assert((Loc1 >= 0) and (Loc1 < MapSize));1213 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1204 1214 if NewTiles and (1 shl V21) <> 0 then 1205 1215 UsedByCity[Loc1] := Loc // employ tile 1206 1216 else if UsedByCity[Loc1] <> Loc then 1207 assert(Mode < moPlaying)1217 Assert(Mode < moPlaying) 1208 1218 // should only happen during loading, because of wrong sSetCityTiles command order 1209 1219 else 1210 UsedByCity[Loc1] := -1 // unemploy tile1211 end; 1212 Tiles := NewTiles 1213 end 1214 end; 1215 end; 1216 1217 procedure GetCityTileAdvice( p, cix: integer; var Advice: TCityTileAdviceData);1220 UsedByCity[Loc1] := -1; // unemploy tile 1221 end; 1222 Tiles := NewTiles; 1223 end; 1224 end; 1225 end; 1226 1227 procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData); 1218 1228 const 1219 1229 oFood = 0; … … 1223 1233 type 1224 1234 TTileData = record 1225 Food, Prod, Trade, SubValue, V21: integer; 1226 end; 1227 var 1228 i, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking, 1235 Food: Integer; 1236 Prod: Integer; 1237 Trade: Integer; 1238 SubValue: Integer; 1239 V21: Integer; 1240 end; 1241 var 1242 I, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking, 1229 1243 WantedProd, MinFood, MinProd, count, Take, MaxTake, AreaSize, FormulaCode, 1230 1244 NeedRare, RareTiles, cix1, dx, dy, BestTiles, ProdBeforeBoost, TestTiles, 1231 SubPlus, SuperPlus: integer;1232 SuperValue, BestSuperValue, SubValue, BestSubValue: integer;1233 Value, BestValue, ValuePlus: extended;1234 ValueFormula_Weight: array [oFood .. oScience] of extended;1235 ValueFormula_Multiply: array [oFood .. oScience] of boolean;1236 Output: array [oFood .. oScience] of integer;1245 SubPlus, SuperPlus: Integer; 1246 SuperValue, BestSuperValue, SubValue, BestSubValue: Integer; 1247 Value, BestValue, ValuePlus: Extended; 1248 ValueFormula_Weight: array [oFood .. oScience] of Extended; 1249 ValueFormula_Multiply: array [oFood .. oScience] of Boolean; 1250 Output: array [oFood .. oScience] of Integer; 1237 1251 TileInfo, BaseTileInfo: TTileInfo; 1238 1252 Radius, Radius1: TVicinity21Loc; … … 1241 1255 CityAreaInfo: TCityAreaInfo; 1242 1256 Hierarchy: array [0 .. 20, 0 .. 31] of TTileData; 1243 nTile, nSelection: array [0 .. 20] of integer;1244 SubCriterion: array [0 .. 27] of integer;1245 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: boolean;1246 begin 1247 if (RW[ p].Government = gAnarchy) or (RW[p].City[cix].Flags and chCaptured <> 0)1257 nTile, nSelection: array [0 .. 20] of Integer; 1258 SubCriterion: array [0 .. 27] of Integer; 1259 FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: Boolean; 1260 begin 1261 if (RW[P].Government = gAnarchy) or (RW[P].City[cix].Flags and chCaptured <> 0) 1248 1262 then 1249 1263 begin … … 1251 1265 Advice.Tiles := 1 shl CityOwnTile; 1252 1266 Advice.CityReport.HypoTiles := 1 shl CityOwnTile; 1253 exit;1254 end; 1255 1256 for i:= oFood to oScience do1267 Exit; 1268 end; 1269 1270 for I := oFood to oScience do 1257 1271 begin // decode evaluation formula from weights parameter 1258 FormulaCode := Advice.ResourceWeights shr (24 - 8 * i) and $FF;1259 ValueFormula_Multiply[ i] := FormulaCode and $80 <> 0;1272 FormulaCode := Advice.ResourceWeights shr (24 - 8 * I) and $FF; 1273 ValueFormula_Multiply[I] := FormulaCode and $80 <> 0; 1260 1274 if FormulaCode and $40 <> 0 then 1261 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1275 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1262 1276 (1 shl (FormulaCode and $30 shr 4)) / 16 1263 1277 else 1264 ValueFormula_Weight[ i] := (FormulaCode and $0F) *1278 ValueFormula_Weight[I] := (FormulaCode and $0F) * 1265 1279 (1 shl (FormulaCode and $30 shr 4)); 1266 1280 end; … … 1269 1283 TestReport.HypoTax := -1; 1270 1284 TestReport.HypoLux := -1; 1271 GetSmallCityReport( p, cix, TestReport, @CityReportEx);1272 with RW[ p].City[cix] do1285 GetSmallCityReport(P, cix, TestReport, @CityReportEx); 1286 with RW[P].City[cix] do 1273 1287 begin 1274 1288 V21_to_Loc(Loc, Radius); 1275 FoodToTax := RW[ p].Government = gFuture;1289 FoodToTax := RW[P].Government = gFuture; 1276 1290 ProdToTax := Project and (cpImp + cpIndex) = cpImp + imTrGoods; 1277 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[ p]]) and1278 not CanCityGrow( p, cix);1291 FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[P]]) and 1292 not CanCityGrow(P, cix); 1279 1293 1280 1294 // sub criteria … … 1286 1300 V21 xor $15; 1287 1301 end; 1288 for cix1 := 0 to RW[ p].nCity - 1 do1302 for cix1 := 0 to RW[P].nCity - 1 do 1289 1303 if cix1 <> cix then 1290 1304 begin 1291 Loc1 := RW[ p].City[cix1].Loc;1305 Loc1 := RW[P].City[cix1].Loc; 1292 1306 if Loc1 >= 0 then 1293 1307 begin … … 1302 1316 begin 1303 1317 dxdy(Loc, Loc1, dx, dy); 1304 dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);1318 Dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160); 1305 1319 end; 1306 1320 end; … … 1309 1323 end; 1310 1324 1311 GetCityAreaInfo( p, Loc, CityAreaInfo);1325 GetCityAreaInfo(P, Loc, CityAreaInfo); 1312 1326 AreaSize := 0; 1313 1327 for V21 := 1 to 26 do 1314 1328 if CityAreaInfo.Available[V21] = faAvailable then 1315 inc(AreaSize);1316 1317 if RW[ p].Government = gFundamentalism then1329 Inc(AreaSize); 1330 1331 if RW[P].Government = gFundamentalism then 1318 1332 begin 1319 1333 MinWorking := Size; … … 1325 1339 if MinWorking > Size then 1326 1340 MinWorking := Size; 1327 if (RW[ p].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury1341 if (RW[P].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury 1328 1342 then 1329 1343 MaxWorking := MinWorking … … 1362 1376 Loc1 := Radius[V21]; 1363 1377 if (Loc1 >= 0) and (Loc1 < MapSize) and 1364 (RealMap[Loc1] and fModern = cardinal(NeedRare)) then1378 (RealMap[Loc1] and fModern = Cardinal(NeedRare)) then 1365 1379 RareTiles := RareTiles or (1 shl V21); 1366 end 1380 end; 1367 1381 end; 1368 1382 … … 1374 1388 begin 1375 1389 Loc1 := Radius[V21]; 1376 assert((Loc1 >= 0) and (Loc1 < MapSize));1377 GetTileInfo( p, cix, Loc1, TileInfo);1390 Assert((Loc1 >= 0) and (Loc1 < MapSize)); 1391 GetTileInfo(P, cix, Loc1, TileInfo); 1378 1392 if V21 = CityOwnTile then 1379 1393 BaseTileInfo := TileInfo … … 1391 1405 (TileInfo.Trade = Hierarchy[iH, iT].Trade) and 1392 1406 (SubCriterion[V21] >= SubCriterion[Hierarchy[iH, iT].V21])) do 1393 inc(iT);1407 Inc(iT); 1394 1408 if (iT = nTile[iH]) // new worst tile in this hierarchy 1395 1409 or ((TileInfo.Food >= Hierarchy[iH, iT].Food) … … 1397 1411 and (TileInfo.Prod >= Hierarchy[iH, iT].Prod) and 1398 1412 (TileInfo.Trade >= Hierarchy[iH, iT].Trade)) then 1399 break; // insert position found!1400 inc(iH);1413 Break; // insert position found! 1414 Inc(iH); 1401 1415 end; 1402 1416 if iH = nHierarchy then 1403 1417 begin // need to start new hierarchy 1404 1418 nTile[iH] := 0; 1405 inc(nHierarchy);1419 Inc(nHierarchy); 1406 1420 iT := 0; 1407 1421 end; 1408 move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],1422 Move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1], 1409 1423 (nTile[iH] - iT) * SizeOf(TTileData)); 1410 inc(nTile[iH]);1424 Inc(nTile[iH]); 1411 1425 Hierarchy[iH, iT].V21 := V21; 1412 1426 Hierarchy[iH, iT].Food := TileInfo.Food; … … 1424 1438 begin 1425 1439 Loc1 := Radius[V21]; 1426 assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));1427 GetTileInfo( p, cix, Loc1, TileInfo);1440 Assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize)); 1441 GetTileInfo(P, cix, Loc1, TileInfo); 1428 1442 if iH = nHierarchy then 1429 1443 begin // need to start new hierarchy 1430 1444 nTile[iH] := 0; 1431 inc(nHierarchy);1445 Inc(nHierarchy); 1432 1446 iT := 0; 1433 1447 end 1434 1448 else 1435 1449 iT := nTile[iH]; 1436 inc(nTile[iH]);1450 Inc(nTile[iH]); 1437 1451 Hierarchy[iH, iT].V21 := V21; 1438 1452 Hierarchy[iH, iT].Food := TileInfo.Food; // = 0 … … 1443 1457 end; 1444 1458 if Built[imAlgae] > 0 then 1445 inc(BaseTileInfo.Food, 12);1459 Inc(BaseTileInfo.Food, 12); 1446 1460 1447 1461 // step 2: summarize resources 1448 1462 for iH := 0 to nHierarchy - 1 do 1449 1463 begin 1450 move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));1464 Move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData)); 1451 1465 Hierarchy[iH, 0].Food := 0; 1452 1466 Hierarchy[iH, 0].Prod := 0; … … 1456 1470 for iT := 1 to nTile[iH] do 1457 1471 begin 1458 inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food);1459 inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod);1460 inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade);1461 inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue);1472 Inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food); 1473 Inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod); 1474 Inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade); 1475 Inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue); 1462 1476 Hierarchy[iH, iT].V21 := 1 shl Hierarchy[iH, iT].V21 + 1463 1477 Hierarchy[iH, iT - 1].V21; … … 1487 1501 (ProdBeforeBoost < WantedProd)) do 1488 1502 begin 1489 assert(nSelection[iH] = 0);1503 Assert(nSelection[iH] = 0); 1490 1504 Take := MinWorking - TestReport.Working; 1491 1505 if Take > nTile[iH] then … … 1500 1514 while (Take < MaxTake) and 1501 1515 (TestReport.FoodRep + Hierarchy[iH, Take].Food < MinFood) do 1502 inc(Take);1516 Inc(Take); 1503 1517 while (Take < MaxTake) and 1504 1518 (ProdBeforeBoost + Hierarchy[iH, Take].Prod < MinProd) do 1505 inc(Take);1519 Inc(Take); 1506 1520 end; 1507 1521 nSelection[iH] := Take; 1508 inc(TestReport.Working, Take);1522 Inc(TestReport.Working, Take); 1509 1523 with Hierarchy[iH, Take] do 1510 1524 begin 1511 inc(TestReport.FoodRep, Food);1512 inc(ProdBeforeBoost, Prod);1513 inc(TestReport.Trade, Trade);1514 end; 1515 inc(iH);1516 end; 1517 1518 assert((TestReport.Working >= MinWorking) and1525 Inc(TestReport.FoodRep, Food); 1526 Inc(ProdBeforeBoost, Prod); 1527 Inc(TestReport.Trade, Trade); 1528 end; 1529 Inc(iH); 1530 end; 1531 1532 Assert((TestReport.Working >= MinWorking) and 1519 1533 (TestReport.Working <= MaxWorking)); 1520 1534 if (TestReport.FoodRep >= MinFood) and (ProdBeforeBoost >= MinProd) then 1521 1535 begin 1522 SplitTrade(TestReport.Trade, RW[ p].TaxRate, RW[p].LuxRate,1536 SplitTrade(TestReport.Trade, RW[P].TaxRate, RW[P].LuxRate, 1523 1537 TestReport.Working, CityReportEx.TradeProcessing, 1524 1538 TestReport.Corruption, TestReport.Tax, TestReport.Lux, … … 1529 1543 TestReport.Deployed >= Size then 1530 1544 begin // city is not in disorder -- evaluate combination 1531 inc(count);1545 Inc(count); 1532 1546 if (MinProd < WantedProd) and (ProdBeforeBoost > MinProd) then 1533 1547 begin // no combination reached wanted prod yet … … 1577 1591 then 1578 1592 begin 1579 inc(Output[oTax], Output[oFood]);1593 Inc(Output[oTax], Output[oFood]); 1580 1594 Output[oFood] := 0; 1581 1595 end; … … 1589 1603 if NeedRare > 0 then 1590 1604 begin 1591 RareOK := false;1605 RareOK := False; 1592 1606 for iH := 0 to nHierarchy - 1 do 1593 1607 if Hierarchy[iH, nSelection[iH]].V21 and RareTiles <> 0 then 1594 RareOK := true;1608 RareOK := True; 1595 1609 if not RareOK then 1596 1610 TestReport.ProdRep := TestReport.Support; … … 1599 1613 if ProdToTax then 1600 1614 begin 1601 inc(Output[oTax], Output[oProd]);1615 Inc(Output[oTax], Output[oProd]); 1602 1616 Output[oProd] := 0; 1603 1617 end; 1604 1618 end; 1605 1619 1606 NeedStep2 := false;1620 NeedStep2 := False; 1607 1621 Value := 0; 1608 for i:= oFood to oScience do1609 if ValueFormula_Multiply[ i] then1610 NeedStep2 := true1622 for I := oFood to oScience do 1623 if ValueFormula_Multiply[I] then 1624 NeedStep2 := True 1611 1625 else 1612 Value := Value + ValueFormula_Weight[ i] * Output[i];1626 Value := Value + ValueFormula_Weight[I] * Output[I]; 1613 1627 if NeedStep2 then 1614 1628 begin 1615 1629 if Value > 0 then 1616 1630 Value := ln(Value) + 123; 1617 for i:= oFood to oScience do1618 if ValueFormula_Multiply[ i] and (Output[i] > 0) then1619 Value := Value + ValueFormula_Weight[ i] *1620 (ln(Output[ i]) + 123);1631 for I := oFood to oScience do 1632 if ValueFormula_Multiply[I] and (Output[I] > 0) then 1633 Value := Value + ValueFormula_Weight[I] * 1634 (ln(Output[I]) + 123); 1621 1635 end; 1622 1636 … … 1629 1643 for iH := 0 to nHierarchy - 1 do 1630 1644 begin 1631 inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);1632 inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);1645 Inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21); 1646 Inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue); 1633 1647 end; 1634 IsBest := true;1648 IsBest := True; 1635 1649 if (SuperPlus = 0) and (ValuePlus = 0.0) then 1636 1650 begin 1637 1651 SubPlus := SubValue - BestSubValue; 1638 1652 if SubPlus < 0 then 1639 IsBest := false1653 IsBest := False 1640 1654 else if SubPlus = 0 then 1641 1655 begin 1642 assert(TestTiles <> BestTiles);1656 Assert(TestTiles <> BestTiles); 1643 1657 IsBest := TestTiles > BestTiles 1644 1658 end … … 1654 1668 TestReport.Lux shr 1; 1655 1669 Advice.CityReport := TestReport; 1656 end 1657 end // if (SuperPlus>0) or (ValuePlus>=0.0)1658 end // if SuperPlus>=01659 end 1670 end; 1671 end; // if (SuperPlus>0) or (ValuePlus>=0.0) 1672 end; // if SuperPlus>=0 1673 end; 1660 1674 end; 1661 1675 … … 1665 1679 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1666 1680 begin 1667 dec(TestReport.FoodRep, Food);1668 dec(ProdBeforeBoost, Prod);1669 dec(TestReport.Trade, Trade);1670 end; 1671 inc(nSelection[iH_Switch]);1672 inc(TestReport.Working);1681 Dec(TestReport.FoodRep, Food); 1682 Dec(ProdBeforeBoost, Prod); 1683 Dec(TestReport.Trade, Trade); 1684 end; 1685 Inc(nSelection[iH_Switch]); 1686 Inc(TestReport.Working); 1673 1687 if (nSelection[iH_Switch] <= nTile[iH_Switch]) and 1674 1688 (TestReport.Working <= MaxWorking) then … … 1676 1690 with Hierarchy[iH_Switch, nSelection[iH_Switch]] do 1677 1691 begin 1678 inc(TestReport.FoodRep, Food);1679 inc(ProdBeforeBoost, Prod);1680 inc(TestReport.Trade, Trade);1692 Inc(TestReport.FoodRep, Food); 1693 Inc(ProdBeforeBoost, Prod); 1694 Inc(TestReport.Trade, Trade); 1681 1695 end; 1682 break;1683 end; 1684 dec(TestReport.Working, nSelection[iH_Switch]);1696 Break; 1697 end; 1698 Dec(TestReport.Working, nSelection[iH_Switch]); 1685 1699 nSelection[iH_Switch] := 0; 1686 inc(iH_Switch);1700 Inc(iH_Switch); 1687 1701 until iH_Switch = nHierarchy; 1688 1702 until iH_Switch = nHierarchy; // everything tested -- done 1689 1703 end; 1690 assert(BestSuperValue > 0); // advice should always be possible1704 Assert(BestSuperValue > 0); // advice should always be possible 1691 1705 Advice.Tiles := BestTiles; 1692 1706 Advice.CityReport.HypoTiles := BestTiles; 1693 end; // GetCityTileAdvice1707 end; 1694 1708 1695 1709 { … … 1699 1713 procedure InitGame; 1700 1714 var 1701 p, i, mixTownGuard: integer;1715 P, I, mixTownGuard: Integer; 1702 1716 begin 1703 1717 MaxDist := Distance(0, MapSize - lx shr 1); 1704 for p:= 0 to nPl - 1 do1705 if (1 shl pand GAlive <> 0) then1706 with RW[ p] do1718 for P := 0 to nPl - 1 do 1719 if (1 shl P and GAlive <> 0) then 1720 with RW[P] do 1707 1721 begin // initialize capital 1708 1722 mixTownGuard := 0; 1709 1723 while Model[mixTownGuard].Kind <> mkSpecial_TownGuard do 1710 inc(mixTownGuard);1724 Inc(mixTownGuard); 1711 1725 with City[0] do 1712 1726 begin 1713 1727 Built[imPalace] := 1; 1714 1728 Size := 4; 1715 for i:= 2 to Size do1716 AddBestCityTile( p, 0);1729 for I := 2 to Size do 1730 AddBestCityTile(P, 0); 1717 1731 Project := mixTownGuard; 1718 1732 end; -
branches/highdpi/CmdList.pas
r361 r465 5 5 6 6 uses 7 Classes ;7 Classes, SysUtils, Math; 8 8 9 9 const 10 10 MaxDataSize = 1024; 11 CommandDataElementSize = 4; 12 CommandDataElementCountMask = $F; 13 CommandDataMaxSize = CommandDataElementSize * CommandDataElementCountMask; 11 14 12 15 type … … 24 27 constructor Create; 25 28 destructor Destroy; override; 26 procedure Get(var Command, Player, Subject: integer; var Data: pointer);27 procedure GetDataChanges(Data: pointer; DataSize: integer);28 procedure Put(Command, Player, Subject: integer; Data: pointer);29 procedure PutDataChanges(Command, Player: integer;30 OldData, NewData: pointer; DataSize: integer);31 procedure LoadFromFile(const f: TFileStream);32 procedure SaveToFile(const f: TFileStream);33 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); 34 37 procedure Cut; 35 function Progress: integer;38 function Progress: Integer; 36 39 private 37 LogAlloc: integer; { allocated size of LogData in bytes }40 LogAlloc: Integer; { allocated size of LogData in bytes } 38 41 LogData: ^TLogData; 39 42 FState: TCmdListState; 40 procedure PutData(Data: pointer; Length: integer);43 procedure PutData(Data: Pointer; Length: Integer); 41 44 procedure CompleteMoveCode; 42 45 public … … 44 47 end; 45 48 49 function CommandWithData(Command: Integer; DataSize: Byte): Integer; 50 51 resourcestring 52 SCommandDataSizeError = 'Command data size %d out of range (0-%d).'; 53 54 46 55 implementation 47 56 … … 53 62 54 63 type 55 TData = array [0 ..MaxDataSize - 1] of Cardinal;64 TData = array [0..MaxDataSize - 1] of Cardinal; 56 65 PData = ^TData; 66 67 function CommandWithData(Command: Integer; DataSize: Byte): Integer; 68 var 69 DataElementCount: Byte; 70 begin 71 if DataSize > CommandDataMaxSize then 72 raise Exception.Create(Format(SCommandDataSizeError, [DataSize, CommandDataMaxSize])); 73 DataElementCount := Ceil(DataSize / CommandDataElementSize); 74 Result := Command or (DataElementCount and CommandDataElementCountMask); 75 end; 57 76 58 77 constructor TCmdList.Create; … … 73 92 end; 74 93 75 procedure TCmdList.Get(var Command, Player, Subject: integer; var Data: pointer);94 procedure TCmdList.Get(var Command, Player, Subject: Integer; var Data: Pointer); 76 95 var 77 96 DirCode: Cardinal; … … 108 127 else 109 128 begin 110 code := Cardinal((@LogData[FState.LoadPos])^);111 if code and 3 = 0 then129 Code := Cardinal((@LogData[FState.LoadPos])^); 130 if Code and 3 = 0 then 112 131 begin // non-clientex command 113 Command := code shr 2 and $3FFF + sExecute;114 Player := code shr 16 and $F;115 Subject := code shr 20 and $FFF;116 inc(FState.LoadPos, 4);117 end 118 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 119 138 begin // clientex command 120 Command := code shr 3 and $FFFF;121 Player := code shr 19 and $F;139 Command := Code shr 3 and $FFFF; 140 Player := Code shr 19 and $F; 122 141 Subject := 0; 123 inc(FState.LoadPos, 3);142 Inc(FState.LoadPos, 3); 124 143 end 125 144 else 126 145 begin // move command shortcut 127 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 128 147 begin 129 FState.LoadMoveCode := code and $FF;130 inc(FState.LoadPos);148 FState.LoadMoveCode := Code and $FF; 149 Inc(FState.LoadPos); 131 150 end 132 151 else 133 152 begin 134 FState.LoadMoveCode := code and $FFFFFF;135 inc(FState.LoadPos, 3);153 FState.LoadMoveCode := Code and $FFFFFF; 154 Inc(FState.LoadPos, 3); 136 155 end; 137 156 Get(Command, Player, Subject, Data); … … 139 158 end; 140 159 141 if Command and $F= 0 then160 if Command and CommandDataElementCountMask = 0 then 142 161 Data := nil 143 162 else 144 163 begin 145 164 Data := @LogData[FState.LoadPos]; 146 inc(FState.LoadPos, Command and $F * 4);147 end; 148 end; 149 end; 150 151 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); 152 171 var 153 b0, b1: integer;172 b0, b1: Integer; 154 173 Map0, Map1: Cardinal; 155 174 begin 156 175 Map0 := Cardinal((@LogData[FState.LoadPos])^); 157 inc(FState.LoadPos, 4);176 Inc(FState.LoadPos, 4); 158 177 b0 := 0; 159 178 while Map0 > 0 do begin 160 179 if Map0 and 1 <> 0 then begin 161 180 Map1 := Cardinal((@LogData[FState.LoadPos])^); 162 inc(FState.LoadPos, 4);181 Inc(FState.LoadPos, 4); 163 182 for b1 := 0 to 31 do 164 183 if 1 shl b1 and Map1 <> 0 then begin 165 184 if b0 * 32 + b1 < DataSize then 166 185 PData(Data)[b0 * 32 + b1] := Cardinal((@LogData[FState.LoadPos])^); 167 inc(FState.LoadPos, 4);186 Inc(FState.LoadPos, 4); 168 187 end; 169 188 end; 170 inc(b0);189 Inc(b0); 171 190 Map0 := Map0 shr 1; 172 191 end; 173 192 end; 174 193 175 procedure TCmdList.Put(Command, Player, Subject: integer; Data: pointer);194 procedure TCmdList.Put(Command, Player, Subject: Integer; Data: Pointer); 176 195 var 177 DirCode, code: Cardinal;196 DirCode, Code: Cardinal; 178 197 begin 179 198 if Command and $FC00 = sMoveUnit then … … 190 209 end; 191 210 if Subject = FState.LastMovingUnit then 192 code := 1 + DirCode shl 1193 else 194 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; 195 214 if FState.MoveCode = 0 then 196 FState.MoveCode := code215 FState.MoveCode := Code 197 216 else if FState.MoveCode and 1 = 1 then 198 217 begin // FM + this 199 FState.MoveCode := FState.MoveCode + code shl 4;200 if code and 1 = 1 then218 FState.MoveCode := FState.MoveCode + Code shl 4; 219 if Code and 1 = 1 then 201 220 PutData(@FState.MoveCode, 1) // FM + FM 202 221 else … … 204 223 FState.MoveCode := 0; 205 224 end 206 else if code and 1 = 1 then225 else if Code and 1 = 1 then 207 226 begin // M + FM 208 FState.MoveCode := FState.MoveCode + code shl 18;227 FState.MoveCode := FState.MoveCode + Code shl 18; 209 228 PutData(@FState.MoveCode, 3); 210 229 FState.MoveCode := 0; … … 213 232 begin 214 233 PutData(@FState.MoveCode, 3); 215 FState.MoveCode := code;234 FState.MoveCode := Code; 216 235 end; 217 236 FState.LastMovingUnit := Subject; … … 222 241 if Command >= cClientEx then 223 242 begin 224 code := 2 + Command shl 3 + Player shl 19;225 PutData(@ code, 3);226 end 227 else 228 begin 229 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 + 230 249 Cardinal(Subject) shl 20; 231 PutData(@ code, 4);232 end; 233 end; 234 if Command and $F<> 0 then235 PutData(Data, Command and $F * 4);236 end; 237 238 procedure TCmdList.PutDataChanges(Command, Player: integer;239 OldData, NewData: pointer; DataSize: integer);250 PutData(@Code, 4); 251 end; 252 end; 253 if Command and CommandDataElementCountMask <> 0 then 254 PutData(Data, Command and CommandDataElementCountMask * CommandDataElementSize); 255 end; 256 257 procedure TCmdList.PutDataChanges(Command, Player: Integer; 258 OldData, NewData: Pointer; DataSize: Integer); 240 259 var 241 MapPos, LogPos, b0, b1, RowEnd: integer;242 Map0, Map1, code: Cardinal;260 MapPos, LogPos, b0, b1, RowEnd: Integer; 261 Map0, Map1, Code: Cardinal; 243 262 begin 244 263 if DataSize <= 0 then 245 exit;264 Exit; 246 265 if DataSize > MaxDataSize then 247 266 DataSize := MaxDataSize; … … 254 273 if LogPos + 4 * 32 > LogAlloc then 255 274 begin 256 inc(LogAlloc, LogGrow);275 Inc(LogAlloc, LogGrow); 257 276 ReallocMem(LogData, LogAlloc); 258 277 end; … … 268 287 begin 269 288 Cardinal((@LogData[LogPos])^) := PData(NewData)[b1]; 270 inc(LogPos, 4);271 inc(Map1, $80000000);289 Inc(LogPos, 4); 290 Inc(Map1, $80000000); 272 291 end; 273 292 end; … … 277 296 Cardinal((@LogData[MapPos])^) := Map1; 278 297 MapPos := LogPos; 279 inc(LogPos, 4);280 inc(Map0, $80000000);298 Inc(LogPos, 4); 299 Inc(Map0, $80000000); 281 300 end; 282 301 end; 283 302 if Map0 = 0 then 284 exit; // no changes303 Exit; // no changes 285 304 286 305 Map0 := Map0 shr (31 - (DataSize - 1) div 32); 287 306 Cardinal((@LogData[FState.nLog + 4])^) := Map0; 288 code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;289 Cardinal((@LogData[FState.nLog])^) := code;307 Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16; 308 Cardinal((@LogData[FState.nLog])^) := Code; 290 309 FState.nLog := MapPos; 291 310 end; 292 311 293 procedure TCmdList.PutData(Data: pointer; Length: integer);312 procedure TCmdList.PutData(Data: Pointer; Length: Integer); 294 313 begin 295 314 if FState.nLog + Length > LogAlloc then 296 315 begin 297 inc(LogAlloc, LogGrow);316 Inc(LogAlloc, LogGrow); 298 317 ReallocMem(LogData, LogAlloc); 299 318 end; 300 move(Data^, LogData[FState.nLog], Length);301 inc(FState.nLog, Length);319 Move(Data^, LogData[FState.nLog], Length); 320 Inc(FState.nLog, Length); 302 321 end; 303 322 … … 314 333 end; 315 334 316 procedure TCmdList.LoadFromFile(const f: TFileStream);317 begin 318 f.read(FState.nLog, 4);335 procedure TCmdList.LoadFromFile(const F: TFileStream); 336 begin 337 F.Read(FState.nLog, 4); 319 338 LogData := nil; 320 339 LogAlloc := ((FState.nLog + 2) div LogGrow + 1) * LogGrow; 321 340 ReallocMem(LogData, LogAlloc); 322 f.read(LogData^, FState.nLog);341 F.Read(LogData^, FState.nLog); 323 342 FState.LoadPos := 0; 324 343 end; 325 344 326 procedure TCmdList.SaveToFile(const f: TFileStream);345 procedure TCmdList.SaveToFile(const F: TFileStream); 327 346 begin 328 347 CompleteMoveCode; 329 f.write(FState.nLog, 4);330 f.write(LogData^, FState.nLog);331 end; 332 333 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; 334 353 const OldState: TCmdListState); 335 354 begin 336 355 CompleteMoveCode; 337 f.write(FState.nLog, 4);338 f.Position := f.Position + OldState.nLog;339 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); 340 359 end; 341 360 … … 345 364 end; 346 365 347 function TCmdList.Progress: integer;366 function TCmdList.Progress: Integer; 348 367 begin 349 368 if (FState.LoadPos = FState.nLog) and (FState.LoadMoveCode = 0) then 350 result := 1000 // loading complete369 Result := 1000 // loading complete 351 370 else if FState.nLog > 1 shl 20 then 352 result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)371 Result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8) 353 372 else 354 result := FState.LoadPos * 999 div FState.nLog;373 Result := FState.LoadPos * 999 div FState.nLog; 355 374 end; 356 375 … … 360 379 Byte3 Byte2 Byte1 Byte0 361 380 ssssssss sssspppp cccccccc cccccc00 362 ( c = Command-sExecute, p = Player, s= Subject)381 (C = Command-sExecute, P = Player, S = Subject) 363 382 364 383 ClientEx-Command: 365 384 Byte2 Byte1 Byte0 366 385 0ppppccc cccccccc ccccc010 367 ( c = Command, p= Player)386 (C = Command, P = Player) 368 387 369 388 Single Move: 370 389 Byte2 Byte1 Byte0 371 390 000000ss ssssssss ssaaa110 372 ( a = Direction, s= Subject)391 (A = Direction, S = Subject) 373 392 374 393 Move + Follow Move: 375 394 Byte2 Byte1 Byte0 376 395 00bbb1ss ssssssss ssaaa110 377 ( a = Direction 1, s = Subject 1, b= Direction 2)396 (A = Direction 1, S = Subject 1, B = Direction 2) 378 397 379 398 Follow Move + Move: 380 399 Byte2 Byte1 Byte0 381 400 00ssssss ssssssbb b110aaa1 382 ( a = Direction 1, b = Direction 2, s= Subject 2)401 (A = Direction 1, B = Direction 2, S = Subject 2) 383 402 384 403 Single Follow Move: 385 404 Byte0 386 405 0000aaa1 387 ( a= Direction)406 (A = Direction) 388 407 389 408 Double Follow Move: 390 409 Byte0 391 410 bbb1aaa1 392 ( a = Direction 1, b= Direction 2)411 (A = Direction 1, B = Direction 2) 393 412 } 394 413 -
branches/highdpi/Database.pas
r349 r465 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 174 implementation … … 179 180 180 181 var 181 UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }182 183 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); 184 185 var 185 186 I: Integer; 186 187 begin 187 188 for I := 0 to Count - 1 do 188 x[I] := x[I] and Mask;189 end; 190 191 procedure CompactLists( p: integer);192 var 193 uix, uix1, cix: integer;194 {$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; 195 196 Radius: TVicinity21Loc; {$ENDIF} 196 197 begin 197 with RW[ p] do198 with RW[P] do 198 199 begin 199 200 // compact unit list … … 202 203 if Un[uix].Loc < 0 then 203 204 begin 204 dec(nUn);205 Dec(nUn); 205 206 Un[uix] := Un[nUn]; { replace removed unit by last } 206 207 if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then … … 211 212 end 212 213 else 213 inc(uix);214 Inc(uix); 214 215 215 216 // compact city list … … 218 219 if City[cix].Loc < 0 then 219 220 begin 220 dec(nCity);221 Dec(nCity); 221 222 City[cix] := City[nCity]; { replace city by last } 222 223 for uix1 := 0 to nUn - 1 do … … 226 227 end 227 228 else 228 inc(cix);229 Inc(cix); 229 230 230 231 // compact enemy city list … … 233 234 if EnemyCity[cix].Loc < 0 then 234 235 begin 235 dec(nEnemyCity);236 Dec(nEnemyCity); 236 237 EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last } 237 238 end 238 239 else 239 inc(cix);240 Inc(cix); 240 241 241 242 {$IFOPT O-} … … 246 247 for V21 := 1 to 26 do 247 248 if Tiles and (1 shl V21) <> 0 then 248 assert(UsedByCity[Radius[V21]] = Loc);249 end 249 Assert(UsedByCity[Radius[V21]] = Loc); 250 end; 250 251 {$ENDIF} 251 252 end; 252 end; // CompactLists253 end; 253 254 254 255 { … … 256 257 ____________________________________________________________________ 257 258 } 258 function TechBaseCost(nTech, diff: integer): integer;259 var 260 c0: single;259 function TechBaseCost(nTech, diff: Integer): Integer; 260 var 261 c0: Single; 261 262 begin 262 263 c0 := TechFormula_M[diff] * (nTech + 4) * 263 264 exp((nTech + 4) / TechFormula_D[diff]); 264 265 if c0 >= $10000000 then 265 result := $10000000266 Result := $10000000 266 267 else 267 result := trunc(c0)268 end; 269 270 function TechCost( p: integer): integer;271 begin 272 with RW[ p] do273 begin 274 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]); 275 276 if ResearchTech >= 0 then 276 277 if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then 277 result := result shr 1278 Result := Result shr 1 278 279 else if ResearchTech in FutureTech then 279 280 if Government = gFuture then 280 result := result * 2281 Result := Result * 2 281 282 else 282 result := result * 4;283 end 284 end; 285 286 procedure SetModelFlags(var m: TModel);287 begin 288 m.Flags := 0;289 if ( m.Domain = dGround) and (m.Kind <> mkDiplomat) then290 m.Flags := m.Flags or mdZOC;291 if ( m.Kind = mkDiplomat) or (m.Attack + m.Cap[mcBombs] = 0) then292 m.Flags := m.Flags or mdCivil;293 if ( m.Cap[mcOver] > 0) or (m.Domain = dSea) and (m.Weight >= 6) then294 m.Flags := m.Flags or mdDoubleSupport;295 end; 296 297 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); 298 299 { calculate attack, defense, cost... of a model by features } 299 300 var 300 i: integer;301 begin 302 with mdo301 I: Integer; 302 begin 303 with M do 303 304 begin 304 305 Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength; … … 311 312 Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines]; 312 313 if Cap[mcNP] = 0 then 313 inc(Speed, 100 * Cap[mcSE]);314 Inc(Speed, 100 * Cap[mcSE]); 314 315 end; 315 316 dAir: … … 317 318 end; 318 319 Cost := 0; 319 for i:= 0 to nFeature - 1 do320 if 1 shl Domain and Feature[ i].Domains <> 0 then321 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); 322 323 Cost := Cost * MCost; 323 324 Weight := 0; 324 for i:= 0 to nFeature - 1 do325 if 1 shl Domain and Feature[ i].Domains <> 0 then326 if (Domain = dGround) and ( i= mcDefense) then327 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) 328 329 else 329 inc(Weight, Cap[i] * Feature[i].Weight);330 end; 331 SetModelFlags( m);332 end; 333 334 procedure CheckSpecialModels( p, pre: integer);335 var 336 i, mix1: integer;337 HasAlready: boolean;338 begin 339 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 - 340 341 1 do { check whether new special model available } 341 if (SpecialModelPreq[ i] = pre) and (RW[p].nModel < nmmax) then342 begin 343 HasAlready := false;344 for mix1 := 0 to RW[ p].nModel - 1 do345 if (RW[ p].Model[mix1].Kind = SpecialModel[i].Kind) and346 (RW[ p].Model[mix1].Attack = SpecialModel[i].Attack) and347 (RW[ p].Model[mix1].Speed = SpecialModel[i].Speed) then348 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; 349 350 if not HasAlready then 350 351 begin 351 RW[ p].Model[RW[p].nModel] := SpecialModel[i];352 SetModelFlags(RW[ p].Model[RW[p].nModel]);353 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 354 355 begin 355 356 Status := 0; … … 358 359 Built := 0; 359 360 Lost := 0; 360 ID := p shl 12 + RW[p].nModel;361 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 362 363 Speed := 350; // old longboat 363 364 end; 364 inc(RW[p].nModel);365 end 366 end; 367 end; 368 369 procedure EnableDevModel( p: integer);370 begin 371 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 372 373 if nModel < nmmax then 373 374 begin … … 380 381 Built := 0; 381 382 Lost := 0; 382 ID := p shl 12 + nModel383 end; 384 inc(nModel);385 inc(Researched[p])386 end 387 end; 388 389 procedure SeeTech( p, ad: integer);390 begin 391 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [ p, ad]); {$ENDIF}392 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; 393 394 // inc(nTech[p]); 394 inc(Researched[p])395 Inc(Researched[P]); 395 396 end; 396 397 397 398 procedure FreeSlaves; 398 399 var 399 p1, uix: integer;400 p1, uix: Integer; 400 401 begin 401 402 for p1 := 0 to nPl - 1 do … … 403 404 for uix := 0 to RW[p1].nUn - 1 do 404 405 if RW[p1].Model[RW[p1].Un[uix].mix].Kind = mkSlaves then 405 RW[p1].Un[uix].Job := jNone 406 end; 407 408 procedure DiscoverTech( p, ad: integer);409 410 procedure TellAboutKeyTech( p, Source: integer);406 RW[p1].Un[uix].Job := jNone; 407 end; 408 409 procedure DiscoverTech(P, ad: Integer); 410 411 procedure TellAboutKeyTech(P, Source: Integer); 411 412 var 412 i, p1: integer;413 begin 414 for i:= 1 to 3 do415 if ad = AgePreq[ i] then413 I, p1: Integer; 414 begin 415 for I := 1 to 3 do 416 if ad = AgePreq[I] then 416 417 for p1 := 0 to nPl - 1 do 417 if (p1 <> p) and ((GAlive or GWatching) and (1 shl p1) <> 0) then418 RW[p1].EnemyReport[ p].Tech[ad] := Source;419 end; 420 421 var 422 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; 423 424 begin 424 425 if ad in FutureTech then 425 426 begin 426 if RW[ p].Tech[ad] < tsApplicable then427 RW[ p].Tech[ad] := 1427 if RW[P].Tech[ad] < tsApplicable then 428 RW[P].Tech[ad] := 1 428 429 else 429 inc(RW[p].Tech[ad]);430 Inc(RW[P].Tech[ad]); 430 431 if ad <> futResearchTechnology then 431 inc(nTech[p], 2);432 inc(Researched[p], 8);433 exit;434 end; 435 436 if RW[ p].Tech[ad] = tsSeen then437 begin 438 inc(nTech[p]);439 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]); 440 441 end 441 442 else 442 443 begin 443 inc(nTech[p], 2);444 inc(Researched[p], 2);445 end; 446 RW[ p].Tech[ad] := tsResearched;447 TellAboutKeyTech( p, tsResearched);448 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); 449 450 if ad = adScience then 450 ResourceMask[ p] := ResourceMask[p] or fSpecial2;451 ResourceMask[P] := ResourceMask[P] or fSpecial2; 451 452 if ad = adMassProduction then 452 ResourceMask[ p] := ResourceMask[p] or fModern;453 454 for i:= 0 to nWonder - 1 do { check whether wonders expired }455 if (GWonder[ i].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and456 (Imp[ i].Expiration = ad) then457 begin 458 GWonder[ i].EffectiveOwner := -1;459 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 460 461 FreeSlaves; 461 462 end; 462 463 end; 463 464 464 procedure CheckExpiration(Wonder: integer);465 procedure CheckExpiration(Wonder: Integer); 465 466 // GWonder[Wonder].EffectiveOwner must be set before! 466 467 var 467 p: integer;468 P: Integer; 468 469 begin 469 470 if (Imp[Wonder].Expiration >= 0) and 470 471 (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) then 471 for p:= 0 to nPl - 1 do // check if already expired472 if (1 shl pand GAlive <> 0) and473 (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 474 475 begin 475 476 GWonder[Wonder].EffectiveOwner := -1; 476 477 if Wonder = woPyramids then 477 FreeSlaves 478 end 478 FreeSlaves; 479 end; 479 480 end; 480 481 … … 483 484 ____________________________________________________________________ 484 485 } 485 function dLoc(Loc, dx, dy: integer): integer;486 function dLoc(Loc, dx, dy: Integer): Integer; 486 487 { relative location, dx in hor and dy in ver direction from Loc } 487 488 var 488 y0: integer;489 y0: Integer; 489 490 begin 490 491 if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then 491 492 raise Exception.Create('Relative location error'); 492 assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));493 Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0)); 493 494 y0 := Loc div lx; 494 result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);495 if ( result < 0) or (result >= MapSize) then496 result := -1;497 end; 498 499 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); 500 501 begin 501 502 dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) - … … 504 505 end; 505 506 506 function Distance(Loc0, Loc1: integer): integer;507 var 508 dx, dy: integer;507 function Distance(Loc0, Loc1: Integer): Integer; 508 var 509 dx, dy: Integer; 509 510 begin 510 511 dxdy(Loc0, Loc1, dx, dy); 511 512 dx := abs(dx); 512 513 dy := abs(dy); 513 result := dx + dy + abs(dx - dy) shr 1;514 end; 515 516 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);517 var 518 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; 519 520 begin 520 521 lx0 := lx; // put in register! … … 526 527 VicinityLoc[5] := Loc0 - lx0 * 2; 527 528 VicinityLoc[7] := Loc0 + 1; 528 inc(Loc0, y0);529 Inc(Loc0, y0); 529 530 VicinityLoc[0] := Loc0 + lx0; 530 531 VicinityLoc[2] := Loc0 + lx0 - 1; … … 537 538 if x0 = 0 then 538 539 begin 539 inc(VicinityLoc[3], lx0);540 Inc(VicinityLoc[3], lx0); 540 541 if y0 = 0 then 541 542 begin 542 inc(VicinityLoc[2], lx0);543 inc(VicinityLoc[4], lx0);544 end 545 end 543 Inc(VicinityLoc[2], lx0); 544 Inc(VicinityLoc[4], lx0); 545 end; 546 end; 546 547 end 547 548 else 548 549 begin 549 dec(VicinityLoc[7], lx0);550 Dec(VicinityLoc[7], lx0); 550 551 if y0 = 1 then 551 552 begin 552 dec(VicinityLoc[0], lx0);553 dec(VicinityLoc[6], lx0);554 end 555 end; 556 end; 557 558 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);559 var 560 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;561 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; 562 563 begin 563 564 y0 := Loc0 div lx; … … 565 566 xCompSwitch := xComp0 - 1 + y0 and 1; 566 567 if xComp0 < 0 then 567 inc(xComp0, lx);568 Inc(xComp0, lx); 568 569 if xCompSwitch < 0 then 569 inc(xCompSwitch, lx);570 Inc(xCompSwitch, lx); 570 571 xCompSwitch := xCompSwitch xor xComp0; 571 572 yComp := lx * (y0 - 3); … … 582 583 else 583 584 dst^ := -1; 584 inc(xComp);585 Inc(xComp); 585 586 if xComp >= lx then 586 dec(xComp, lx);587 inc(dst);587 Dec(xComp, lx); 588 Inc(dst); 588 589 bit := bit shl 1; 589 590 end; 590 inc(yComp, lx);591 Inc(yComp, lx); 591 592 end; 592 593 end; … … 597 598 } 598 599 var 599 primitive: integer;600 StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }600 primitive: Integer; 601 StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates } 601 602 Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation } 602 ElCount: array [Byte] of integer; { count of elevation occurance }603 ElCount: array [Byte] of Integer; { count of elevation occurance } 603 604 604 605 procedure CalculatePrimitive; 605 606 var 606 i, j: integer;607 I, J: Integer; 607 608 begin 608 609 primitive := 1; 609 i:= 2;610 while i * i<= MapSize + 1 do // test whether prime611 begin 612 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 613 614 primitive := 0; 614 inc(i)615 Inc(I); 615 616 end; 616 617 617 618 if primitive > 0 then 618 619 repeat 619 inc(primitive);620 i:= 1;621 j:= 0;620 Inc(primitive); 621 I := 1; 622 J := 0; 622 623 repeat 623 inc(j);624 i := i * primitive mod (MapSize + 1)625 until ( i = 1) or (j= MapSize + 1);626 until j= MapSize;627 end; 628 629 function MapGeneratorAvailable: boolean;630 begin 631 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); 632 633 end; 633 634 634 635 procedure CreateElevation; 635 636 const 636 d= 64;637 D = 64; 637 638 Smooth = 0.049; { causes low amplitude of short waves } 638 639 Detail = 0.095; { causes short period of short waves } … … 641 642 642 643 var 643 sa, ca, f1, f2: array [1 .. d] of single;644 imerge, x, y: integer;645 v, maxv: single;646 647 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 } 648 649 var 649 i: integer;650 begin 651 result := 0;652 for i := 1 to ddo653 result := result + sin(f1[i] * ((x * 2 + y and 1) * sa[i] + y* 1.5 *654 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]; 655 656 { x values effectively multiplied with 2 to get 2 horizantal periods 656 657 of the prime waves } … … 658 659 659 660 begin 660 for x := 1 to ddo { prepare formula parameters }661 begin 662 {$IFNDEF SCR} if x= 1 then663 v:= pi / 2 { first wave goes horizontal }664 else {$ENDIF} v:= DelphiRandom * 2 * pi;665 sa[ x] := sin(v) / lx;666 ca[ x] := cos(v) / ly;667 f1[ x] := 2 * pi * exp(Detail * (x- 1));668 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); 669 670 end; 670 671 … … 672 673 FillChar(ElCount, SizeOf(ElCount), 0); 673 674 maxv := 0; 674 for x:= 0 to lx - 1 do675 for y:= 0 to ly - 1 do676 begin 677 v := Value(x, y);678 if x* 2 < imerge then679 v := (x * 2 * v + (imerge - x * 2) * Value(x + lx, y)) / imerge;680 v := v - sqr(sqr(2 * y/ ly - 1)); { soft cut at poles }681 if v> maxv then682 maxv := v;683 684 if v< -4 then685 Elevation[ x + lx * y] := 0686 else if v> 8.75 then687 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 688 689 else 689 Elevation[ x + lx * y] := Round((v+ 4) * 20);690 inc(ElCount[Elevation[x + lx * y]])690 Elevation[X + lx * Y] := Round((V + 4) * 20); 691 Inc(ElCount[Elevation[X + lx * Y]]); 691 692 end; 692 693 end; … … 694 695 procedure FindContinents; 695 696 696 procedure ReplaceCont( a, b, Stop: integer);697 procedure ReplaceCont(A, B, Stop: Integer); 697 698 { replace continent name a by b } 698 699 // make sure always continent[loc]<=loc 699 700 var 700 i: integer;701 begin 702 if a < bthen703 begin 704 i := a;705 a := b;706 b := i707 end; 708 if a > bthen709 for i := ato Stop do710 if Continent[ i] = athen711 Continent[ i] := b712 end; 713 714 var 715 x, y, Loc, Wrong: integer;716 begin 717 for y:= 1 to ly - 2 do718 for x:= 0 to lx - 1 do719 begin 720 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; 721 722 Continent[Loc] := -1; 722 723 if RealMap[Loc] and fTerrain >= fGrass then 723 724 begin 724 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 725 726 Continent[Loc] := Continent[Loc - 2 * lx]; 726 if ( x - 1 + y and 1 >= 0) and (y- 1 >= 1) and727 (RealMap[Loc - 1 + yand 1 - lx] and fTerrain >= fGrass) then728 Continent[Loc] := Continent[Loc - 1 + yand 1 - lx];729 if ( x + y and 1 < lx) and (y- 1 >= 1) and730 (RealMap[Loc + yand 1 - lx] and fTerrain >= fGrass) then731 Continent[Loc] := Continent[Loc + yand 1 - lx];732 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 733 734 if Continent[Loc] = -1 then 734 735 Continent[Loc] := Continent[Loc - 1] … … 736 737 ReplaceCont(Continent[Loc - 1], Continent[Loc], Loc); 737 738 if Continent[Loc] = -1 then 738 Continent[Loc] := Loc 739 end 739 Continent[Loc] := Loc; 740 end; 740 741 end; 741 742 742 743 { connect continents due to round earth } 743 for y:= 1 to ly - 2 do744 if RealMap[lx * y] and fTerrain >= fGrass then744 for Y := 1 to ly - 2 do 745 if RealMap[lx * Y] and fTerrain >= fGrass then 745 746 begin 746 747 Wrong := -1; 747 if RealMap[lx - 1 + lx * y] and fTerrain >= fGrass then748 Wrong := Continent[lx - 1 + lx * y];749 if ( y and 1 = 0) and (y- 1 >= 1) and750 (RealMap[lx - 1 + lx * ( y- 1)] and fTerrain >= fGrass) then751 Wrong := Continent[lx - 1 + lx * ( y- 1)];752 if ( y and 1 = 0) and (y+ 1 < ly - 1) and753 (RealMap[lx - 1 + lx * ( y+ 1)] and fTerrain >= fGrass) then754 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)]; 755 756 if Wrong >= 0 then 756 ReplaceCont(Wrong, Continent[lx * y], MapSize - 1)757 ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1); 757 758 end; 758 759 end; … … 762 763 // must be done after FindContinents 763 764 var 764 i, j, Cnt, x, y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,765 RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: integer;766 AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of integer;767 RareLoc: array [0 .. 11] of integer;768 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; 769 770 Adjacent: TVicinity8Loc; 770 771 begin … … 772 773 repeat 773 774 FillChar(AreaCount, SizeOf(AreaCount), 0); 774 for y:= 1 to ly - 2 do775 begin 776 yBlock := y* 5 div ly;777 if yBlock = ( y+ 1) * 5 div ly then778 for x:= 0 to lx - 1 do779 begin 780 xBlock := x* 8 div lx;781 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 782 783 begin 783 Loc0 := x + lx * y;784 Loc0 := X + lx * Y; 784 785 if RealMap[Loc0] and fTerrain >= fGrass then 785 786 begin … … 791 792 if (Loc1 >= 0) and (Loc1 < MapSize) and 792 793 (RealMap[Loc1] and fTerrain < fGrass) then 793 inc(Cnt); // count adjacent water794 Inc(Cnt); // count adjacent water 794 795 end; 795 796 if Cnt <= RareMaxWater then // inner land 796 797 begin 797 inc(AreaCount[xBlock, yBlock]);798 Inc(AreaCount[xBlock, yBlock]); 798 799 if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then 799 RareByArea[xBlock, yBlock] := Loc0 800 end 800 RareByArea[xBlock, yBlock] := Loc0; 801 end; 801 802 end; 802 803 end; 803 end 804 end; 804 805 end; 805 806 totalrare := 0; 806 for x:= 0 to 7 do807 for y:= 0 to 4 do808 if AreaCount[ x, y] > 0 then809 inc(totalrare);810 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); 811 812 until totalrare >= 12; 812 813 … … 814 815 begin // remove rarebyarea resources too close to each other 815 816 FillChar(RareAdjacent, SizeOf(RareAdjacent), 0); 816 for x:= 0 to 7 do817 for y:= 0 to 4 do818 if AreaCount[ x, y] > 0 then819 begin 820 if (AreaCount[( x + 1) mod 8, y] > 0) and821 (Continent[RareByArea[ x, y]] = Continent822 [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 823 824 begin 824 inc(RareAdjacent[x, y]);825 inc(RareAdjacent[(x + 1) mod 8, y]);825 Inc(RareAdjacent[X, Y]); 826 Inc(RareAdjacent[(X + 1) mod 8, Y]); 826 827 end; 827 if y< 4 then828 if Y < 4 then 828 829 begin 829 if (AreaCount[ x, y+ 1] > 0) and830 (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]]) 831 832 then 832 833 begin 833 inc(RareAdjacent[x, y]);834 inc(RareAdjacent[x, y+ 1]);834 Inc(RareAdjacent[X, Y]); 835 Inc(RareAdjacent[X, Y + 1]); 835 836 end; 836 if (AreaCount[( x + 1) mod 8, y+ 1] > 0) and837 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 1) mod 8,838 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 839 840 begin 840 inc(RareAdjacent[x, y]);841 inc(RareAdjacent[(x + 1) mod 8, y+ 1]);841 Inc(RareAdjacent[X, Y]); 842 Inc(RareAdjacent[(X + 1) mod 8, Y + 1]); 842 843 end; 843 if (AreaCount[( x + 7) mod 8, y+ 1] > 0) and844 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 7) mod 8,845 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 846 847 begin 847 inc(RareAdjacent[x, y]);848 inc(RareAdjacent[(x + 7) mod 8, y+ 1]);848 Inc(RareAdjacent[X, Y]); 849 Inc(RareAdjacent[(X + 7) mod 8, Y + 1]); 849 850 end; 850 end 851 end; 851 852 end; 852 853 xworst := 0; 853 854 yworst := 0; 854 855 Cnt := 0; 855 for x:= 0 to 7 do856 for y:= 0 to 4 do857 if AreaCount[ x, y] > 0 then858 begin 859 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]) 860 861 then 861 862 begin 862 xworst := x;863 yworst := y;864 Cnt := 1 863 xworst := X; 864 yworst := Y; 865 Cnt := 1; 865 866 end 866 else if (RareAdjacent[ x, y] = RareAdjacent[xworst, yworst]) then867 else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then 867 868 begin 868 inc(Cnt);869 Inc(Cnt); 869 870 if DelphiRandom(Cnt) = 0 then 870 871 begin 871 xworst := x;872 yworst := y;873 end 872 xworst := X; 873 yworst := Y; 874 end; 874 875 end; 875 876 end; 876 877 AreaCount[xworst, yworst] := 0; 877 dec(totalrare)878 Dec(totalrare); 878 879 end; 879 880 880 881 Cnt := 0; 881 for x:= 0 to 7 do882 for y:= 0 to 4 do883 if AreaCount[ x, y] > 0 then884 begin 885 RareLoc[Cnt] := RareByArea[ x, y];886 inc(Cnt)887 end; 888 for i:= 0 to 11 do889 begin 890 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 891 892 (fDesert or fDeadLands); 892 893 for dy := -1 to 1 do … … 894 895 if (dx + dy) and 1 = 0 then 895 896 begin 896 Loc1 := dLoc(RareLoc[ i], dx, dy);897 Loc1 := dLoc(RareLoc[I], dx, dy); 897 898 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then 898 899 RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills; 899 end 900 end; 901 for i:= 0 to 11 do902 for j:= 0 to 11 do903 Dist[ i, j] := Distance(RareLoc[i], RareLoc[j]);900 end; 901 end; 902 for I := 0 to 11 do 903 for J := 0 to 11 do 904 Dist[I, J] := Distance(RareLoc[I], RareLoc[J]); 904 905 905 906 ibest := 0; … … 909 910 begin 910 911 Cnt := 0; 911 for i:= 0 to 11 do912 if RareLoc[ i] >= 0 then913 for j:= 0 to 11 do914 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 915 916 if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then 916 917 begin 917 if Dist[ i, j] >= MinDist then918 if Dist[I, J] >= MinDist then 918 919 begin 919 inc(Cnt);920 Inc(Cnt); 920 921 if DelphiRandom(Cnt) = 0 then 921 922 begin 922 iBest := i;923 jbest := j924 end 925 end 923 iBest := I; 924 jbest := J; 925 end; 926 end; 926 927 end 927 else if (Cnt = 0) or (Dist[ i, j] > Dist[iBest, jbest]) then928 else if (Cnt = 0) or (Dist[I, J] > Dist[iBest, jbest]) then 928 929 begin 929 iBest := i;930 jbest := j;930 iBest := I; 931 jbest := J; 931 932 Cnt := 1; 932 933 end; … … 938 939 RareLoc[jbest] := -1; 939 940 end; 940 end; // RarePositions941 942 function CheckShore(Loc: integer): boolean;943 var 944 Loc1, OldTile, V21: integer;941 end; 942 943 function CheckShore(Loc: Integer): Boolean; 944 var 945 Loc1, OldTile, V21: Integer; 945 946 Radius: TVicinity21Loc; 946 947 begin 947 result := false;948 Result := False; 948 949 OldTile := RealMap[Loc]; 949 950 if OldTile and fTerrain < fGrass then … … 960 961 end; 961 962 if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then 962 result := true;963 end; 964 end; 965 966 function ActualSpecialTile(Loc: integer): Cardinal;967 begin 968 result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);969 end; 970 971 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); 972 973 const 973 974 ShHiHills = 6; { of land } … … 980 981 hotunification = 50; // min. 25 981 982 982 Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }983 Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution } 983 984 ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35), 984 985 (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3)); 985 986 { Grs Dst Pra Tun - - - For } 986 987 987 function RndLow( y: integer): Cardinal;988 function RndLow(Y: Integer): Cardinal; 988 989 { random lowland appropriate to climate } 989 990 var 990 z0, i: integer;991 p, p0, ZPlus: single;992 begin 993 if ly - 1 - y > ythen994 begin 995 z0 := 6 * ydiv ly;996 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; 997 998 end 998 999 else 999 1000 begin 1000 z0 := 6 * (ly - 1 - y) div ly;1001 ZPlus := 6 * (ly - 1 - y) / ly - z0;1001 z0 := 6 * (ly - 1 - Y) div ly; 1002 ZPlus := 6 * (ly - 1 - Y) / ly - z0; 1002 1003 end; 1003 1004 p0 := 1; 1004 for i:= 2 to 9 do1005 begin 1006 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; 1007 1008 { weight between zones z0 and z0+1 } 1008 if DelphiRandom * p0 < pthen1009 begin 1010 RndLow := i;1009 if DelphiRandom * p0 < P then 1010 begin 1011 RndLow := I; 1011 1012 Break; 1012 1013 end; 1013 p0 := p0 - p;1014 end; 1015 end; 1016 1017 function RunRiver(Loc0: integer): integer;1014 p0 := p0 - P; 1015 end; 1016 end; 1017 1018 function RunRiver(Loc0: Integer): Integer; 1018 1019 { runs river from start point Loc0; return value: length } 1019 1020 var 1020 Dir, T, Loc, Loc1, Cost: integer;1021 Dir, T, Loc, Loc1, Cost: Integer; 1021 1022 Q: TIPQ; 1022 From: array [0 .. lxmax * lymax - 1] of integer;1023 Time: array [0 .. lxmax * lymax - 1] of integer;1024 OneTileLake: boolean;1023 From: array [0 .. lxmax * lymax - 1] of Integer; 1024 Time: array [0 .. lxmax * lymax - 1] of Integer; 1025 OneTileLake: Boolean; 1025 1026 begin 1026 1027 FillChar(Time, SizeOf(Time), 255); { -1 } … … 1031 1032 if (RealMap[Loc] and fTerrain < fGrass) then 1032 1033 begin 1033 OneTileLake := true;1034 OneTileLake := True; 1034 1035 for Dir := 0 to 3 do 1035 1036 begin 1036 1037 Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1); 1037 1038 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then 1038 OneTileLake := false;1039 OneTileLake := False; 1039 1040 end; 1040 1041 if not OneTileLake then … … 1061 1062 end; 1062 1063 Loc1 := Loc; 1063 result := 0;1064 Result := 0; 1064 1065 while Loc <> Loc0 do 1065 1066 begin 1066 1067 Loc := From[Loc]; 1067 inc(result);1068 end; 1069 if ( result > 1) and ((result >= MinRivLen) or1068 Inc(Result); 1069 end; 1070 if (Result > 1) and ((Result >= MinRivLen) or 1070 1071 (RealMap[Loc1] and fTerrain >= fGrass)) then 1071 1072 begin … … 1081 1082 end 1082 1083 else 1083 result := 0;1084 Result := 0; 1084 1085 FreeAndNil(Q); 1085 1086 end; 1086 1087 1087 1088 var 1088 x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;1089 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; 1090 1091 Adjacent: TVicinity8Loc; 1091 1092 … … 1096 1097 while plus < MapSize * LandMass * ShMountains div 10000 do 1097 1098 begin 1098 dec(bMountains);1099 inc(plus, ElCount[bMountains])1099 Dec(bMountains); 1100 Inc(plus, ElCount[bMountains]); 1100 1101 end; 1101 1102 Count := plus; … … 1104 1105 while plus < MapSize * LandMass * ShHiHills div 10000 do 1105 1106 begin 1106 dec(bHills);1107 inc(plus, ElCount[bHills])1108 end; 1109 inc(Count, plus);1107 Dec(bHills); 1108 Inc(plus, ElCount[bHills]); 1109 end; 1110 Inc(Count, plus); 1110 1111 bLand := bHills; 1111 1112 while Count < MapSize * LandMass div 100 do 1112 1113 begin 1113 dec(bLand);1114 inc(Count, ElCount[bLand])1114 Dec(bLand); 1115 Inc(Count, ElCount[bLand]); 1115 1116 end; 1116 1117 … … 1135 1136 (RealMap[Loc1] and fTerrain < fGrass) or 1136 1137 (RealMap[Loc1] and fTerrain = fArctic) then 1137 inc(Count); // count adjacent water1138 Inc(Count); // count adjacent water 1138 1139 end; 1139 1140 if Count = 8 then 1140 RealMap[Loc0] := fOcean 1141 RealMap[Loc0] := fOcean; 1141 1142 end; 1142 1143 … … 1147 1148 plus := MapSize; 1148 1149 Loc0 := DelphiRandom(MapSize); 1149 for n:= 0 to plus - 1 do1150 for N := 0 to plus - 1 do 1150 1151 begin 1151 1152 if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and … … 1164 1165 CopyFrom[Loc0] := Loc0; 1165 1166 1166 for n:= 0 to unification * MapSize div 100 do1167 begin 1168 y:= DelphiRandom(ly);1169 if abs( y- (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then1170 if y< ly shr 1 then1171 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 1172 1173 else 1173 y := 3 * ly shr 1 - y;1174 Loc0 := lx * y+ DelphiRandom(lx);1174 Y := 3 * ly shr 1 - Y; 1175 Loc0 := lx * Y + DelphiRandom(lx); 1175 1176 if RealMap[Loc0] and fTerrain = fGrass then 1176 1177 begin … … 1202 1203 Loc1 := CopyFrom[Loc1]; 1203 1204 RealMap[Loc0] := RealMap[Loc0] and not fTerrain or 1204 RealMap[Loc1] and fTerrain 1205 RealMap[Loc1] and fTerrain; 1205 1206 end; 1206 1207 … … 1225 1226 if Loc1 >= 0 then 1226 1227 if RealMap[Loc1] and fTerrain < fGrass then 1227 inc(Count, 2)1228 Inc(Count, 2); 1228 1229 end; 1229 1230 end; 1230 1231 if Count >= 4 then 1231 RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie 1232 RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie; 1232 1233 end; 1233 1234 … … 1241 1242 if Loc1 >= 0 then 1242 1243 if RealMap[Loc1] and fTerrain <> fDesert then 1243 inc(Count)1244 Inc(Count); 1244 1245 end; 1245 1246 if Count >= 4 then 1246 RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie 1247 RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie; 1247 1248 end; 1248 1249 1249 1250 for Loc0 := 0 to MapSize - 1 do 1250 1251 CheckShore(Loc0); // change ocean to shore 1251 for x:= 0 to lx - 1 do1252 begin 1253 RealMap[ x+ lx * 0] := fArctic;1254 if RealMap[ x+ lx * 1] >= fGrass then1255 RealMap[ x + lx * 1] := RealMap[x+ lx * 1] and not fTerrain or fTundra;1256 if RealMap[ x+ lx * (ly - 2)] >= fGrass then1257 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 1258 1259 not fTerrain or fTundra; 1259 RealMap[ x + lx * (ly - 1)] := fArctic1260 RealMap[X + lx * (ly - 1)] := fArctic; 1260 1261 end; 1261 1262 … … 1278 1279 CountGood: (cgBest, cgFlat, cgLand); 1279 1280 1280 function IsGoodTile(Loc: integer): boolean;1281 function IsGoodTile(Loc: Integer): Boolean; 1281 1282 var 1282 xLoc, yLoc: integer;1283 xLoc, yLoc: Integer; 1283 1284 begin 1284 1285 xLoc := Loc mod lx; 1285 1286 yLoc := Loc div lx; 1286 1287 if RealMap[Loc] and fDeadLands <> 0 then 1287 result := false1288 Result := False 1288 1289 else 1289 1290 case CountGood of 1290 1291 cgBest: 1291 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1292 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1292 1293 fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc + 1293 1294 (yLoc + 1) shr 1); 1294 1295 cgFlat: 1295 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1296 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1296 1297 fSwamp, fForest]); 1297 1298 cgLand: 1298 result := RealMap[Loc] and fTerrain >= fGrass;1299 Result := RealMap[Loc] and fTerrain >= fGrass; 1299 1300 end; 1300 1301 end; … … 1304 1305 1305 1306 var 1306 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, 1307 1308 nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc, 1308 FineDistSQR, nRest: integer;1309 ccount: array [0 .. lxmax * lymax - 1] of word;1310 sc, StartLoc0, sccount: array [1 .. nPl] of integer;1311 TestStartLoc: array [0 .. nPl - 1] of integer;1312 CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of integer;1313 nCityLoc: array [1 .. nPl] of integer;1314 RestLoc: array [0 .. MaxCityLoc - 1] of integer;1315 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; 1316 1317 Radius: TVicinity21Loc; 1317 1318 Adjacent: TVicinity8Loc; 1318 ok: boolean;1319 ok: Boolean; 1319 1320 1320 1321 begin … … 1322 1323 for p1 := 0 to nPl - 1 do 1323 1324 if 1 shl p1 and GAlive <> 0 then 1324 inc(nAlive);1325 Inc(nAlive); 1325 1326 if nAlive = 0 then 1326 exit;1327 Exit; 1327 1328 1328 1329 { count good tiles } … … 1331 1332 if RealMap[Loc] and fTerrain = fGrass then 1332 1333 if ActualSpecialTile(Loc) = 1 then 1333 inc(ccount[Continent[Loc]], 3)1334 Inc(ccount[Continent[Loc]], 3) 1334 1335 else 1335 inc(ccount[Continent[Loc]], 2)1336 Inc(ccount[Continent[Loc]], 2) 1336 1337 else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills] 1337 1338 then 1338 inc(ccount[Continent[Loc]]);1339 Inc(ccount[Continent[Loc]]); 1339 1340 1340 1341 Loc := 0; 1341 1342 while ccount[Loc] > 0 do 1342 inc(Loc);1343 for i:= 1 to nAlive do1344 begin 1345 sc[ i] := Loc;1346 sccount[ i] := 11343 Inc(Loc); 1344 for I := 1 to nAlive do 1345 begin 1346 sc[I] := Loc; 1347 sccount[I] := 1 1347 1348 end; 1348 1349 { init with zero size start continents, then search bigger ones } … … 1355 1356 if p1 < nAlive + 1 then 1356 1357 sc[p1] := sc[p1 - 1]; 1357 dec(p1)1358 Dec(p1); 1358 1359 end; 1359 1360 if p1 < nAlive + 1 then … … 1362 1363 nsc := nAlive; 1363 1364 repeat 1364 c:= 1; // search least crowded continent after smallest1365 for i:= 2 to nsc - 1 do1366 if ccount[sc[ i]] * (2 * sccount[c] + 1) > ccount[sc[c]] *1367 (2 * sccount[ i] + 1) then1368 c := i;1369 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 1370 1371 Break; // even least crowded continent is more crowded than smallest 1371 inc(sccount[c]);1372 dec(nsc)1372 Inc(sccount[C]); 1373 Dec(nsc); 1373 1374 until sccount[nsc] > 1; 1374 1375 … … 1376 1377 CountGood := cgBest; 1377 1378 repeat 1378 dec(MinGood);1379 Dec(MinGood); 1379 1380 if (MinGood = 3) and (CountGood < cgLand) then // too demanding! 1380 1381 begin 1381 inc(CountGood);1382 MinGood := 6 1382 Inc(CountGood); 1383 MinGood := 6; 1383 1384 end; 1384 1385 FillChar(nCityLoc, SizeOf(nCityLoc), 0); 1385 1386 Loc := DelphiRandom(MapSize); 1386 for i:= 0 to MapSize - 1 do1387 for I := 0 to MapSize - 1 do 1387 1388 begin 1388 1389 if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand)) 1389 1390 and IsGoodTile(Loc) then 1390 1391 begin 1391 c:= nsc;1392 while ( c > 0) and (Continent[Loc] <> sc[c]) do1393 dec(c);1394 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 1395 1396 begin 1396 1397 CntGood := 1; … … 1401 1402 Loc1 := Radius[V21]; 1402 1403 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1403 inc(CntGood)1404 Inc(CntGood); 1404 1405 end; 1405 1406 if CntGood >= MinGood then 1406 1407 begin 1407 CityLoc[ c, nCityLoc[c]] := Loc;1408 inc(nCityLoc[c])1408 CityLoc[C, nCityLoc[C]] := Loc; 1409 Inc(nCityLoc[C]); 1409 1410 end; 1410 1411 end; … … 1413 1414 end; 1414 1415 1415 ok := true;1416 for c:= 1 to nsc do1417 if nCityLoc[ c] < sccount[c] * (8 - MinGood) div (7 - MinGood) then1418 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; 1419 1420 until ok; 1420 1421 1421 1422 FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100); 1422 1423 p1 := 1; 1423 for c:= 1 to nsc do1424 for C := 1 to nsc do 1424 1425 begin // for all start continents 1425 if sccount[ c] = 1 then1426 StartLoc0[p1] := CityLoc[ c, DelphiRandom(nCityLoc[c])]1426 if sccount[C] = 1 then 1427 StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])] 1427 1428 else 1428 1429 begin 1429 1430 BestDist := 0; 1430 n := 1 shl sccount[c] * 32; // number of tries to find good distribution1431 if n> 1 shl 12 then1432 n:= 1 shl 12;1433 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 1434 1435 begin 1435 1436 MinDist := MaxInt; 1436 nRest := nCityLoc[ c];1437 for i:= 0 to nRest - 1 do1438 RestLoc[ i] := CityLoc[c, i];1439 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 1440 1441 begin 1441 1442 if nRest = 0 then 1442 1443 Break; 1443 j:= DelphiRandom(nRest);1444 TestStartLoc[ i] := RestLoc[j];1445 RestLoc[ j] := RestLoc[nRest - 1];1446 dec(nRest);1447 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 1448 1449 begin 1449 TestDist := Distance(TestStartLoc[ i], TestStartLoc[j]);1450 TestDist := Distance(TestStartLoc[I], TestStartLoc[J]); 1450 1451 if TestDist < MinDist then 1451 MinDist := TestDist 1452 MinDist := TestDist; 1452 1453 end; 1453 if i = sccount[c] - 1 then1454 if I = sccount[C] - 1 then 1454 1455 begin 1455 assert(MinDist > BestDist);1456 Assert(MinDist > BestDist); 1456 1457 BestDist := MinDist; 1457 for j := 0 to sccount[c] - 1 do1458 StartLoc0[p1 + j] := TestStartLoc[j];1458 for J := 0 to sccount[C] - 1 do 1459 StartLoc0[p1 + J] := TestStartLoc[J]; 1459 1460 end 1460 1461 else if BestDist > 0 then 1461 1462 begin 1462 j:= 0;1463 while j< nRest do1463 J := 0; 1464 while J < nRest do 1464 1465 begin // remove all locs from rest which have too little distance to this one 1465 TestDist := Distance(TestStartLoc[ i], RestLoc[j]);1466 TestDist := Distance(TestStartLoc[I], RestLoc[J]); 1466 1467 if TestDist <= BestDist then 1467 1468 begin 1468 RestLoc[ j] := RestLoc[nRest - 1];1469 dec(nRest);1469 RestLoc[J] := RestLoc[nRest - 1]; 1470 Dec(nRest); 1470 1471 end 1471 1472 else 1472 inc(j);1473 Inc(J); 1473 1474 end; 1474 1475 end; 1475 1476 end; 1476 dec(n)1477 end; 1478 end; 1479 p1 := p1 + sccount[ c]1477 Dec(N) 1478 end; 1479 end; 1480 p1 := p1 + sccount[C] 1480 1481 end; 1481 1482 … … 1494 1495 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1495 1496 if RealMap[Loc1] and fTerrain = fGrass then 1496 inc(CntGoodGrass)1497 Inc(CntGoodGrass) 1497 1498 else 1498 inc(CntGood);1499 Inc(CntGood); 1499 1500 end; 1500 1501 for V21 := 1 to 26 do … … 1528 1529 begin 1529 1530 IrrLoc[nIrrLoc] := Loc1; 1530 inc(nIrrLoc);1531 end; 1532 end; 1533 i:= 2;1534 if i> nIrrLoc then1535 i:= nIrrLoc;1536 while i> 0 do1537 begin 1538 j:= DelphiRandom(nIrrLoc);1539 RealMap[IrrLoc[ j]] := RealMap[IrrLoc[j]] or tiIrrigation;1540 IrrLoc[ j] := IrrLoc[nIrrLoc - 1];1541 dec(nIrrLoc);1542 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); 1543 1544 end; 1544 1545 end; … … 1549 1550 begin 1550 1551 repeat 1551 i:= DelphiRandom(nAlive) + 11552 until StartLoc0[ i] >= 0;1553 StartLoc[p1] := StartLoc0[ i];1554 StartLoc0[ i] := -11552 I := DelphiRandom(nAlive) + 1 1553 until StartLoc0[I] >= 0; 1554 StartLoc[p1] := StartLoc0[I]; 1555 StartLoc0[I] := -1 1555 1556 end; 1556 1557 SaveMapCenterLoc := StartLoc[0]; … … 1585 1586 StartLoc2[p1] := Loc1; 1586 1587 BestDist := TestDist; 1587 n:= 1;1588 N := 1; 1588 1589 end 1589 1590 else if TestDist = BestDist then 1590 1591 begin 1591 inc(n);1592 if DelphiRandom( n) = 0 then1592 Inc(N); 1593 if DelphiRandom(N) = 0 then 1593 1594 StartLoc2[p1] := Loc1; 1594 1595 end; 1595 1596 end; 1596 1597 end; 1597 end; { StartPositions }1598 1599 procedure PredefinedStartPositions(Human: integer);1598 end; 1599 1600 procedure PredefinedStartPositions(Human: Integer); 1600 1601 // use predefined nation start positions 1601 1602 var 1602 i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;1603 StartLoc0: array [0 .. lxmax * lymax - 1] of integer;1604 ishuman: boolean;1603 I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer; 1604 StartLoc0: array [0 .. lxmax * lymax - 1] of Integer; 1605 ishuman: Boolean; 1605 1606 begin 1606 1607 nAlive := 0; 1607 1608 for p1 := 0 to nPl - 1 do 1608 1609 if 1 shl p1 and GAlive <> 0 then 1609 inc(nAlive);1610 Inc(nAlive); 1610 1611 if nAlive = 0 then 1611 exit;1612 Exit; 1612 1613 1613 1614 for I := 0 to Length(StartLoc0) - 1 do … … 1622 1623 StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0]; 1623 1624 StartLoc0[nPrefStartLoc0] := Loc1; 1624 inc(nPrefStartLoc0);1625 inc(nStartLoc0);1625 Inc(nPrefStartLoc0); 1626 Inc(nStartLoc0); 1626 1627 RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos; 1627 1628 end … … 1629 1630 begin 1630 1631 StartLoc0[nStartLoc0] := Loc1; 1631 inc(nStartLoc0);1632 Inc(nStartLoc0); 1632 1633 RealMap[Loc1] := RealMap[Loc1] and not fStartPos; 1633 1634 end; 1634 assert(nStartLoc0 >= nAlive);1635 Assert(nStartLoc0 >= nAlive); 1635 1636 1636 1637 StartLoc[0] := 0; 1637 for ishuman := true downto false do1638 for ishuman := True downto False do 1638 1639 for p1 := 0 to nPl - 1 do 1639 1640 if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman) 1640 1641 then 1641 1642 begin 1642 dec(nStartLoc0);1643 Dec(nStartLoc0); 1643 1644 imax := nStartLoc0; 1644 1645 if nPrefStartLoc0 > 0 then 1645 1646 begin 1646 dec(nPrefStartLoc0);1647 Dec(nPrefStartLoc0); 1647 1648 imax := nPrefStartLoc0; 1648 1649 end; 1649 i:= DelphiRandom(imax + 1);1650 StartLoc[p1] := StartLoc0[ i];1651 StartLoc2[p1] := StartLoc0[ i];1652 StartLoc0[ i] := StartLoc0[imax];1650 I := DelphiRandom(imax + 1); 1651 StartLoc[p1] := StartLoc0[I]; 1652 StartLoc2[p1] := StartLoc0[I]; 1653 StartLoc0[I] := StartLoc0[imax]; 1653 1654 StartLoc0[imax] := StartLoc0[nStartLoc0]; 1654 1655 end; 1655 1656 SaveMapCenterLoc := StartLoc[0]; 1656 end; { PredefinedStartPositions }1657 end; 1657 1658 1658 1659 procedure InitGame; 1659 1660 var 1660 i, p, p1, uix, Loc1: integer;1661 I, P, p1, uix, Loc1: Integer; 1661 1662 begin 1662 1663 {$IFDEF FastContact} … … 1670 1671 if RealMap[Loc1] and fterrain>=fGrass then 1671 1672 if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRoad 1672 else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR; 1673 else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;} 1673 1674 {random Road and Railroad } 1674 1675 { !!!for Loc1:=0 to MapSize-1 do … … 1682 1683 GTestFlags := 0; 1683 1684 GInitialized := GAlive or GWatching; 1684 for p:= 0 to nPl - 1 do1685 if 1 shl pand GInitialized <> 0 then1686 with RW[ p] do1687 begin 1688 Researched[ p] := 0;1689 Discovered[ p] := 0;1690 TerritoryCount[ p] := 0;1691 nTech[ p] := 0;1692 if Difficulty[ p] = 0 then1693 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 1694 1695 else 1695 ResourceMask[ p] := $FFFFFFFF and not(fSpecial2 or fModern);1696 GrWallContinent[ p] := -1;1696 ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern); 1697 GrWallContinent[P] := -1; 1697 1698 1698 1699 GetMem(Map, 4 * MapSize); … … 1712 1713 if 1 shl p1 and GInitialized <> 0 then 1713 1714 begin 1714 FillChar(RWemix[ p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }1715 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); 1716 1717 end; 1717 1718 Attitude[p1] := atNeutral; … … 1721 1722 Tribute[p1] := 0; 1722 1723 TributePaid[p1] := 0; 1723 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1724 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1724 1725 begin // initialize enemy report 1725 1726 GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 * … … 1731 1732 EnemyReport[p1].Attitude := atNeutral; 1732 1733 EnemyReport[p1].Government := gDespotism; 1733 if 1 shl pand GAlive = 0 then1734 if 1 shl P and GAlive = 0 then 1734 1735 Treaty[p1] := trNone // supervisor 1735 1736 end … … 1753 1754 1754 1755 // create initial models and units 1755 for p:= 0 to nPl - 1 do1756 if (1 shl pand GAlive <> 0) then1757 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 1758 1759 begin 1759 1760 nModel := 0; 1760 for i:= 0 to nSpecialModel - 1 do1761 if SpecialModelPreq[ i] = preNone then1761 for I := 0 to nSpecialModel - 1 do 1762 if SpecialModelPreq[I] = preNone then 1762 1763 begin 1763 Model[nModel] := SpecialModel[ i];1764 Model[nModel] := SpecialModel[I]; 1764 1765 Model[nModel].Status := 0; 1765 1766 Model[nModel].IntroTurn := 0; 1766 1767 Model[nModel].Built := 0; 1767 1768 Model[nModel].Lost := 0; 1768 Model[nModel].ID := pshl 12 + nModel;1769 Model[nModel].ID := P shl 12 + nModel; 1769 1770 SetModelFlags(Model[nModel]); 1770 inc(nModel)1771 Inc(nModel); 1771 1772 end; 1772 1773 nUn := 0; 1773 UnBuilt[ p] := 0;1774 UnBuilt[P] := 0; 1774 1775 for uix := 0 to nStartUn - 1 do 1775 1776 begin 1776 CreateUnit( p, StartUn[uix]);1777 dec(Model[StartUn[uix]].Built);1778 Un[uix].Loc := StartLoc2[ p];1779 PlaceUnit( p, uix);1780 end; 1781 FoundCity( p, StartLoc[p]); // capital1782 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; 1783 1784 with City[0] do 1784 1785 begin 1785 ID := pshl 12;1786 ID := P shl 12; 1786 1787 Flags := chFounded; 1787 1788 end; … … 1790 1791 TerritoryCount[nPl] := MapSize; 1791 1792 // fillchar(NewContact, sizeof(NewContact), false); 1792 end; // InitGame1793 end; 1793 1794 1794 1795 procedure InitRandomGame; … … 1797 1798 CalculatePrimitive; 1798 1799 CreateElevation; 1799 CreateMap( false);1800 CreateMap(False); 1800 1801 StartPositions; 1801 1802 InitGame; 1802 1803 end; 1803 1804 1804 procedure InitMapGame(Human: integer);1805 procedure InitMapGame(Human: Integer); 1805 1806 begin 1806 1807 DelphiRandSeed := RND; … … 1812 1813 procedure ReleaseGame; 1813 1814 var 1814 p1, p2: integer;1815 p1, p2: Integer; 1815 1816 begin 1816 1817 for p1 := 0 to nPl - 1 do … … 1834 1835 procedure InitMapEditor; 1835 1836 var 1836 p1: integer;1837 p1: Integer; 1837 1838 begin 1838 1839 CalculatePrimitive; … … 1871 1872 end; 1872 1873 1873 procedure EditTile(Loc, NewTile: integer);1874 var 1875 Loc1, V21: integer;1874 procedure EditTile(Loc, NewTile: Integer); 1875 var 1876 Loc1, V21: Integer; 1876 1877 Radius: TVicinity21Loc; 1877 1878 begin … … 1897 1898 if (NewTile and fTerImp = tiIrrigation) or (NewTile and fTerImp = tiFarm) 1898 1899 then 1899 NewTile := NewTile and not fTerImp 1900 NewTile := NewTile and not fTerImp; 1900 1901 end; 1901 1902 if (Terrain[NewTile and fTerrain].MineEff = 0) and … … 1921 1922 RealMap[Loc1] := RealMap[Loc1] or ($F shl 27); 1922 1923 RW[0].Map[Loc1] := RealMap[Loc1] and $07FFFFFF or fObserved; 1923 end 1924 end; 1924 1925 end; 1925 1926 // RealMap[Loc]:=RealMap[Loc] and not fSpecial; … … 1931 1932 ____________________________________________________________________ 1932 1933 } 1933 function GetTileInfo( p, cix, Loc: integer; var Info: TTileInfo): integer;1934 function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer; 1934 1935 // cix>=0 - known city index of player p -- only core internal! 1935 1936 // cix=-1 - search city, player unknown, only if permission for p 1936 1937 // cix=-2 - don't search city, don't calculate city benefits, just government of player p 1937 1938 var 1938 p0, Tile, special: integer;1939 p0, Tile, special: Integer; 1939 1940 begin 1940 1941 with Info do 1941 1942 begin 1942 p0 := p;1943 p0 := P; 1943 1944 if cix >= 0 then 1944 1945 Tile := RealMap[Loc] 1945 1946 else 1946 1947 begin 1947 Tile := RW[ p].Map[Loc];1948 Tile := RW[P].Map[Loc]; 1948 1949 if Tile and fTerrain = fUNKNOWN then 1949 1950 begin 1950 result := eNoPreq;1951 exit;1951 Result := eNoPreq; 1952 Exit; 1952 1953 end; 1953 1954 end; … … 1955 1956 if (cix = -1) and (UsedByCity[Loc] >= 0) then 1956 1957 begin // search exploiting player and city 1957 SearchCity(UsedByCity[Loc], p, cix);1958 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 1959 1960 3 = lObserveSuper)) then 1960 1961 cix := -1 … … 1962 1963 if cix = -1 then 1963 1964 begin 1964 result := eInvalid;1965 exit;1965 Result := eInvalid; 1966 Exit; 1966 1967 end; // no city found here 1967 1968 1968 special := Tile and fSpecial and ResourceMask[ p] shr 5;1969 special := Tile and fSpecial and ResourceMask[P] shr 5; 1969 1970 with Terrain[Tile and fTerrain] do 1970 1971 begin … … 1973 1974 Trade := TradeRes[special]; 1974 1975 if (special > 0) and (Tile and fTerrain <> fGrass) and 1975 (RW[ p].NatBuilt[imSpacePort] > 0) then1976 (RW[P].NatBuilt[imSpacePort] > 0) then 1976 1977 begin // GeoSat effect 1977 1978 Food := 2 * Food - FoodRes[0]; … … 1982 1983 if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or 1983 1984 (Tile and fCity <> 0) then 1984 inc(Food, IrrEff); { irrigation effect }1985 Inc(Food, IrrEff); { irrigation effect } 1985 1986 if Tile and fTerImp = tiMine then 1986 inc(Prod, MineEff); { mining effect }1987 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) 1988 1989 then 1989 inc(Trade); { river effect }1990 Inc(Trade); { river effect } 1990 1991 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 1991 (RW[ p].Tech[adWheel] >= tsApplicable) then1992 inc(Trade); { road effect }1992 (RW[P].Tech[adWheel] >= tsApplicable) then 1993 Inc(Trade); { road effect } 1993 1994 if (Tile and (fRR or fCity) <> 0) and 1994 (RW[ p].Tech[adRailroad] >= tsApplicable) then1995 inc(Prod, Prod shr 1); { railroad effect }1995 (RW[P].Tech[adRailroad] >= tsApplicable) then 1996 Inc(Prod, Prod shr 1); { railroad effect } 1996 1997 1997 1998 ExplCity := -1; 1998 if (cix >= 0) and ( p= p0) then1999 if (cix >= 0) and (P = p0) then 1999 2000 ExplCity := cix; 2000 2001 if cix >= 0 then … … 2002 2003 begin 2003 2004 if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and 2004 (RW[ p].City[cix].Built[imSupermarket] > 0) then2005 inc(Food, Food shr 1); { farmland effect }2005 (RW[P].City[cix].Built[imSupermarket] > 0) then 2006 Inc(Food, Food shr 1); { farmland effect } 2006 2007 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 2007 (RW[ p].City[cix].Built[imHighways] > 0) then2008 inc(Trade, 1); { superhighway effect }2008 (RW[P].City[cix].Built[imHighways] > 0) then 2009 Inc(Trade, 1); { superhighway effect } 2009 2010 end 2010 2011 else 2011 2012 begin 2012 if RW[ p].City[cix].Built[imHarbor] > 0 then2013 inc(Food); { harbour effect }2014 if RW[ p].City[cix].Built[imPlatform] > 0 then2015 inc(Prod); { oil platform effect }2016 if GWonder[woLighthouse].EffectiveOwner = pthen2017 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); 2018 2019 end; 2019 2020 end; 2020 2021 2021 2022 { good government influence } 2022 if (RW[ p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)2023 if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0) 2023 2024 then 2024 inc(Trade);2025 if (RW[ p].Government = gCommunism) and (Prod > 1) then2026 inc(Prod);2027 2028 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 2029 2030 begin { bad government influence } 2030 2031 if Food > 3 then … … 2038 2039 if Tile and (fTerrain or fPoll) > fPoll then 2039 2040 begin { pollution - decrease ressources } 2040 dec(Food, Food shr 1);2041 dec(Prod, Prod shr 1);2042 dec(Trade, Trade shr 1);2041 Dec(Food, Food shr 1); 2042 Dec(Prod, Prod shr 1); 2043 Dec(Trade, Trade shr 1); 2043 2044 end; 2044 2045 2045 2046 if Tile and fCity <> 0 then 2046 2047 Trade := 0 2047 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] 2048 2049 .Built[imPalace] = 0) then 2049 if RW[ p].City[cix].Built[imTownHall] = 0 then2050 if RW[P].City[cix].Built[imTownHall] = 0 then 2050 2051 Trade := 0 2051 2052 else if Trade > 3 then 2052 2053 Trade := 3; 2053 2054 end; 2054 result := eOK;2055 end; { GetTileInfo }2056 2057 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); 2058 2059 { find strongest defender at Loc } 2059 2060 var 2060 2061 Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost, 2061 Domain: integer;2062 Domain: Integer; 2062 2063 PUn: ^TUn; 2063 2064 PModel: ^TModel; … … 2077 2078 if PUn.Loc = Loc then 2078 2079 begin 2079 inc(Cnt);2080 Inc(Cnt); 2080 2081 if PUn.Master < 0 then 2081 2082 begin … … 2084 2085 TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense; 2085 2086 if RealMap[Loc] and fTerImp = tiFort then 2086 inc(TestBonus, 4);2087 Inc(TestBonus, 4); 2087 2088 if PUn.Flags and unFortified <> 0 then 2088 inc(TestBonus, 2);2089 Inc(TestBonus, 2); 2089 2090 if (PModel.Kind = mkSpecial_TownGuard) and 2090 2091 (RealMap[Loc] and fCity <> 0) then 2091 inc(TestBonus, 4);2092 Inc(TestBonus, 4); 2092 2093 end 2093 2094 else 2094 2095 TestBonus := 4; 2095 inc(TestBonus, PUn.exp div ExpCost);2096 Inc(TestBonus, PUn.exp div ExpCost); 2096 2097 TestStrength := PModel.Defense * TestBonus * PUn.Health; 2097 2098 if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or … … 2103 2104 if PModel.Cap[mcStealth] > 0 then 2104 2105 else if PModel.Cap[mcSub] > 0 then 2105 inc(TestDet, 1 shl 28)2106 Inc(TestDet, 1 shl 28) 2106 2107 else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and 2107 2108 not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then 2108 inc(TestDet, 4 shl 28) // fanatic ground units always defend2109 Inc(TestDet, 4 shl 28) // fanatic ground units always defend 2109 2110 else if PModel.Flags and mdZOC <> 0 then 2110 inc(TestDet, 3 shl 28)2111 Inc(TestDet, 3 shl 28) 2111 2112 else 2112 inc(TestDet, 2 shl 28);2113 Inc(TestDet, 2 shl 28); 2113 2114 TestCost := RW[Defender].Model[PUn.mix].Cost; 2114 2115 if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then … … 2125 2126 end; 2126 2127 2127 function UnitSpeed( p, mix, Health: integer): integer;2128 begin 2129 with RW[ p].Model[mix] do2130 begin 2131 result := Speed;2128 function UnitSpeed(P, mix, Health: Integer): Integer; 2129 begin 2130 with RW[P].Model[mix] do 2131 begin 2132 Result := Speed; 2132 2133 if Domain = dSea then 2133 2134 begin 2134 if GWonder[woMagellan].EffectiveOwner = pthen2135 inc(result, 200);2135 if GWonder[woMagellan].EffectiveOwner = P then 2136 Inc(Result, 200); 2136 2137 if Health < 100 then 2137 result := ((result - 250) * Health div 5000) * 50 + 250;2138 end 2139 end 2140 end; 2141 2142 procedure GetUnitReport( p, uix: integer; var UnitReport: TUnitReport);2143 var 2144 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; 2145 2146 PModel: ^TModel; 2146 2147 begin … … 2148 2149 UnitReport.ProdSupport := 0; 2149 2150 UnitReport.ReportFlags := 0; 2150 if RW[ p].Government <> gAnarchy then2151 with RW[ p].Un[uix] do2152 begin 2153 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]; 2154 2155 if (PModel.Kind = mkSettler) 2155 2156 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then 2156 UnitReport.FoodSupport := SettlerFood[RW[ p].Government]2157 UnitReport.FoodSupport := SettlerFood[RW[P].Government] 2157 2158 else if Flags and unConscripts <> 0 then 2158 2159 UnitReport.FoodSupport := 1; 2159 2160 2160 if RW[ p].Government <> gFundamentalism then2161 if RW[P].Government <> gFundamentalism then 2161 2162 begin 2162 2163 if GTestFlags and tfImmImprove = 0 then … … 2173 2174 begin 2174 2175 TerrOwner := RealMap[Loc] shr 27; 2175 case RW[ p].Government of2176 case RW[P].Government of 2176 2177 gRepublic, gFuture: 2177 if (TerrOwner <> p) and (TerrOwner < nPl) and2178 (RW[ p].Treaty[TerrOwner] < trAlliance) then2178 if (TerrOwner <> P) and (TerrOwner < nPl) and 2179 (RW[P].Treaty[TerrOwner] < trAlliance) then 2179 2180 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2180 2181 gDemocracy: 2181 if (TerrOwner >= nPl) or (TerrOwner <> p) and2182 (RW[ p].Treaty[TerrOwner] < trAlliance) then2182 if (TerrOwner >= nPl) or (TerrOwner <> P) and 2183 (RW[P].Treaty[TerrOwner] < trAlliance) then 2183 2184 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2184 2185 end; … … 2188 2189 end; 2189 2190 2190 procedure SearchCity(Loc: integer; var p, cix: integer);2191 procedure SearchCity(Loc: Integer; var P, cix: Integer); 2191 2192 // set p to supposed owner before call 2192 2193 var 2193 i: integer;2194 I: Integer; 2194 2195 begin 2195 2196 if RealMap[Loc] < nPl shl 27 then 2196 p:= RealMap[Loc] shr 27;2197 for i:= 0 to nPl - 1 do2198 begin 2199 if 1 shl pand GAlive <> 0 then2200 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 2201 2202 begin 2202 2203 cix := nCity - 1; 2203 2204 while (cix >= 0) and (City[cix].Loc <> Loc) do 2204 dec(cix);2205 Dec(cix); 2205 2206 if cix >= 0 then 2206 exit;2207 end; 2208 assert(i< nPl - 1);2209 p := (p+ 1) mod nPl;2210 end; 2211 end; 2212 2213 procedure MakeCityInfo( p, cix: integer; var ci: TCityInfo);2214 begin 2215 assert((p >= 0) and (p< nPl));2216 assert((cix >= 0) and (cix < RW[p].nCity));2217 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 2218 2219 begin 2219 2220 ci.Loc := Loc; 2220 2221 ci.ID := ID; 2221 ci.Owner := p;2222 ci.Owner := P; 2222 2223 ci.Size := Size; 2223 2224 ci.Flags := 0; 2224 2225 if Built[imPalace] > 0 then 2225 inc(ci.Flags, ciCapital);2226 if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[ p]) then2227 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); 2228 2229 if Built[imCoastalFort] > 0 then 2229 inc(ci.Flags, ciCoastalFort);2230 Inc(ci.Flags, ciCoastalFort); 2230 2231 if Built[imMissileBat] > 0 then 2231 inc(ci.Flags, ciMissileBat);2232 Inc(ci.Flags, ciMissileBat); 2232 2233 if Built[imBunker] > 0 then 2233 inc(ci.Flags, ciBunker);2234 Inc(ci.Flags, ciBunker); 2234 2235 if Built[imSpacePort] > 0 then 2235 inc(ci.Flags, ciSpacePort);2236 end; 2237 end; 2238 2239 procedure TellAboutModel( p, taOwner, tamix: integer);2240 var 2241 i: integer;2242 begin 2243 if ( p= taOwner) or (Mode < moPlaying) then2244 exit;2245 i:= 0;2246 while ( i < RW[p].nEnemyModel) and ((RW[p].EnemyModel[i].Owner <> taOwner) or2247 (RW[ p].EnemyModel[i].mix <> tamix)) do2248 inc(i);2249 if i = RW[p].nEnemyModel then2250 IntServer(sIntTellAboutModel + pshl 4, taOwner, tamix, nil^);2251 end; 2252 2253 function emixSafe( p, taOwner, tamix: integer): integer;2254 begin 2255 result := RWemix[p, taOwner, tamix];2256 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 2257 2258 begin // sIntTellAboutModel comes too late 2258 assert(Mode = moMovie);2259 result := $FFFF;2260 end; 2261 end; 2262 2263 procedure IntroduceEnemy(p1, p2: integer);2259 Assert(Mode = moMovie); 2260 Result := $FFFF; 2261 end; 2262 end; 2263 2264 procedure IntroduceEnemy(p1, p2: Integer); 2264 2265 begin 2265 2266 RW[p1].Treaty[p2] := trNone; … … 2267 2268 end; 2268 2269 2269 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;2270 euix: integer = -2): boolean;2270 function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean; 2271 euix: Integer = -2): Boolean; 2271 2272 // euix = -2: full discover 2272 2273 // euix = -1: unit and city only, append units in EnemyUn 2273 2274 // euix >= 0: unit and city only, replace EnemyUn[euix] 2274 2275 2275 procedure SetContact(p1, p2: integer);2276 procedure SetContact(p1, p2: Integer); 2276 2277 begin 2277 2278 if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then 2278 exit;2279 Exit; 2279 2280 IntServer(sIntTellAboutNation, p1, p2, nil^); 2280 2281 // NewContact[p1,p2]:=true … … 2282 2283 2283 2284 var 2284 i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,2285 cixFoundCity, MinLevel, Loc1, V8: integer;2285 I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity, 2286 cixFoundCity, MinLevel, Loc1, V8: Integer; 2286 2287 Tile, AddFlags: Cardinal; 2287 2288 Adjacent: TVicinity8Loc; … … 2289 2290 mox: ^TModel; 2290 2291 begin 2291 result := false;2292 Result := False; 2292 2293 with RW[pTell] do 2293 2294 begin … … 2305 2306 AddFlags := AddFlags or fGrWall; 2306 2307 if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and 2307 (pTell = p)) then2308 (pTell = P)) then 2308 2309 begin // set fPeace flag? 2309 2310 TerrOwner := Tile shr 27; … … 2314 2315 (1 shl trPeace or 1 shl TrFriendlyContact) <> 0 then 2315 2316 AddFlags := AddFlags or fPeace; 2316 end 2317 end; 2317 2318 end; 2318 2319 … … 2332 2333 unx := @RW[Occupant[Loc]].Un[uix]; 2333 2334 mox := @RW[Occupant[Loc]].Model[unx.mix]; 2334 assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));2335 Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0)); 2335 2336 if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and 2336 2337 (Tile and fTerImp <> tiBase) then … … 2348 2349 begin 2349 2350 uix := nEnemyUn; 2350 inc(nEnemyUn);2351 assert(nEnemyUn < neumax);2351 Inc(nEnemyUn); 2352 Assert(nEnemyUn < neumax); 2352 2353 end; 2353 2354 MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]); 2354 2355 if Cnt > 1 then 2355 2356 EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti; 2356 if (mox.Flags and mdZOC <> 0) and (pTell = p) and2357 if (mox.Flags and mdZOC <> 0) and (pTell = P) and 2357 2358 (Treaty[Occupant[Loc]] < trAlliance) then 2358 2359 begin // set fInEnemyZoC flags of surrounding tiles … … 2363 2364 if (Loc1 >= 0) and (Loc1 < MapSize) then 2364 2365 Map[Loc1] := Map[Loc1] or fInEnemyZoC 2365 end 2366 end; 2366 2367 end; 2367 2368 if EnableContact and (mox.Domain = dGround) then … … 2373 2374 end; 2374 2375 // Level:=lObserveSuper; // don't discover unit twice 2375 if (pTell = p) and2376 if (pTell = P) and 2376 2377 ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then 2377 result := true;2378 Result := True; 2378 2379 end 2379 2380 else … … 2397 2398 while (cixFoundCity >= 0) and 2398 2399 (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do 2399 dec(cixFoundCity);2400 assert(cixFoundCity >= 0);2401 i:= 0;2402 while ( i < nEnemyCity) and (EnemyCity[i].Loc <> Loc) do2403 inc(i);2404 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 2405 2406 begin 2406 inc(nEnemyCity);2407 assert(nEnemyCity < necmax);2408 EnemyCity[ i].Status := 0;2409 EnemyCity[ i].SavedStatus := 0;2410 if pTell = pthen2411 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; 2412 2413 end; 2413 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[ i]);2414 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]); 2414 2415 end; 2415 2416 end … … 2420 2421 2421 2422 if Map[Loc] and fTerrain = fUNKNOWN then 2422 inc(Discovered[pTell]);2423 Inc(Discovered[pTell]); 2423 2424 if euix >= -1 then 2424 2425 Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or … … 2437 2438 Cardinal(Level) shl (2 * pTell); 2438 2439 end; 2439 end; // DiscoverTile2440 2441 function Discover9(Loc, p, Level: integer;2442 TellAllied, EnableContact: boolean): boolean;2443 var 2444 V9, Loc1, pTell, OldLevel: integer;2440 end; 2441 2442 function Discover9(Loc, P, Level: Integer; 2443 TellAllied, EnableContact: Boolean): Boolean; 2444 var 2445 V9, Loc1, pTell, OldLevel: Integer; 2445 2446 Radius: TVicinity8Loc; 2446 2447 begin 2447 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2448 result := false;2448 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2449 Result := False; 2449 2450 V8_to_Loc(Loc, Radius); 2450 2451 for V9 := 0 to 8 do … … 2458 2459 begin 2459 2460 for pTell := 0 to nPl - 1 do 2460 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2461 (RW[ p].Treaty[pTell] = trAlliance) then2461 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2462 (RW[P].Treaty[pTell] = trAlliance) then 2462 2463 begin 2463 2464 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2464 2465 if Level > OldLevel then 2465 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2466 or result;2466 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2467 or Result; 2467 2468 end; 2468 2469 end 2469 2470 else 2470 2471 begin 2471 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2472 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2472 2473 if Level > OldLevel then 2473 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2474 end; 2475 end; 2476 end; 2477 2478 function Discover21(Loc, p, AdjacentLevel: integer;2479 TellAllied, EnableContact: boolean): boolean;2480 var 2481 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; 2482 2483 Radius: TVicinity21Loc; 2483 2484 begin 2484 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2485 result := false;2485 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2486 Result := False; 2486 2487 AdjacentFlags := $00267620 shr 1; 2487 2488 V21_to_Loc(Loc, Radius); … … 2498 2499 begin 2499 2500 for pTell := 0 to nPl - 1 do 2500 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2501 (RW[ p].Treaty[pTell] = trAlliance) then2501 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2502 (RW[P].Treaty[pTell] = trAlliance) then 2502 2503 begin 2503 2504 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2504 2505 if Level > OldLevel then 2505 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2506 or result;2506 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2507 or Result; 2507 2508 end; 2508 2509 end 2509 2510 else 2510 2511 begin 2511 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2512 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2512 2513 if Level > OldLevel then 2513 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2514 Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result; 2514 2515 end; 2515 2516 end; … … 2518 2519 end; 2519 2520 2520 procedure DiscoverAll( p, Level: integer);2521 procedure DiscoverAll(P, Level: Integer); 2521 2522 { player p discovers complete playground (for supervisor) } 2522 2523 var 2523 Loc, OldLevel: integer;2524 begin 2525 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)); 2526 2527 for Loc := 0 to MapSize - 1 do 2527 2528 begin 2528 OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;2529 OldLevel := ObserveLevel[Loc] shr (2 * P) and 3; 2529 2530 if Level > OldLevel then 2530 DiscoverTile(Loc, p, p, Level, false);2531 end; 2532 end; 2533 2534 procedure DiscoverViewAreas( p: integer);2535 var 2536 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; 2537 2538 PModel: ^TModel; 2538 2539 begin // discover unit and city view areas 2539 2540 for pTell := 0 to nPl - 1 do 2540 if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then2541 if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then 2541 2542 begin 2542 2543 for uix := 0 to RW[pTell].nUn - 1 do … … 2546 2547 PModel := @RW[pTell].Model[mix]; 2547 2548 if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then 2548 Discover21(Loc, p, lObserveSuper, false, true)2549 Discover21(Loc, P, lObserveSuper, False, True) 2549 2550 else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or 2550 2551 (PModel.Domain = dAir) then 2551 Discover21(Loc, p, lObserveAll, false, false)2552 Discover21(Loc, P, lObserveAll, False, False) 2552 2553 else if (RealMap[Loc] and fTerrain = fMountains) or 2553 2554 (RealMap[Loc] and fTerImp = tiFort) or 2554 2555 (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0) 2555 2556 then 2556 Discover21(Loc, p, lObserveUnhidden, false,2557 Discover21(Loc, P, lObserveUnhidden, False, 2557 2558 PModel.Domain = dGround) 2558 2559 else 2559 Discover9(Loc, p, lObserveUnhidden, false,2560 Discover9(Loc, P, lObserveUnhidden, False, 2560 2561 PModel.Domain = dGround); 2561 2562 end; 2562 2563 for cix := 0 to RW[pTell].nCity - 1 do 2563 2564 if RW[pTell].City[cix].Loc >= 0 then 2564 Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);2565 Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True); 2565 2566 for ecix := 0 to RW[pTell].nEnemyCity - 1 do 2566 2567 begin // players know territory, so no use in hiding city owner … … 2574 2575 begin 2575 2576 RW[pTell].EnemyCity[ecix].Loc := -1; 2576 RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity 2577 RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity; 2577 2578 end; 2578 2579 end; … … 2581 2582 end; 2582 2583 2583 function GetUnitStack( p, Loc: integer): integer;2584 var 2585 uix: integer;2584 function GetUnitStack(P, Loc: Integer): Integer; 2585 var 2586 uix: Integer; 2586 2587 unx: ^TUn; 2587 2588 begin 2588 result := 0;2589 Result := 0; 2589 2590 if Occupant[Loc] < 0 then 2590 exit;2591 Exit; 2591 2592 for uix := 0 to RW[Occupant[Loc]].nUn - 1 do 2592 2593 begin … … 2594 2595 if unx.Loc = Loc then 2595 2596 begin 2596 MakeUnitInfo(Occupant[Loc], unx^, RW[ p].EnemyUn[RW[p].nEnemyUn + result]);2597 TellAboutModel( p, Occupant[Loc], unx.mix);2598 RW[ p].EnemyUn[RW[p].nEnemyUn + result].emix :=2599 RWemix[ p, Occupant[Loc], unx.mix];2600 inc(result);2601 end; 2602 end; 2603 end; 2604 2605 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); 2606 2607 // update maps and enemy units of all players after unit change 2607 2608 var 2608 p, euix, OldLevel: integer;2609 P, euix, OldLevel: Integer; 2609 2610 AddFlags, ClearFlags: Cardinal; 2610 2611 begin 2611 2612 if (Mode = moLoading_Fast) and not CityChange then 2612 exit;2613 for p:= 0 to nPl - 1 do2614 if 1 shl pand (GAlive or GWatching) <> 0 then2615 begin 2616 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; 2617 2618 if OldLevel > lNoObserve then 2618 2619 begin 2619 if RW[ p].Map[Loc] and (fUnit or fOwned) = fUnit then2620 if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then 2620 2621 begin 2621 2622 // replace unit located here in EnemyUn 2622 2623 // do not just set loc:=-1 because total number would be unlimited 2623 euix := RW[ p].nEnemyUn - 1;2624 euix := RW[P].nEnemyUn - 1; 2624 2625 while euix >= 0 do 2625 2626 begin 2626 if RW[ p].EnemyUn[euix].Loc = Loc then2627 if RW[P].EnemyUn[euix].Loc = Loc then 2627 2628 begin 2628 RW[ p].EnemyUn[euix].Loc := -1;2629 RW[P].EnemyUn[euix].Loc := -1; 2629 2630 Break; 2630 2631 end; 2631 dec(euix);2632 Dec(euix); 2632 2633 end; 2633 RW[ p].Map[Loc] := RW[p].Map[Loc] and not fUnit2634 RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit 2634 2635 end 2635 2636 else 2636 2637 begin // look for empty slot in EnemyUn 2637 euix := RW[ p].nEnemyUn - 1;2638 while (euix >= 0) and (RW[ p].EnemyUn[euix].Loc >= 0) do2639 dec(euix);2638 euix := RW[P].nEnemyUn - 1; 2639 while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do 2640 Dec(euix); 2640 2641 end; 2641 2642 if (Occupant[Loc] < 0) and not CityChange then … … 2644 2645 if RealMap[Loc] and fCity = 0 then 2645 2646 ClearFlags := ClearFlags or fOwned; 2646 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;2647 RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags; 2647 2648 end 2648 else if (Occupant[Loc] <> p) or CityChange then2649 else if (Occupant[Loc] <> P) or CityChange then 2649 2650 begin // city or enemy unit update necessary, call DiscoverTile 2650 ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));2651 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); 2652 2653 end 2653 2654 else { if (Occupant[Loc]=p) and not CityChange then } … … 2659 2660 else 2660 2661 ClearFlags := ClearFlags or fOwnZoCUnit; 2661 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;2662 end; 2663 end; 2664 end; 2665 end; 2666 2667 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); 2668 2669 // recalculate fInEnemyZoC flags around single tile 2669 2670 var 2670 V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;2671 V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer; 2671 2672 Tile1: ^Cardinal; 2672 2673 Adjacent, AdjacentAdjacent: TVicinity8Loc; 2673 2674 begin 2674 2675 if Mode = moLoading_Fast then 2675 exit;2676 ObserveMask := 3 shl (2 * p);2676 Exit; 2677 ObserveMask := 3 shl (2 * P); 2677 2678 V8_to_Loc(Loc, Adjacent); 2678 2679 for V8 := 0 to 7 do … … 2681 2682 if (Loc1 >= 0) and (Loc1 < MapSize) then 2682 2683 begin 2683 Tile1 := @RW[ p].Map[Loc1];2684 Tile1 := @RW[P].Map[Loc1]; 2684 2685 Tile1^ := Tile1^ and not fInEnemyZoC; 2685 2686 V8_to_Loc(Loc1, AdjacentAdjacent); … … 2691 2692 begin 2692 2693 p1 := Occupant[Loc2]; 2693 assert(p1 <> nPl);2694 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2694 Assert(p1 <> nPl); 2695 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2695 2696 begin 2696 2697 Tile1^ := Tile1^ or fInEnemyZoC; 2697 Break 2698 Break; 2698 2699 end; 2699 2700 end; … … 2703 2704 end; 2704 2705 2705 procedure RecalcMapZoC( p: integer);2706 procedure RecalcMapZoC(P: Integer); 2706 2707 // recalculate fInEnemyZoC flags for the whole map 2707 2708 var 2708 Loc, Loc1, V8, p1, ObserveMask: integer;2709 Loc, Loc1, V8, p1, ObserveMask: Integer; 2709 2710 Adjacent: TVicinity8Loc; 2710 2711 begin 2711 2712 if Mode = moLoading_Fast then 2712 exit;2713 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));2714 ObserveMask := 3 shl (2 * p);2713 Exit; 2714 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC))); 2715 ObserveMask := 3 shl (2 * P); 2715 2716 for Loc := 0 to MapSize - 1 do 2716 2717 if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then 2717 2718 begin 2718 2719 p1 := Occupant[Loc]; 2719 assert(p1 <> nPl);2720 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2720 Assert(p1 <> nPl); 2721 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2721 2722 begin // this non-allied enemy ZoC unit is known to this player -- set flags! 2722 2723 V8_to_Loc(Loc, Adjacent); … … 2725 2726 Loc1 := Adjacent[V8]; 2726 2727 if (Loc1 >= 0) and (Loc1 < MapSize) then 2727 RW[ p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC2728 end; 2729 end; 2730 end; 2731 end; 2732 2733 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); 2734 2735 // recalculate fPeace flags for the whole map 2735 2736 var 2736 Loc, p1: integer;2737 PeacePlayer: array [-1 .. nPl - 1] of boolean;2737 Loc, p1: Integer; 2738 PeacePlayer: array [-1 .. nPl - 1] of Boolean; 2738 2739 begin 2739 2740 if Mode <> moPlaying then 2740 exit;2741 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));2741 Exit; 2742 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace))); 2742 2743 for p1 := -1 to nPl - 1 do 2743 PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)2744 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]); 2745 2746 for Loc := 0 to MapSize - 1 do 2746 if PeacePlayer[RW[ p].Territory[Loc]] then2747 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; 2748 2749 end; 2749 2750 … … 2755 2756 BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal; 2756 2757 2757 procedure ChangeTerritory(Loc, p: integer);2758 var 2759 p1: integer;2760 begin 2761 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 2762 2763 Dec(TerritoryCount[RealMap[Loc] shr 27]); 2763 Inc(TerritoryCount[ p]);2764 RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal( p) shl 27;2765 if p= $F then2766 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; 2767 2768 for p1 := 0 to nPl - 1 do 2768 2769 if 1 shl p1 and (GAlive or GWatching) <> 0 then 2769 2770 if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then 2770 2771 begin 2771 RW[p1].Territory[Loc] := p;2772 if ( p < nPl) and (p <> p1) and (1 shl pand GAlive <> 0) and2773 (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 2774 2775 RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace 2775 2776 else … … 2778 2779 end; 2779 2780 2780 procedure ExpandTerritory(OriginLoc: integer);2781 var 2782 i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;2781 procedure ExpandTerritory(OriginLoc: Integer); 2782 var 2783 I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer; 2783 2784 begin 2784 2785 if OriginLoc = -1 then 2785 2786 raise Exception.Create('Location error'); 2786 i:= 0;2787 I := 0; 2787 2788 dyMax := 0; 2788 2789 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2789 inc(dyMax);2790 Inc(dyMax); 2790 2791 for dy := -dyMax to dyMax do 2791 2792 begin … … 2793 2794 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2794 2795 CountryRadius do 2795 inc(dxMax, 2);2796 Inc(dxMax, 2); 2796 2797 for dx := -dxMax to dxMax do 2797 2798 if (dy + dx) and 1 = 0 then 2798 2799 begin 2799 NewOwner := BorderChanges[ i div 8] shr (imod 8 * 4) and $F;2800 NewOwner := BorderChanges[I div 8] shr (I mod 8 * 4) and $F; 2800 2801 Loc := dLoc(OriginLoc, dx, dy); 2801 2802 if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then 2802 2803 ChangeTerritory(Loc, NewOwner); 2803 inc(i);2804 end; 2805 end; 2806 end; 2807 2808 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);2804 Inc(I); 2805 end; 2806 end; 2807 end; 2808 2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer); 2809 2810 // OriginLoc: only changes in CountryRadius around this location possible, 2810 2811 // -1 for complete map, -2 for double-check (no more changes allowed) … … 2812 2813 // player's territory, -1 for full border recalculation 2813 2814 var 2814 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; 2815 2816 NewOwner: Cardinal; 2816 2817 Adjacent: TVicinity8Loc; 2817 AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;2818 AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean; 2818 2819 Country, FormerCountry, { to who's country a tile belongs } 2819 2820 Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt; … … 2827 2828 StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0; 2828 2829 2829 for r:= 1 to CountryRadius shr 1 do2830 begin 2831 move(StolenDist, FormerDist, MapSize);2830 for R := 1 to CountryRadius shr 1 do 2831 begin 2832 Move(StolenDist, FormerDist, MapSize); 2832 2833 for Loc := 0 to MapSize - 1 do 2833 2834 if (FormerDist[Loc] <= CountryRadius - 2) … … 2861 2862 end; 2862 2863 2863 for r:= 1 to CountryRadius shr 1 do2864 begin 2865 move(Country, FormerCountry, MapSize);2866 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); 2867 2868 for Loc := 0 to MapSize - 1 do 2868 2869 if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above! … … 2870 2871 (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then 2871 2872 begin 2872 assert(FormerCountry[Loc] >= 0);2873 Assert(FormerCountry[Loc] >= 0); 2873 2874 V8_to_Loc(Loc, Adjacent); 2874 2875 for V8 := 0 to 7 do … … 2885 2886 end; 2886 2887 2887 FillChar(AtPeace, SizeOf(AtPeace), false);2888 FillChar(AtPeace, SizeOf(AtPeace), False); 2888 2889 for p1 := 0 to nPl - 1 do 2889 2890 if 1 shl p1 and GAlive <> 0 then … … 2891 2892 if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and 2892 2893 (RW[p1].Treaty[p2] >= trPeace) then 2893 AtPeace[p1, p2] := true;2894 AtPeace[p1, p2] := True; 2894 2895 2895 2896 if OriginLoc >= 0 then 2896 2897 begin // update area only 2897 i:= 0;2898 I := 0; 2898 2899 FillChar(BorderChanges, SizeOf(BorderChanges), 0); 2899 2900 dyMax := 0; 2900 2901 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2901 inc(dyMax);2902 Inc(dyMax); 2902 2903 for dy := -dyMax to dyMax do 2903 2904 begin … … 2905 2906 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2906 2907 CountryRadius do 2907 inc(dxMax, 2);2908 Inc(dxMax, 2); 2908 2909 for dx := -dxMax to dxMax do 2909 2910 if (dy + dx) and 1 = 0 then … … 2921 2922 else 2922 2923 ChangeTerritory(Loc, NewOwner); 2923 BorderChanges[ i shr 3] := BorderChanges[ishr 3] or2924 ((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); 2925 2926 end; 2926 inc(i);2927 Inc(I); 2927 2928 end; 2928 2929 end; … … 2937 2938 then 2938 2939 begin 2939 assert(OriginLoc <> -2); // test if border saving works2940 Assert(OriginLoc <> -2); // test if border saving works 2940 2941 ChangeTerritory(Loc, NewOwner); 2941 2942 end; … … 2944 2945 {$IFOPT O-} if OriginLoc <> -2 then 2945 2946 CheckBorders(-2); {$ENDIF} // check: single pass should do! 2946 end; // CheckBorders2947 2948 procedure LogCheckBorders( p, cix, PlayerLosingCity: integer);2949 begin 2950 CheckBorders(RW[ p].City[cix].Loc, PlayerLosingCity);2951 IntServer(sIntExpandTerritory, p, cix, BorderChanges);2947 end; 2948 2949 procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer); 2950 begin 2951 CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity); 2952 IntServer(sIntExpandTerritory, P, cix, BorderChanges); 2952 2953 end; 2953 2954 … … 2957 2958 } 2958 2959 2959 procedure CreateUnit( p, mix: integer);2960 begin 2961 with RW[ p] do2960 procedure CreateUnit(P, mix: Integer); 2961 begin 2962 with RW[P] do 2962 2963 begin 2963 2964 Un[nUn].mix := mix; 2964 2965 with Un[nUn] do 2965 2966 begin 2966 ID := UnBuilt[ p];2967 inc(UnBuilt[p]);2967 ID := UnBuilt[P]; 2968 Inc(UnBuilt[P]); 2968 2969 Status := 0; 2969 2970 SavedStatus := 0; 2970 inc(Model[mix].Built);2971 Inc(Model[mix].Built); 2971 2972 Home := -1; 2972 2973 Health := 100; … … 2976 2977 begin 2977 2978 Fuel := Model[mix].Cap[mcFuel]; 2978 Flags := Flags or unBombsLoaded 2979 Flags := Flags or unBombsLoaded; 2979 2980 end; 2980 2981 Job := jNone; … … 2984 2985 Master := -1; 2985 2986 end; 2986 inc(nUn);2987 Inc(nUn); 2987 2988 end 2988 2989 end; 2989 2990 2990 procedure FreeUnit( p, uix: integer);2991 procedure FreeUnit(P, uix: Integer); 2991 2992 // loc or master should be set after call 2992 2993 // implementation is critical for loading performance, change carefully 2993 2994 var 2994 Loc0, uix1: integer;2995 Occ, ZoC: boolean;2996 begin 2997 with RW[ p].Un[uix] do2995 Loc0, uix1: Integer; 2996 Occ, ZoC: Boolean; 2997 begin 2998 with RW[P].Un[uix] do 2998 2999 begin 2999 3000 Job := jNone; 3000 3001 Flags := Flags and not(unFortified or unMountainDelay); 3001 Loc0 := Loc 3002 Loc0 := Loc; 3002 3003 end; 3003 3004 if Occupant[Loc0] >= 0 then 3004 3005 begin 3005 assert(Occupant[Loc0] = p);3006 Occ := false;3007 ZoC := false;3008 for uix1 := 0 to RW[ p].nUn - 1 do3009 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 3010 3011 if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then 3011 3012 begin 3012 Occ := true;3013 if RW[ p].Model[mix].Flags and mdZOC <> 0 then3013 Occ := True; 3014 if RW[P].Model[mix].Flags and mdZOC <> 0 then 3014 3015 begin 3015 ZoC := true;3016 Break 3017 end 3016 ZoC := True; 3017 Break; 3018 end; 3018 3019 end; 3019 3020 if not Occ then … … 3024 3025 end; 3025 3026 3026 procedure PlaceUnit( p, uix: integer);3027 begin 3028 with RW[ p].Un[uix] do3029 begin 3030 Occupant[Loc] := p;3031 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 3032 3033 ZoCMap[Loc] := 1; 3033 3034 end; 3034 3035 end; 3035 3036 3036 procedure CountLost( p, mix, Enemy: integer);3037 begin 3038 Inc(RW[ p].Model[mix].Lost);3039 TellAboutModel(Enemy, p, mix);3040 Inc(Destroyed[Enemy, p, mix]);3041 end; 3042 3043 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); 3044 3045 // use enemy only from inside sMoveUnit if attack 3045 3046 var 3046 uix1: integer;3047 begin 3048 with RW[ p].Un[uix] do3049 begin 3050 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)); 3051 3052 // already freed when spy mission 3052 3053 if Loc >= 0 then 3053 FreeUnit( p, uix);3054 FreeUnit(P, uix); 3054 3055 if Master >= 0 then 3055 if RW[ p].Model[mix].Domain = dAir then3056 dec(RW[p].Un[Master].AirLoad)3056 if RW[P].Model[mix].Domain = dAir then 3057 Dec(RW[P].Un[Master].AirLoad) 3057 3058 else 3058 dec(RW[p].Un[Master].TroopLoad);3059 Dec(RW[P].Un[Master].TroopLoad); 3059 3060 if (TroopLoad > 0) or (AirLoad > 0) then 3060 for uix1 := 0 to RW[ p].nUn - 1 do3061 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 3062 3063 { unit mastered by removed unit -- remove too } 3063 3064 begin 3064 RW[ p].Un[uix1].Loc := -1;3065 RW[P].Un[uix1].Loc := -1; 3065 3066 if Enemy >= 0 then 3066 CountLost( p, RW[p].Un[uix1].mix, Enemy);3067 CountLost(P, RW[P].Un[uix1].mix, Enemy); 3067 3068 end; 3068 3069 Loc := -1; 3069 3070 if Enemy >= 0 then 3070 CountLost( p, mix, Enemy);3071 end; 3072 end; 3073 3074 procedure RemoveUnit_UpdateMap( p, uix: integer);3071 CountLost(P, mix, Enemy); 3072 end; 3073 end; 3074 3075 procedure RemoveUnit_UpdateMap(P, uix: Integer); 3075 3076 var 3076 3077 Loc0: Integer; 3077 3078 begin 3078 Loc0 := RW[ p].Un[uix].Loc;3079 RemoveUnit( p, uix);3079 Loc0 := RW[P].Un[uix].Loc; 3080 RemoveUnit(P, uix); 3080 3081 if Mode > moLoading_Fast then 3081 3082 UpdateUnitMap(Loc0); 3082 3083 end; 3083 3084 3084 procedure RemoveAllUnits( p, Loc: integer; Enemy: integer = -1);3085 var 3086 uix: integer;3087 begin 3088 for uix := 0 to RW[ p].nUn - 1 do3089 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 3090 3091 begin 3091 3092 if Enemy >= 0 then 3092 CountLost( p, RW[p].Un[uix].mix, Enemy);3093 RW[ p].Un[uix].Loc := -13093 CountLost(P, RW[P].Un[uix].mix, Enemy); 3094 RW[P].Un[uix].Loc := -1; 3094 3095 end; 3095 3096 Occupant[Loc] := -1; … … 3097 3098 end; 3098 3099 3099 procedure RemoveDomainUnits( d, p, Loc: integer);3100 var 3101 uix: integer;3102 begin 3103 for uix := 0 to RW[ p].nUn - 1 do3104 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) 3105 3106 then 3106 RemoveUnit( p, uix);3107 end; 3108 3109 procedure FoundCity( p, FoundLoc: integer);3110 var 3111 p1, cix1, V21, dx, dy: integer;3112 begin 3113 if RW[ p].nCity = ncmax then3114 exit;3115 inc(RW[p].nCity);3116 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 3117 3118 begin 3118 3119 Size := 2; … … 3130 3131 if UsedByCity[FoundLoc] >= 0 then 3131 3132 begin { central tile is exploited - toggle in exploiting city } 3132 p1 := p;3133 p1 := P; 3133 3134 SearchCity(UsedByCity[FoundLoc], p1, cix1); 3134 3135 dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy); … … 3141 3142 (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity; 3142 3143 3143 ChangeTerritory(Loc, p)3144 end; 3145 end; 3146 3147 procedure StealCity( p, cix: integer; SaveUnits: boolean);3148 var 3149 i, j, uix1, cix1, nearest: integer;3150 begin 3151 for i:= 0 to nWonder - 1 do3152 if RW[ p].City[cix].Built[i] = 1 then3153 begin 3154 GWonder[ i].EffectiveOwner := -1;3155 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 3156 3157 FreeSlaves; 3157 if i= woEiffel then // deactivate expired wonders3158 for j:= 0 to nWonder - 1 do3159 if GWonder[ j].EffectiveOwner = pthen3160 CheckExpiration( j);3161 end; 3162 for i:= nWonder to nImp - 1 do3163 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 3164 3165 begin { destroy national projects } 3165 RW[ p].NatBuilt[i] := 0;3166 if i= imGrWall then3167 GrWallContinent[ p] := -1;3168 end; 3169 3170 for uix1 := 0 to RW[ p].nUn - 1 do3171 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 3172 3173 if (Loc >= 0) and (Home = cix) then 3173 3174 if SaveUnits then 3174 3175 begin // support units by nearest other city 3175 3176 nearest := -1; 3176 for cix1 := 0 to RW[ p].nCity - 1 do3177 if (cix1 <> cix) and (RW[ p].City[cix1].Loc >= 0) and3178 ((nearest < 0) or (Distance(RW[ p].City[cix1].Loc, Loc) <3179 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 3180 3181 nearest := cix1; 3181 Home := nearest 3182 Home := nearest; 3182 3183 end 3183 3184 else 3184 RemoveUnit( p, uix1); // destroy supported units3185 end; 3186 3187 procedure DestroyCity( p, cix: integer; SaveUnits: boolean);3188 var 3189 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; 3190 3191 Radius: TVicinity21Loc; 3191 3192 begin 3192 StealCity( p, cix, SaveUnits);3193 with RW[ p].City[cix] do begin3194 for i:= 0 to nWonder - 1 do3195 if Built[ i] > 0 then3196 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; 3197 3198 V21_to_Loc(Loc, Radius); 3198 3199 for V21 := 1 to 26 do … … 3200 3201 UsedByCity[Radius[V21]] := -1; 3201 3202 RealMap[Loc] := RealMap[Loc] and not fCity; 3202 Loc := -1 3203 end; 3204 end; 3205 3206 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);3207 var 3208 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; 3209 3210 Radius: TVicinity21Loc; 3210 3211 begin 3211 inc(RW[pNew].nCity);3212 Inc(RW[pNew].nCity); 3212 3213 RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld]; 3213 StealCity(pOld, cixOld, false);3214 StealCity(pOld, cixOld, False); 3214 3215 RW[pOld].City[cixOld].Loc := -1; 3215 3216 with RW[pNew].City[(RW[pNew].nCity - 1)] do … … 3230 3231 begin 3231 3232 Loc1 := Radius[V21]; 3232 assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));3233 Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc)); 3233 3234 if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and 3234 3235 (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then … … 3242 3243 Built[imTownHall] := 0; 3243 3244 Built[imCourt] := 0; 3244 for i:= nWonder to nImp - 1 do3245 if Imp[ i].Kind <> ikCommon then3246 Built[ i] := 0; { destroy national projects }3247 for i:= 0 to nWonder - 1 do3248 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 3249 3250 begin // new wonder owner! 3250 GWonder[ i].EffectiveOwner := pNew;3251 if i= woEiffel then // reactivate expired wonders3252 begin 3253 for j:= 0 to nWonder - 1 do3254 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 3255 3256 for cix1 := 0 to (RW[pNew].nCity - 1) do 3256 if RW[pNew].City[cix1].Built[ j] = 1 then3257 GWonder[ j].EffectiveOwner := pNew;3257 if RW[pNew].City[cix1].Built[J] = 1 then 3258 GWonder[J].EffectiveOwner := pNew; 3258 3259 end 3259 3260 else 3260 CheckExpiration( i);3261 case iof3261 CheckExpiration(I); 3262 case I of 3262 3263 woLighthouse: 3263 3264 CheckSpecialModels(pNew, preLighthouse); … … 3273 3274 cix1 := RW[pNew].nEnemyCity - 1; 3274 3275 while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do 3275 dec(cix1);3276 assert(cix1 >= 0);3276 Dec(cix1); 3277 Assert(cix1 >= 0); 3277 3278 RW[pNew].EnemyCity[cix1].Loc := -1; 3278 3279 … … 3281 3282 end; 3282 3283 3283 procedure CompleteJob( p, Loc, Job: integer);3284 var 3285 ChangedTerrain, p1: integer;3286 begin 3287 assert(Job <> jCity);3284 procedure CompleteJob(P, Loc, Job: Integer); 3285 var 3286 ChangedTerrain, p1: Integer; 3287 begin 3288 Assert(Job <> jCity); 3288 3289 ChangedTerrain := -1; 3289 3290 case Job of … … 3327 3328 if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then 3328 3329 begin 3329 RemoveDomainUnits(dSea, p, Loc);3330 RemoveDomainUnits(dSea, P, Loc); 3330 3331 RealMap[Loc] := RealMap[Loc] and not fCanal; 3331 3332 end; … … 3339 3340 begin 3340 3341 if RealMap[Loc] and fTerImp = tiBase then 3341 RemoveDomainUnits(dAir, p, Loc);3342 RemoveDomainUnits(dAir, P, Loc); 3342 3343 RealMap[Loc] := RealMap[Loc] and not fTerImp 3343 3344 end 3344 3345 else if RealMap[Loc] and fCanal <> 0 then 3345 3346 begin 3346 RemoveDomainUnits(dSea, p, Loc);3347 RemoveDomainUnits(dSea, P, Loc); 3347 3348 RealMap[Loc] := RealMap[Loc] and not fCanal 3348 3349 end … … 3374 3375 fPoll) or RealMap[Loc] and (fTerrain or fSpecial or fTerImp or 3375 3376 fRoad or fRR or fCanal or fPoll); 3376 end; // CompleteJob3377 end; 3377 3378 3378 3379 { … … 3380 3381 ____________________________________________________________________ 3381 3382 } 3382 procedure GiveCivilReport( p, pAbout: integer);3383 begin 3384 with RW[ p].EnemyReport[pAbout]^ do3383 procedure GiveCivilReport(P, pAbout: Integer); 3384 begin 3385 with RW[P].EnemyReport[pAbout]^ do 3385 3386 begin 3386 3387 // general info 3387 3388 TurnOfCivilReport := LastValidStat[pAbout]; 3388 move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));3389 Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty)); 3389 3390 Government := RW[pAbout].Government; 3390 3391 Money := RW[pAbout].Money; … … 3395 3396 if ResearchDone > 100 then 3396 3397 ResearchDone := 100; 3397 move(RW[pAbout].Tech, Tech, nAdv);3398 end; 3399 end; 3400 3401 procedure GiveMilReport( p, pAbout: integer);3402 var 3403 uix, mix: integer;3404 begin 3405 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 3406 3407 begin 3407 3408 TurnOfMilReport := LastValidStat[pAbout]; … … 3409 3410 for mix := 0 to RW[pAbout].nModel - 1 do 3410 3411 begin 3411 TellAboutModel( p, pAbout, mix);3412 TellAboutModel(P, pAbout, mix); 3412 3413 UnCount[mix] := 0 3413 3414 end; 3414 3415 for uix := 0 to RW[pAbout].nUn - 1 do 3415 3416 if RW[pAbout].Un[uix].Loc >= 0 then 3416 inc(UnCount[RW[pAbout].Un[uix].mix]);3417 end; 3418 end; 3419 3420 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); 3421 3422 begin 3422 3423 case Price and opMask of … … 3433 3434 end; 3434 3435 3435 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;3436 var 3437 i: integer;3436 function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean; 3437 var 3438 I: Integer; 3438 3439 rSender, rTarget: ^TEnemyReport; 3439 3440 begin // copy third nation civil report 3440 result := false;3441 Result := False; 3441 3442 if RW[pTarget].Treaty[pAbout] = trNoContact then 3442 3443 IntroduceEnemy(pTarget, pAbout); 3443 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3444 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3444 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3445 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3445 3446 if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then 3446 3447 begin // only if newer than current information … … 3451 3452 rTarget.ResearchTech := rSender.ResearchTech; 3452 3453 rTarget.ResearchDone := rSender.ResearchDone; 3453 result := true;3454 end; 3455 for i:= 0 to nAdv - 1 do3456 if rTarget.Tech[ i] < rSender.Tech[i] then3457 begin 3458 rTarget.Tech[ i] := rSender.Tech[i];3459 result := true;3460 end; 3461 end; 3462 3463 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;3464 var 3465 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; 3466 3467 rSender, rTarget: ^TEnemyReport; 3467 3468 begin // copy third nation military report 3468 result := false;3469 Result := False; 3469 3470 if RW[pTarget].Treaty[pAbout] = trNoContact then 3470 3471 IntroduceEnemy(pTarget, pAbout); 3471 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3472 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3472 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3473 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3473 3474 if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then 3474 3475 begin // only if newer than current information 3475 3476 rTarget.TurnOfMilReport := rSender.TurnOfMilReport; 3476 3477 rTarget.nModelCounted := rSender.nModelCounted; 3477 move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);3478 Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted); 3478 3479 for mix := 0 to rTarget.nModelCounted - 1 do 3479 3480 TellAboutModel(pTarget, pAbout, mix); 3480 result := true;3481 end; 3482 end; 3483 3484 procedure CopyModel(pSender, pTarget, mix: integer);3485 var 3486 i: integer;3481 Result := True; 3482 end; 3483 end; 3484 3485 procedure CopyModel(pSender, pTarget, mix: Integer); 3486 var 3487 I: Integer; 3487 3488 miSender, miTarget: TModelInfo; 3488 ok: boolean;3489 ok: Boolean; 3489 3490 begin 3490 3491 // only if target doesn't already have a model like this 3491 3492 ok := RW[pTarget].nModel < nmmax; 3492 3493 MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender); 3493 for i:= 0 to RW[pTarget].nModel - 1 do3494 begin 3495 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); 3496 3497 if IsSameModel(miSender, miTarget) then 3497 ok := false;3498 ok := False; 3498 3499 end; 3499 3500 if ok then … … 3510 3511 Lost := 0; 3511 3512 end; 3512 inc(RW[pTarget].nModel);3513 inc(Researched[pTarget]);3513 Inc(RW[pTarget].nModel); 3514 Inc(Researched[pTarget]); 3514 3515 TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1); 3515 3516 end; 3516 3517 end; 3517 3518 3518 procedure CopyMap(pSender, pTarget: integer);3519 var 3520 Loc, i, cix: integer;3519 procedure CopyMap(pSender, pTarget: Integer); 3520 var 3521 Loc, I, cix: Integer; 3521 3522 Tile: Cardinal; 3522 3523 begin … … 3528 3529 if Tile and fCity <> 0 then 3529 3530 begin 3530 i:= 0;3531 while ( i< RW[pTarget].nEnemyCity) and3532 (RW[pTarget].EnemyCity[ i].Loc <> Loc) do3533 inc(i);3534 if i= RW[pTarget].nEnemyCity then3535 begin 3536 inc(RW[pTarget].nEnemyCity);3537 assert(RW[pTarget].nEnemyCity < necmax);3538 RW[pTarget].EnemyCity[ i].Status := 0;3539 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; 3540 3541 end; 3541 3542 if Tile and fOwned <> 0 then … … 3543 3544 cix := RW[pSender].nCity - 1; 3544 3545 while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do 3545 dec(cix);3546 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[ i]);3546 Dec(cix); 3547 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]); 3547 3548 end 3548 3549 else // city not owned by sender -- copy old info … … 3550 3551 cix := RW[pSender].nEnemyCity - 1; 3551 3552 while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do 3552 dec(cix);3553 RW[pTarget].EnemyCity[ i] := RW[pSender].EnemyCity[cix];3553 Dec(cix); 3554 RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix]; 3554 3555 end; 3555 3556 end … … 3565 3566 3566 3567 if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then 3567 inc(Discovered[pTarget]);3568 Inc(Discovered[pTarget]); 3568 3569 RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC 3569 3570 // always preserve this flag! … … 3581 3582 end; 3582 3583 3583 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;3584 var 3585 pSubject, i, n, NewTreaty: integer;3586 begin 3587 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; 3588 3589 case Price and opMask of 3589 3590 opCivilReport: // + turn + concerned player shl 16 … … 3591 3592 pSubject := Price shr 16 and $F; 3592 3593 if pTarget = pSubject then 3593 result := false3594 Result := False 3594 3595 else if pSender = pSubject then 3595 3596 begin 3596 3597 if execute then 3597 GiveCivilReport(pTarget, pSender) 3598 GiveCivilReport(pTarget, pSender); 3598 3599 end 3599 3600 else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then 3600 result := false3601 Result := False 3601 3602 else if execute then 3602 3603 CopyCivilReport(pSender, pTarget, pSubject); … … 3606 3607 pSubject := Price shr 16 and $F; 3607 3608 if pTarget = pSubject then 3608 result := false3609 Result := False 3609 3610 else if pSender = pSubject then 3610 3611 begin 3611 3612 if execute then 3612 GiveMilReport(pTarget, pSender) 3613 GiveMilReport(pTarget, pSender); 3613 3614 end 3614 3615 else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then 3615 result := false3616 Result := False 3616 3617 else if execute then 3617 CopyMilReport(pSender, pTarget, pSubject) 3618 CopyMilReport(pSender, pTarget, pSubject); 3618 3619 end; 3619 3620 opMap: … … 3628 3629 begin // agreed treaty end 3629 3630 if execute then 3630 CancelTreaty(pSender, pTarget, false)3631 CancelTreaty(pSender, pTarget, False); 3631 3632 end 3632 3633 else … … 3639 3640 NewTreaty := trPeace; 3640 3641 if NewTreaty < 0 then 3641 result := false3642 Result := False 3642 3643 else if execute then 3643 3644 begin 3644 assert(NewTreaty > RW[pSender].Treaty[pTarget]);3645 Assert(NewTreaty > RW[pSender].Treaty[pTarget]); 3645 3646 RW[pSender].Treaty[pTarget] := NewTreaty; 3646 3647 RW[pTarget].Treaty[pSender] := NewTreaty; … … 3671 3672 opShipParts: // + number + part type shl 16 3672 3673 begin 3673 n:= Price and $FFFF; // number3674 i:= Price shr 16 and $F; // type3675 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 3676 3677 begin 3677 3678 if execute then 3678 3679 begin 3679 dec(GShip[pSender].Parts[i], n);3680 RW[pSender].Ship[pSender].Parts[ i] := GShip[pSender].Parts[i];3681 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]; 3682 3683 if RW[pTarget].NatBuilt[imSpacePort] > 0 then 3683 3684 begin // space ship control requires space port 3684 inc(GShip[pTarget].Parts[i], n);3685 RW[pSender].Ship[pTarget].Parts[ i] := GShip[pTarget].Parts[i];3686 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]; 3687 3688 end; 3688 3689 end; 3689 3690 end 3690 3691 else 3691 result := false;3692 Result := False; 3692 3693 end; 3693 3694 opMoney: // + value … … 3697 3698 if execute then 3698 3699 begin 3699 dec(RW[pSender].Money, Price - opMoney);3700 inc(RW[pTarget].Money, Price - opMoney);3700 Dec(RW[pSender].Money, Price - opMoney); 3701 Inc(RW[pTarget].Money, Price - opMoney); 3701 3702 end; 3702 3703 end 3703 3704 else 3704 result := false;3705 Result := False; 3705 3706 opTribute: // + value 3706 3707 if execute then … … 3717 3718 end 3718 3719 else 3719 result := false;3720 Result := False; 3720 3721 opAllTech: 3721 3722 if execute then 3722 for i:= 0 to nAdv - 1 do3723 if (RW[pSender].Tech[ i] >= tsApplicable) and3724 (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 3725 3726 begin 3726 SeeTech(pTarget, i);3727 RW[pSender].EnemyReport[pTarget].Tech[ i] := tsSeen;3728 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; 3729 3730 end; 3730 3731 opModel: // + model index … … 3732 3733 begin 3733 3734 if execute then 3734 CopyModel(pSender, pTarget, Price - opModel) 3735 CopyModel(pSender, pTarget, Price - opModel); 3735 3736 end 3736 3737 else 3737 result := false;3738 Result := False; 3738 3739 opAllModel: 3739 3740 if execute then 3740 for i:= 0 to RW[pSender].nModel - 1 do3741 begin 3742 TellAboutModel(pTarget, pSender, i);3743 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); 3744 3745 end; 3745 3746 { opCity: // + city ID 3746 3747 begin 3747 result:=false3748 Result:=False 3748 3749 end; } 3749 end 3750 end; 3751 3752 procedure CancelTreaty( p, pWith: integer; DecreaseCredibility: boolean);3750 end; 3751 end; 3752 3753 procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean); 3753 3754 // side effect: PeaceEnded := bitarray of players with which peace treaty was canceled 3754 3755 var 3755 p1, OldTreaty: integer;3756 begin 3757 OldTreaty := RW[ p].Treaty[pWith];3756 p1, OldTreaty: Integer; 3757 begin 3758 OldTreaty := RW[P].Treaty[pWith]; 3758 3759 PeaceEnded := 0; 3759 3760 if OldTreaty >= trPeace then 3760 RW[ p].LastCancelTreaty[pWith] := GTurn;3761 RW[P].LastCancelTreaty[pWith] := GTurn; 3761 3762 if DecreaseCredibility then 3762 3763 begin … … 3764 3765 trPeace: 3765 3766 begin 3766 RW[ p].Credibility := RW[p].Credibility shr 1;3767 if RW[ p].MaxCredibility > 0 then3768 dec(RW[p].MaxCredibility, 10);3769 if RW[ p].Credibility > RW[p].MaxCredibility then3770 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; 3771 3772 end; 3772 3773 trAlliance: 3773 RW[ p].Credibility := RW[p].Credibility * 3 div 4;3774 end; 3775 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; 3776 3777 end; 3777 3778 … … 3779 3780 begin 3780 3781 for p1 := 0 to nPl - 1 do 3781 if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and3782 (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) 3783 3784 then 3784 3785 begin 3785 RW[ p].Treaty[p1] := trNone;3786 RW[p1].Treaty[ p] := trNone;3787 RW[ p].EvaStart[p1] := -PeaceEvaTurns - 1;3788 RW[p1].EvaStart[ p] := -PeaceEvaTurns - 1;3789 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); 3790 3791 end; 3791 3792 CheckBorders(-1); 3792 3793 if (Mode > moLoading_Fast) and (PeaceEnded > 0) then 3793 RecalcMapZoC( p);3794 RecalcMapZoC(P); 3794 3795 end 3795 3796 else 3796 3797 begin 3797 RW[ p].Treaty[pWith] := OldTreaty - 1;3798 RW[pWith].Treaty[ p] := OldTreaty - 1;3798 RW[P].Treaty[pWith] := OldTreaty - 1; 3799 RW[pWith].Treaty[P] := OldTreaty - 1; 3799 3800 if OldTreaty = TrFriendlyContact then 3800 3801 begin // necessary for loading 3801 GiveCivilReport( p, pWith);3802 GiveCivilReport(pWith, p);3802 GiveCivilReport(P, pWith); 3803 GiveCivilReport(pWith, P); 3803 3804 end 3804 3805 else if OldTreaty = trAlliance then 3805 3806 begin // necessary for loading 3806 GiveMilReport( p, pWith);3807 GiveMilReport(pWith, p);3807 GiveMilReport(P, pWith); 3808 GiveMilReport(pWith, P); 3808 3809 end; 3809 3810 if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then 3810 3811 begin 3811 RecalcMapZoC( p);3812 RecalcMapZoC(P); 3812 3813 RecalcMapZoC(pWith); 3813 3814 end; … … 3815 3816 if OldTreaty in [trPeace, trAlliance] then 3816 3817 begin 3817 RecalcPeaceMap( p);3818 RecalcPeaceMap(P); 3818 3819 RecalcPeaceMap(pWith); 3819 3820 end; 3820 3821 end; 3821 3822 3822 function DoSpyMission( p, pCity, cix, Mission: integer): Cardinal;3823 var 3824 p1: integer;3825 begin 3826 result := 0;3823 function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal; 3824 var 3825 p1: Integer; 3826 begin 3827 Result := 0; 3827 3828 case Mission of 3828 3829 smSabotageProd: … … 3831 3832 smStealMap: 3832 3833 begin 3833 CopyMap(pCity, p);3834 RecalcPeaceMap( p);3834 CopyMap(pCity, P); 3835 RecalcPeaceMap(P); 3835 3836 end; 3836 3837 smStealCivilReport: 3837 3838 begin 3838 if RW[ p].Treaty[pCity] = trNoContact then3839 IntroduceEnemy( p, pCity);3840 GiveCivilReport( p, pCity);3839 if RW[P].Treaty[pCity] = trNoContact then 3840 IntroduceEnemy(P, pCity); 3841 GiveCivilReport(P, pCity); 3841 3842 end; 3842 3843 smStealMilReport: 3843 3844 begin 3844 if RW[ p].Treaty[pCity] = trNoContact then3845 IntroduceEnemy( p, pCity);3846 GiveMilReport( p, pCity);3845 if RW[P].Treaty[pCity] = trNoContact then 3846 IntroduceEnemy(P, pCity); 3847 GiveMilReport(P, pCity); 3847 3848 end; 3848 3849 smStealForeignReports: 3849 3850 begin 3850 3851 for p1 := 0 to nPl - 1 do 3851 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) 3852 3853 then 3853 3854 begin 3854 3855 if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then 3855 if CopyCivilReport(pCity, p, p1) then3856 result := result or (1 shl (2 * p1));3856 if CopyCivilReport(pCity, P, p1) then 3857 Result := Result or (1 shl (2 * p1)); 3857 3858 if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then 3858 if CopyMilReport(pCity, p, p1) then3859 result := result or (2 shl (2 * p1));3859 if CopyMilReport(pCity, P, p1) then 3860 Result := Result or (2 shl (2 * p1)); 3860 3861 end; 3861 3862 end; … … 3867 3868 ____________________________________________________________________ 3868 3869 } 3869 procedure ClearTestFlags(ClearFlags: integer);3870 var 3871 p1: integer;3870 procedure ClearTestFlags(ClearFlags: Integer); 3871 var 3872 p1: Integer; 3872 3873 begin 3873 3874 GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or … … 3878 3879 end; 3879 3880 3880 procedure SetTestFlags( p, SetFlags: integer);3881 var 3882 i, p1, p2, MoreFlags: integer;3881 procedure SetTestFlags(P, SetFlags: Integer); 3882 var 3883 I, p1, p2, MoreFlags: Integer; 3883 3884 begin 3884 3885 MoreFlags := SetFlags and not GTestFlags; … … 3895 3896 begin // make p1 and p2 know each other 3896 3897 if RW[p1].Treaty[p2] = trNoContact then 3897 IntroduceEnemy(p1, p2) 3898 IntroduceEnemy(p1, p2); 3898 3899 end; 3899 3900 … … 3904 3905 if 1 shl p1 and GAlive <> 0 then 3905 3906 begin 3906 for i:= 0 to nAdv - 1 do // give all techs to player p13907 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 3908 3909 begin 3909 RW[p1].Tech[ i] := tsCheat;3910 CheckSpecialModels(p1, i);3910 RW[p1].Tech[I] := tsCheat; 3911 CheckSpecialModels(p1, I); 3911 3912 end; 3912 3913 for p2 := 0 to nPl - 1 do 3913 3914 if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then 3914 for i:= 1 to 3 do3915 if RW[p2].EnemyReport[p1].Tech[AgePreq[ i]] < tsApplicable then3916 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; 3917 3918 end; 3918 3919 end; … … 3920 3921 if MoreFlags and tfUncover <> 0 then 3921 3922 begin 3922 DiscoverAll( p, lObserveSuper);3923 DiscoverAll(P, lObserveSuper); 3923 3924 for p1 := 0 to nPl - 1 do 3924 3925 if 1 shl p1 and GAlive <> 0 then 3925 3926 begin 3926 3927 ResourceMask[p1] := $FFFFFFFF; 3927 if p1 <> pthen3928 begin 3929 GiveCivilReport( p, p1);3930 GiveMilReport( p, p1);3928 if p1 <> P then 3929 begin 3930 GiveCivilReport(P, p1); 3931 GiveMilReport(P, p1); 3931 3932 end; 3932 3933 end; … … 3938 3939 ____________________________________________________________________ 3939 3940 } 3940 procedure IntServer(Command, Player, Subject: integer; var Data); 3941 var 3942 i, p1: integer; 3943 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); 4033 4033 DiscoverViewAreas(Subject); 4034 Break 4035 end 4034 Break; 4035 end; 4036 4036 end; 4037 4037 4038 4038 sIntSetDevModel: 4039 4039 if Mode < moPlaying then 4040 move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4);4040 Move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4); 4041 4041 4042 4042 sIntSetModelStatus: … … 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); 4072 end; 4073 4074 end; { case command } 4075 end; { IntServer } 4071 RW[Player].EnemyCity[Subject].Status := Integer(Data); 4072 end; 4073 end; 4074 end; 4076 4075 4077 4076 end. -
branches/highdpi/Direct.lfm
r246 r465 8 8 Caption = 'C-evo' 9 9 Color = clBtnFace 10 DesignTimePPI = 1 2510 DesignTimePPI = 144 11 11 Font.Color = clWindowText 12 Font.Height = - 1312 Font.Height = -20 13 13 Font.Name = 'MS Sans Serif' 14 14 FormStyle = fsStayOnTop … … 17 17 OnPaint = FormPaint 18 18 OnShow = FormShow 19 LCLVersion = '1.8.0.6'20 PixelsPerInch = 9619 ShowInTaskBar = stNever 20 LCLVersion = '2.2.6.0' 21 21 Scaled = False 22 22 end -
branches/highdpi/Direct.pas
r405 r465 7 7 UDpiControls, Messg, 8 8 9 LCLIntf, LCLType, {$IFDEF Linux}LMessages, {$ENDIF}Messages, SysUtils, Classes,9 LCLIntf, LCLType, {$IFDEF UNIX}LMessages, {$ENDIF}Messages, SysUtils, Classes, 10 10 Graphics, Controls, Forms, DrawDlg, GameServer; 11 11 … … 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; … … 40 40 DirectDlg: TDirectDlg; 41 41 42 42 43 implementation 43 44 44 45 uses 45 ScreenTools, Protocol, Start, LocalPlayer, NoTerm, Back, Global, UNetworkServer,46 UNetworkClient;46 ScreenTools, Protocol, Start, LocalPlayer, NoTerm, Back, Global, NetworkServer, 47 NetworkClient; 47 48 48 49 {$R *.lfm} … … 57 58 // hMem: Cardinal; 58 59 // p: pointer; 59 s: string;60 S: string; 60 61 Begin 61 62 case ID of … … 72 73 if visible then 73 74 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);75 S := Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]); 76 while BiColorTextWidth(Canvas, S) + 64 > ClientWidth do 77 Delete(S, Length(S), 1); 78 SetInfo(S); 78 79 end; 79 80 ntCreateWorld: … … 111 112 hMem := GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE, 112 113 Length(NotifyMessage)); 113 p:= GlobalLock(hMem);114 if p<> nil then115 move(NotifyMessage[1], p^, Length(NotifyMessage));114 P := GlobalLock(hMem); 115 if P <> nil then 116 Move(NotifyMessage[1], P^, Length(NotifyMessage)); 116 117 GlobalUnlock(hMem); 117 118 SetClipboardData(CF_TEXT, hMem); … … 153 154 State := -1; 154 155 Show; 155 {$IFDEF LINUX} 156 // Force shown window repaint on Gtk2 widgetset 157 Sleep(1); 158 DpiApplication.ProcessMessages; 159 {$ENDIF} 156 Gtk2Fix; 160 157 Invalidate; 161 158 Update; … … 183 180 BrainTerm.Name := Phrases.Lookup('HUMAN'); 184 181 if NetworkEnabled then begin 185 BrainNetworkServer.Client := UNetworkServer.Client;182 BrainNetworkServer.Client := NetworkServer.Client; 186 183 BrainNetworkServer.Name := Phrases.Lookup('NETWORK_SERVER'); 187 BrainNetworkClient.Client := UNetworkClient.Client;184 BrainNetworkClient.Client := NetworkClient.Client; 188 185 BrainNetworkClient.Name := Phrases.Lookup('NETWORK_CLIENT'); 189 186 end; … … 198 195 begin 199 196 PostMessage(Handle, WM_GO, 0, 0); 200 Gone := true;197 Gone := True; 201 198 end; 202 199 end; … … 209 206 procedure TDirectDlg.OnGo(var Msg: TMessage); 210 207 var 211 i: integer;212 s: string;208 I: Integer; 209 S: string; 213 210 FileName: string; 214 211 begin … … 220 217 Exit; 221 218 end; 222 Quick := false;219 Quick := False; 223 220 if ParamCount > 0 then 224 221 begin 225 s:= ParamStr(1);226 if ( s[1] = '-') {$IFDEF WINDOWS}or (s[1] = '/'){$ENDIF} then222 S := ParamStr(1); 223 if (S[1] = '-') {$IFDEF WINDOWS}or (S[1] = '/'){$ENDIF} then 227 224 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' then225 Delete(S, 1, 1); 226 for I := 1 to Length(S) do 227 if S[I] in ['a' .. 'z'] then 228 Dec(S[I], 32); 229 if S = 'MAN' then 233 230 begin 234 Quick := true;231 Quick := True; 235 232 DirectHelp(cHelpOnly); 236 233 Close; … … 242 239 Quick := True; 243 240 if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1) 244 ), -1, false) then begin241 ), -1, False) then begin 245 242 SimpleMessage(Phrases.Lookup('LOADERR')); 246 243 Close; … … 280 277 procedure TDirectDlg.FormPaint(Sender: TObject); 281 278 begin 282 PaintBackground( self, 3, 3, ClientWidth - 6, ClientHeight - 6);279 PaintBackground(Self, 3, 3, ClientWidth - 6, ClientHeight - 6); 283 280 Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0); 284 281 Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2, … … 297 294 end; 298 295 299 procedure TDirectDlg.SetInfo( x: string);300 begin 301 Info := x;296 procedure TDirectDlg.SetInfo(X: string); 297 begin 298 Info := X; 302 299 Invalidate; 303 300 Update; 304 {$IFDEF LINUX}301 {$IFDEF UNIX} 305 302 DpiApplication.ProcessMessages; 306 303 {$ENDIF} 307 304 end; 308 305 309 procedure TDirectDlg.SetState( x: integer);310 begin 311 if ( x< 0) <> (State < 0) then begin312 State := x;306 procedure TDirectDlg.SetState(X: Integer); 307 begin 308 if (X < 0) <> (State < 0) then begin 309 State := X; 313 310 Invalidate; 314 311 Update; 315 312 end 316 else if x<> State then begin317 State := x;313 else if X <> State then begin 314 State := X; 318 315 PaintProgressBar(Canvas, 6, ClientWidth div 2 - 64, 40, State, 128 - State, 319 316 128, MainTexture); -
branches/highdpi/GameServer.pas
r405 r465 7 7 8 8 uses 9 Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,10 Graphics, UBrain, Global;9 Protocol, Database, dynlibs, Platform, dateutils, LazFileUtils, Graphics, 10 Brain, Global; 11 11 12 12 const … … 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} 157 end 157 end; 158 158 end; 159 159 … … 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 }556 MapFile. write(MaxTurn, 4);557 MapFile. write(lx, 4);558 MapFile. write(ly, 4);559 MapFile. write(RealMap, MapSize * 4);552 S := 'cEvoMap'#0; 553 MapFile.Write(S[1], 8); { file id } 554 I := 0; 555 MapFile.Write(I, 4); { format id } 556 MapFile.Write(MaxTurn, 4); 557 MapFile.Write(lx, 4); 558 MapFile.Write(ly, 4); 559 MapFile.Write(RealMap, MapSize * 4); 560 560 finally 561 561 FreeAndNil(MapFile); … … 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); // MaxTurn581 MapFile. read(lx, 4);582 MapFile. read(ly, 4);580 MapFile.Read(I, 4); // MaxTurn 581 MapFile.Read(lx, 4); 582 MapFile.Read(ly, 4); 583 583 ly := ly and not 1; 584 584 if lx > lxmax then … … 587 587 ly := lymax; 588 588 MapSize := lx * ly; 589 MapFile. read(RealMap, MapSize * 4);589 MapFile.Read(RealMap, MapSize * 4); 590 590 for Loc1 := 0 to MapSize - 1 do 591 591 begin … … 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; 632 632 633 if auto and AutoSaveExists then // append to existing file633 if Auto and AutoSaveExists then // append to existing file 634 634 LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or 635 635 fmShareExclusive) … … 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 }646 LogFile. write(ExeInfo.Time, 4);647 LogFile. write(lx, 4);648 LogFile. write(ly, 4);649 LogFile. write(LandMass, 4);642 S := 'cEvoBook'; 643 LogFile.Write(S[1], 8); { file id } 644 I := CevoVersion; 645 LogFile.Write(I, 4); { c-evo version } 646 LogFile.Write(ExeInfo.Time, 4); 647 LogFile.Write(lx, 4); 648 LogFile.Write(ly, 4); 649 LogFile.Write(LandMass, 4); 650 650 if LandMass = 0 then 651 LogFile. write(MapField^, MapSize * 4);652 653 LogFile. write(MaxTurn, 4);654 LogFile. write(RND, 4);655 LogFile. write(GTurn, 4);651 LogFile.Write(MapField^, MapSize * 4); 652 653 LogFile.Write(MaxTurn, 4); 654 LogFile.Write(RND, 4); 655 LogFile.Write(GTurn, 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 LogFile. write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);663 for i:= 0 to nPl - 1 do664 if not Assigned(bix[ i]) then665 LogFile. write(zero, 4)662 LogFile.Write(SaveMap, ((MapSize - 1) div 4 + 1) * 4); 663 for I := 0 to nPl - 1 do 664 if not Assigned(bix[I]) then 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 681 if auto and AutoSaveExists then681 if Auto and AutoSaveExists then 682 682 CL.AppendToFile(LogFile, AutoSaveState) 683 683 else 684 684 CL.SaveToFile(LogFile); 685 685 FreeAndNil(LogFile); 686 if auto then686 if Auto then 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] := nil817 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;837 838 { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); {}836 RW[P].DefaultDebugMap := nil; 837 838 { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); } 839 839 end; 840 840 … … 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; … … 958 958 if Mode >= moMovie then 959 959 Notify(ntEndInfo); 960 end; { StartGame }960 end; 961 961 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); … … 1139 1139 LogFile.Read(SaveMap, 4); 1140 1140 if SaveMap[0] <> $80 then 1141 LogFile. read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);1141 LogFile.Read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 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} … … 1324 1324 Inform(pTurn); 1325 1325 ChangeClientWhenDone(cResume, 0, nil^, 0); 1326 end; // LoadGame1326 end; 1327 1327 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 … … 1810 1810 end; 1811 1811 end; 1812 exit1812 Exit; 1813 1813 end; 1814 1814 … … 1824 1824 DiscoverTech(pTurn, ResearchTech); 1825 1825 1826 dec(Research, Cost);1826 Dec(Research, Cost); 1827 1827 Happened := Happened or phTech; 1828 ResearchTech := -1 1828 ResearchTech := -1; 1829 1829 end 1830 1830 else if (ResearchTech = -2) and (nCity > 0) then … … 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); 1861 end 1861 end; 1862 1862 end; 1863 1863 if WinOnAlone and (GAlive and not(1 shl pTurn or 1) = 0) then … … 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 … … 1908 1908 end; 1909 1909 // CheckContact; 1910 end; { BeforeTurn }1910 end; 1911 1911 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 … … 2035 2035 CheckWin(p1); 2036 2036 end; 2037 end; // Afterturn2037 end; 2038 2038 2039 2039 procedure NextPlayer; … … 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 end; // ExecuteMove2292 2293 function ExecuteAttack( p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;2294 ShowMove: TShowMove): integer;2291 end; 2292 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 … … 2559 2559 end; 2560 2560 end; 2561 end; // ExecuteAttack2562 2563 function MoveUnit( p, uix, dx, dy: integer; TestOnly: boolean): integer;2561 end; 2562 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; 2613 end; // with2614 end; { MoveUnit }2615 2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;2617 2618 function CountPrice(const Offer: TOffer; PriceType: integer): integer;2613 end; 2614 end; 2615 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; … … 2698 2698 ShowShipChange: TShowShipChange; 2699 2699 ShowNegoData: TShowNegoData; 2700 logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: boolean; 2701 2702 begin { >>>server } 2700 logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: Boolean; 2701 begin 2703 2702 if Command = sTurn then 2704 2703 begin … … 2709 2708 end; 2710 2709 2711 assert(MapSize = lx * ly);2712 assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);2710 Assert(MapSize = lx * ly); 2711 Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute); 2713 2712 // not for internal commands 2714 2713 if (Command < 0) or (Command >= $10000) then 2715 2714 begin 2716 result := eUnknown;2717 exit;2715 Result := eUnknown; 2716 Exit; 2718 2717 end; 2719 2718 … … 2722 2721 ((Subject < 0) or (Subject >= $1000))) then 2723 2722 begin 2724 result := eInvalid;2725 exit;2723 Result := eInvalid; 2724 Exit; 2726 2725 end; 2727 2726 … … 2732 2731 begin 2733 2732 PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player])); 2734 result := eNoTurn;2735 exit;2733 Result := eNoTurn; 2734 Exit; 2736 2735 end; 2737 2736 2738 result := eOK;2737 Result := eOK; 2739 2738 2740 2739 // check if command allowed now … … 2759 2758 PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x', 2760 2759 [Player, Command shr 4])); 2761 result := eNoTurn;2762 exit;2760 Result := eNoTurn; 2761 Exit; 2763 2762 end; 2764 2763 … … 2768 2767 HandoverStack[nHandoverStack] := Player + $1000; 2769 2768 HandoverStack[nHandoverStack + 1] := Command; 2770 inc(nHandoverStack, 2);2769 Inc(nHandoverStack, 2); 2771 2770 2772 2771 InvalidTreatyMap := 0; … … 2781 2780 FormerCLState := CL.State; 2782 2781 CL.Put(Command, Player, Subject, @Data); 2783 logged := true;2782 logged := True; 2784 2783 end 2785 2784 else 2786 logged := false;2785 logged := False; 2787 2786 2788 2787 case Command of … … 2799 2798 2800 2799 sGetDebugMap: 2801 pointer(Data) := DebugMap[Subject];2800 Pointer(Data) := DebugMap[Subject]; 2802 2801 2803 2802 { sChangeSuperView: 2804 2803 if Difficulty[Player]=0 then 2805 2804 begin 2806 for i:=0 to nBrain-1 do if Brain[i].Initialized then2807 CallClient( i, cShowSuperView, Subject)2805 for I:=0 to nBrain-1 do if Brain[I].Initialized then 2806 CallClient(I, cShowSuperView, Subject) 2808 2807 end 2809 else result:=eInvalid; }2808 else Result:=eInvalid; } 2810 2809 2811 2810 sRefreshDebugMap: … … 2830 2829 else 2831 2830 StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1; 2832 move(Stat[Command shr 4 and $F, Subject]^, Data,2833 StopTurn * SizeOf( integer));2831 Move(Stat[Command shr 4 and $F, Subject]^, Data, 2832 StopTurn * SizeOf(Integer)); 2834 2833 FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) * 2835 SizeOf( integer), 0);2834 SizeOf(Integer), 0); 2836 2835 end 2837 2836 else 2838 result := eInvalid;2837 Result := eInvalid; 2839 2838 2840 2839 sGetTechCost: 2841 integer(Data) := TechCost(Player);2840 Integer(Data) := TechCost(Player); 2842 2841 2843 2842 sGetAIInfo: 2844 2843 if AIInfo[Subject] = '' then 2845 pchar(Data) := nil2846 else 2847 pchar(Data) := @AIInfo[Subject][1];2844 PChar(Data) := nil 2845 else 2846 PChar(Data) := @AIInfo[Subject][1]; 2848 2847 2849 2848 sGetAICredits: 2850 2849 if AICredits = '' then 2851 pchar(Data) := nil2852 else 2853 pchar(Data) := @AICredits[1];2850 PChar(Data) := nil 2851 else 2852 PChar(Data) := @AICredits[1]; 2854 2853 2855 2854 sGetVersion: 2856 integer(Data) := CevoVersion;2855 Integer(Data) := CevoVersion; 2857 2856 2858 2857 sGetGameChanged: 2859 2858 if Player <> 0 then 2860 result := eInvalid2859 Result := eInvalid 2861 2860 else if (CL <> nil) and (CL.State.nLog = nLogOpened) and 2862 2861 (CL.State.MoveCode = 0) and not HasCityTileChanges and 2863 2862 not HasChanges(Player) then 2864 result := eNotChanged;2863 Result := eNotChanged; 2865 2864 2866 2865 sGetTileInfo: 2867 2866 if (Subject >= 0) and (Subject < MapSize) then 2868 result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))2869 else 2870 result := eInvalid;2867 Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data)) 2868 else 2869 Result := eInvalid; 2871 2870 2872 2871 sGetCityTileInfo: 2873 2872 if (Subject >= 0) and (Subject < MapSize) then 2874 result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))2875 else 2876 result := eInvalid;2873 Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data)) 2874 else 2875 Result := eInvalid; 2877 2876 2878 2877 sGetHypoCityTileInfo: … … 2881 2880 if (TTileInfo(Data).ExplCity < 0) or 2882 2881 (TTileInfo(Data).ExplCity >= RW[Player].nCity) then 2883 result := eInvalid2882 Result := eInvalid 2884 2883 else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2885 result := eNoPreq2884 Result := eNoPreq 2886 2885 else 2887 result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,2886 Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject, 2888 2887 TTileInfo(Data)); 2889 2888 end 2890 2889 else 2891 result := eInvalid;2890 Result := eInvalid; 2892 2891 2893 2892 sGetJobProgress: … … 2895 2894 begin 2896 2895 if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2897 result := eNoPreq2896 Result := eNoPreq 2898 2897 else 2899 result := GetJobProgress(Player, Subject, TJobProgressData(Data));2898 Result := GetJobProgress(Player, Subject, TJobProgressData(Data)); 2900 2899 end 2901 2900 else 2902 result := eInvalid;2901 Result := eInvalid; 2903 2902 2904 2903 sGetModels: … … 2912 2911 end 2913 2912 else 2914 result := eInvalid;2913 Result := eInvalid; 2915 2914 2916 2915 sGetUnits: 2917 2916 if (Subject >= 0) and (Subject < MapSize) and 2918 2917 (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then 2919 integer(Data) := GetUnitStack(Player, Subject)2920 else 2921 result := eNoPreq;2918 Integer(Data) := GetUnitStack(Player, Subject) 2919 else 2920 Result := eNoPreq; 2922 2921 2923 2922 sGetDefender: 2924 2923 if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player) 2925 2924 then 2926 Strongest(Subject, integer(Data), d, i, j)2927 else 2928 result := eInvalid;2925 Strongest(Subject, Integer(Data), D, I, J) 2926 else 2927 Result := eInvalid; 2929 2928 2930 2929 sGetBattleForecast, sGetBattleForecastEx: … … 2936 2935 ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then 2937 2936 begin 2938 result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,2937 Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1, 2939 2938 cix1, AStr, DStr, ABaseDamage, DBaseDamage); 2940 2939 if Command = sGetBattleForecastEx then … … 2945 2944 TBattleForecastEx(Data).DBaseDamage := DBaseDamage; 2946 2945 end; 2947 if result = eOK then2948 result := eInvalid; // no enemy unit there!2946 if Result = eOK then 2947 Result := eInvalid; // no enemy unit there! 2949 2948 end 2950 2949 else 2951 result := eInvalid2952 else 2953 result := eInvalid;2950 Result := eInvalid 2951 else 2952 Result := eInvalid; 2954 2953 2955 2954 sGetUnitReport: 2956 2955 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2957 2956 (RW[Player].Un[Subject].Loc < 0) then 2958 result := eInvalid2957 Result := eInvalid 2959 2958 else 2960 2959 GetUnitReport(Player, Subject, TUnitReport(Data)); … … 2963 2962 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2964 2963 (RW[Player].Un[Subject].Loc < 0) then 2965 result := eInvalid2966 else 2967 result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));2964 Result := eInvalid 2965 else 2966 Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data)); 2968 2967 2969 2968 sGetPlaneReturn: … … 2971 2970 (RW[Player].Un[Subject].Loc < 0) or 2972 2971 (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then 2973 result := eInvalid2972 Result := eInvalid 2974 2973 else 2975 2974 begin 2976 2975 if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then 2977 result := eOK2976 Result := eOK 2978 2977 else 2979 result := eNoWay;2978 Result := eNoWay; 2980 2979 end; 2981 2980 … … 2988 2987 Owner := Player; 2989 2988 SearchCity(Subject, Owner, cix1); 2990 c:= RW[Owner].City[cix1];2991 if (Owner <> Player) and ( c.Project and cpImp = 0) then2992 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); 2993 2992 end 2994 2993 else 2995 result := eInvalid;2994 Result := eInvalid; 2996 2995 2997 2996 sGetCityReport: 2998 2997 if (Subject < 0) or (Subject >= RW[Player].nCity) or 2999 2998 (RW[Player].City[Subject].Loc < 0) then 3000 result := eInvalid3001 else 3002 result := GetCityReport(Player, Subject, TCityReport(Data));2999 Result := eInvalid 3000 else 3001 Result := GetCityReport(Player, Subject, TCityReport(Data)); 3003 3002 3004 3003 sGetCityReportNew: 3005 3004 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3006 3005 (RW[Player].City[Subject].Loc < 0) then 3007 result := eInvalid3006 Result := eInvalid 3008 3007 else 3009 3008 GetCityReportNew(Player, Subject, TCityReportNew(Data)); … … 3012 3011 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3013 3012 (RW[Player].City[Subject].Loc < 0) then 3014 result := eInvalid3013 Result := eInvalid 3015 3014 else 3016 3015 GetCityAreaInfo(Player, RW[Player].City[Subject].Loc, … … 3032 3031 end 3033 3032 else 3034 result := eInvalid;3033 Result := eInvalid; 3035 3034 3036 3035 sGetEnemyCityReportNew: … … 3049 3048 end 3050 3049 else 3051 result := eInvalid;3050 Result := eInvalid; 3052 3051 3053 3052 sGetEnemyCityAreaInfo: … … 3063 3062 end 3064 3063 else 3065 result := eInvalid;3064 Result := eInvalid; 3066 3065 3067 3066 sGetCityTileAdvice: 3068 3067 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3069 3068 (RW[Player].City[Subject].Loc < 0) then 3070 result := eInvalid3069 Result := eInvalid 3071 3070 else 3072 3071 GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data)); … … 3081 3080 EditTile(Loc, NewTile) 3082 3081 else 3083 result := eInvalid;3082 Result := eInvalid; 3084 3083 3085 3084 sRandomMap: … … 3087 3086 begin 3088 3087 CreateElevation; 3089 PreviewElevation := false;3090 CreateMap( false);3088 PreviewElevation := False; 3089 CreateMap(False); 3091 3090 FillChar(ObserveLevel, MapSize * 4, 0); 3092 3091 DiscoverAll(Player, lObserveSuper); 3093 3092 end 3094 3093 else 3095 result := eInvalid;3094 Result := eInvalid; 3096 3095 3097 3096 sMapGeneratorRequest: 3098 3097 if not MapGeneratorAvailable then 3099 result := eInvalid;3098 Result := eInvalid; 3100 3099 3101 3100 { … … 3105 3104 sTurn, sTurn - sExecute: 3106 3105 begin 3107 AllHumansDead := true;3106 AllHumansDead := True; 3108 3107 for p1 := 0 to nPl - 1 do 3109 3108 if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then 3110 AllHumansDead := false;3109 AllHumansDead := False; 3111 3110 if (pDipActive >= 0) // still in negotiation mode 3112 3111 or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or 3113 3112 (Difficulty[0] > 0) and AllHumansDead) then // game end reached 3114 result := eViolation3113 Result := eViolation 3115 3114 else if Command >= sExecute then 3116 3115 begin … … 3123 3122 begin 3124 3123 LogChanges; 3125 SaveGame('~' + LogFileName, true);3124 SaveGame('~' + LogFileName, True); 3126 3125 end; 3127 3126 {$ENDIF} … … 3138 3137 TotalFood := 0; 3139 3138 TotalProd := 0; 3140 for i:= 0 to RW[pTurn].nCity - 1 do3141 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 3142 3141 begin 3143 inc(TotalFood, RW[pTurn].City[i].Food);3144 inc(TotalProd, RW[pTurn].City[i].Prod);3142 Inc(TotalFood, RW[pTurn].City[I].Food); 3143 Inc(TotalProd, RW[pTurn].City[I].Prod); 3145 3144 end; 3146 3145 CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 + … … 3153 3152 begin 3154 3153 if CheckSum <> Subject then 3155 LoadOK := false;3154 LoadOK := False; 3156 3155 end 3157 3156 else // save checksum … … 3180 3179 pTurn := (pTurn + 1) mod nPl; 3181 3180 if pTurn = 0 then 3182 inc(GTurn);3181 Inc(GTurn); 3183 3182 if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then 3184 3183 begin // already made extinct -- continue statistics … … 3219 3218 sBreak, sResign, sNextRound, sReload: 3220 3219 if Mode = moMovie then 3221 MovieStopped := true3220 MovieStopped := True 3222 3221 else 3223 3222 begin … … 3225 3224 begin 3226 3225 ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and 3227 ( integer(Data) >= 0) and (integer(Data) < GTurn);3226 (Integer(Data) >= 0) and (Integer(Data) < GTurn); 3228 3227 for p1 := 1 to nPl - 1 do 3229 3228 if bix[p1].Kind = btTerm then 3230 ok := false;3229 ok := False; 3231 3230 // allow reload in AI-only games only 3232 3231 end … … 3237 3236 if (Command = sBreak) or (Command = sResign) then 3238 3237 Notify(ntBackOn); 3239 for i:= 0 to Brains.Count - 1 do3240 if Brains[ i].Initialized then3238 for I := 0 to Brains.Count - 1 do 3239 if Brains[I].Initialized then 3241 3240 begin 3242 if Brains[ i].Kind = btAI then3243 Notify(ntDeinitModule, i);3244 CallClient( i, cBreakGame, nil^);3241 if Brains[I].Kind = btAI then 3242 Notify(ntDeinitModule, I); 3243 CallClient(I, cBreakGame, nil^); 3245 3244 end; 3246 3245 Notify(ntEndInfo); … … 3249 3248 LogCityTileChanges; 3250 3249 LogChanges; 3251 SaveGame(LogFileName, false);3250 SaveGame(LogFileName, False); 3252 3251 end; 3253 3252 DeleteFile(SavePath + '~' + LogFileName); … … 3262 3261 LandMass, MaxTurn); 3263 3262 sReload: 3264 LoadGame(SavePath, LogFileName, integer(Data), false);3263 LoadGame(SavePath, LogFileName, Integer(Data), False); 3265 3264 end; 3266 3265 end 3267 3266 else 3268 result := eInvalid;3267 Result := eInvalid; 3269 3268 end; 3270 3269 … … 3283 3282 end 3284 3283 else 3285 result := eInvalid;3284 Result := eInvalid; 3286 3285 3287 3286 scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact 3288 3287 - sExecute + (nPl - 1) shl 4: 3289 3288 if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then 3290 result := eInvalid3289 Result := eInvalid 3291 3290 else if GWinner > 0 then 3292 result := eViolation // game end reached3291 Result := eViolation // game end reached 3293 3292 else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then 3294 result := eNoPreq3293 Result := eNoPreq 3295 3294 else if GTurn < GColdWarStart + ColdWarTurns then 3296 result := eColdWar3295 Result := eColdWar 3297 3296 else if RW[Player].Government = gAnarchy then 3298 result := eAnarchy3297 Result := eAnarchy 3299 3298 else if RW[Command shr 4 and $F].Government = gAnarchy then 3300 3299 begin 3301 result := eAnarchy;3300 Result := eAnarchy; 3302 3301 LastEndClientCommand := scReject; // enable cancel treaty 3303 3302 pContacted := Command shr 4 and $F; … … 3307 3306 pContacted := Command shr 4 and $F; 3308 3307 pDipActive := pContacted; 3309 assert(Mode = moPlaying);3308 Assert(Mode = moPlaying); 3310 3309 Inform(pDipActive); 3311 3310 ChangeClientWhenDone(scContact, pDipActive, pTurn, 4); … … 3318 3317 begin // contact requested and not accepted yet 3319 3318 pDipActive := -1; 3320 assert(Mode = moPlaying);3319 Assert(Mode = moPlaying); 3321 3320 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3322 3321 end; 3323 3322 end 3324 3323 else 3325 result := eInvalid;3324 Result := eInvalid; 3326 3325 3327 3326 scDipStart, scDipStart - sExecute: … … 3334 3333 RW[pTurn].Credibility; 3335 3334 pDipActive := pTurn; 3336 assert(Mode = moPlaying);3335 Assert(Mode = moPlaying); 3337 3336 IntServer(sIntHaveContact, pTurn, pContacted, nil^); 3338 3337 ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0); … … 3340 3339 end 3341 3340 else 3342 result := eInvalid;3341 Result := eInvalid; 3343 3342 3344 3343 scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak, … … 3347 3346 if pDipActive >= 0 then 3348 3347 begin 3349 assert(Mode = moPlaying);3348 Assert(Mode = moPlaying); 3350 3349 if pDipActive = pTurn then 3351 3350 p1 := pContacted … … 3363 3362 // check if offer can be accepted 3364 3363 if nDeliver + nCost = 0 then 3365 result := eOfferNotAcceptable;3366 for i:= 0 to nDeliver + nCost - 1 do3367 if Price[ i] = opChoose then3368 result := eOfferNotAcceptable;3369 for i:= 0 to nCost - 1 do3370 if not PayPrice(pDipActive, p1, Price[nDeliver + i], false) then3371 result := eOfferNotAcceptable;3372 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 3373 3372 begin 3374 3373 IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive, … … 3377 3376 3378 3377 // tell other players about ship part trades 3379 HasShipChanged := false;3378 HasShipChanged := False; 3380 3379 FillChar(ShowShipChange, SizeOf(ShowShipChange), 0); 3381 for i:= 0 to nDeliver + nCost - 1 do3382 if Price[ i] and opMask = opShipParts then3380 for I := 0 to nDeliver + nCost - 1 do 3381 if Price[I] and opMask = opShipParts then 3383 3382 begin 3384 HasShipChanged := true;3385 if i>= nDeliver then3383 HasShipChanged := True; 3384 if I >= nDeliver then 3386 3385 begin // p1 has demanded from pDipActive 3387 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3388 + integer(Price[i] and $FFFF);3389 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3390 - 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); 3391 3390 end 3392 3391 else 3393 3392 begin // p1 has delivered to pDipActive 3394 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3395 - integer(Price[i] and $FFFF);3396 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3397 + 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); 3398 3397 end; 3399 3398 end; … … 3407 3406 (1 shl p2 and (GAlive or GWatching) <> 0) then 3408 3407 begin 3409 move(GShip, RW[p2].Ship, SizeOf(GShip));3408 Move(GShip, RW[p2].Ship, SizeOf(GShip)); 3410 3409 if 1 shl p2 and GWatching <> 0 then 3411 3410 CallPlayer(cShowShipChange, p2, ShowShipChange); … … 3420 3419 (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns) 3421 3420 then 3422 result := eCancelTreatyRush3421 Result := eCancelTreatyRush 3423 3422 else if Command >= sExecute then 3424 3423 begin … … 3427 3426 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3428 3427 begin 3429 i:= p1 shl 4 + pDipActive;3430 CallPlayer(cShowSupportAllianceAgainst, p2, i);3428 I := p1 shl 4 + pDipActive; 3429 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3431 3430 end; 3432 3431 for p2 := 0 to nPl - 1 do 3433 3432 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3434 3433 begin 3435 i:= p2;3436 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);3434 I := p2; 3435 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I); 3437 3436 end; 3438 3437 end; 3439 3438 end 3440 3439 else 3441 result := eInvalid;3442 if (Command >= sExecute) and ( result >= rExecuted) then3440 Result := eInvalid; 3441 if (Command >= sExecute) and (Result >= rExecuted) then 3443 3442 if LastEndClientCommand = scDipBreak then 3444 3443 begin // break negotiation … … 3462 3461 end 3463 3462 else 3464 result := eInvalid;3463 Result := eInvalid; 3465 3464 3466 3465 scDipOffer, scDipOffer - sExecute: … … 3475 3474 pDipActive := -1; 3476 3475 CallPlayer(cShowEndContact, pContacted, nil^); 3477 assert(Mode = moPlaying);3476 Assert(Mode = moPlaying); 3478 3477 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3479 3478 end; … … 3488 3487 if RW[pDipActive].Treaty[p1] < trPeace then 3489 3488 begin // no tribute allowed! 3490 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3491 if (TOffer(Data).Price[ i] and opMask = opTribute) then3492 result := eInvalidOffer;3493 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3494 if (TOffer(Data).Price[ i] = opTreaty + trPeace) then3495 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; 3496 3495 end; 3497 for i:= 0 to TOffer(Data).nDeliver - 1 do3498 if (TOffer(Data).Price[ i] <> opChoose) and3499 not PayPrice(pDipActive, p1, TOffer(Data).Price[ i], false) then3500 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; 3501 3500 if CountPrice(TOffer(Data), opTreaty) > 1 then 3502 result := eInvalidOffer;3503 for i:= 0 to nShipPart - 1 do3504 if CountPrice(TOffer(Data), opShipParts + ishl 16) > 1 then3505 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; 3506 3505 if CountPrice(TOffer(Data), opMoney) > 1 then 3507 result := eInvalidOffer;3506 Result := eInvalidOffer; 3508 3507 if CountPrice(TOffer(Data), opTribute) > 1 then 3509 result := eInvalidOffer;3508 Result := eInvalidOffer; 3510 3509 case CountPrice(TOffer(Data), opChoose) of 3511 3510 0: … … 3513 3512 1: 3514 3513 if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then 3515 result := eInvalidOffer;3514 Result := eInvalidOffer; 3516 3515 else 3517 result := eInvalidOffer;3516 Result := eInvalidOffer; 3518 3517 end; 3519 3518 3520 3519 // !!! check here if cost can be demanded 3521 3520 3522 if (Command >= sExecute) and ( result >= rExecuted) then3521 if (Command >= sExecute) and (Result >= rExecuted) then 3523 3522 begin 3524 3523 OfferFullySupported := (TOffer(Data).nDeliver <= 2) and 3525 3524 (TOffer(Data).nCost <= 2); // >2 no more allowed 3526 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3525 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3527 3526 begin 3528 if TOffer(Data).Price[ i] and opMask = opTribute then3529 OfferFullySupported := false;3527 if TOffer(Data).Price[I] and opMask = opTribute then 3528 OfferFullySupported := False; 3530 3529 // tribute no more part of the game 3531 if (TOffer(Data).Price[ i] and opMask = opTreaty) and3532 (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]) 3533 3532 then 3534 OfferFullySupported := false;3533 OfferFullySupported := False; 3535 3534 // agreed treaty end no more part of the game 3536 if TOffer(Data).Price[ i] = opTreaty + trCeaseFire then3537 OfferFullySupported := false;3535 if TOffer(Data).Price[I] = opTreaty + trCeaseFire then 3536 OfferFullySupported := False; 3538 3537 // ceasefire no more part of the game 3539 3538 end; … … 3560 3559 LastOffer := TOffer(Data); 3561 3560 // show offered things to receiver 3562 for i:= 0 to LastOffer.nDeliver - 1 do3563 ShowPrice(pDipActive, p1, LastOffer.Price[ i]);3561 for I := 0 to LastOffer.nDeliver - 1 do 3562 ShowPrice(pDipActive, p1, LastOffer.Price[I]); 3564 3563 pDipActive := p1; 3565 assert(Mode = moPlaying);3564 Assert(Mode = moPlaying); 3566 3565 ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer, 3567 3566 SizeOf(LastOffer)); 3568 end 3569 end 3567 end; 3568 end; 3570 3569 end 3571 3570 else 3572 result := eInvalid;3571 Result := eInvalid; 3573 3572 3574 3573 { … … 3583 3582 end 3584 3583 else 3585 result := eInvalid;3584 Result := eInvalid; 3586 3585 3587 3586 sSetTestFlag: … … 3593 3592 end 3594 3593 else 3595 result := eInvalid;3594 Result := eInvalid; 3596 3595 3597 3596 sSetGovernment, sSetGovernment - sExecute: … … 3599 3598 {$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF} 3600 3599 if RW[Player].Happened and phChangeGov = 0 then 3601 result := eViolation3600 Result := eViolation 3602 3601 else if RW[Player].Government = Subject then 3603 result := eNotChanged3602 Result := eNotChanged 3604 3603 else if (Subject >= nGov) then 3605 result := eInvalid3604 Result := eInvalid 3606 3605 else if (Subject >= gMonarchy) and 3607 3606 (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then 3608 result := eNoPreq3607 Result := eNoPreq 3609 3608 else if Command >= sExecute then 3610 3609 begin … … 3614 3613 then 3615 3614 RW[p1].EnemyReport[Player].Government := Subject; 3616 end 3615 end; 3617 3616 end; 3618 3617 … … 3621 3620 {$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF} 3622 3621 if Subject and $F + Subject shr 4 > 10 then 3623 result := eInvalid3622 Result := eInvalid 3624 3623 else if (RW[Player].TaxRate = Subject and $F * 10) and 3625 3624 (RW[Player].LuxRate = Subject shr 4 * 10) then 3626 result := eNotChanged3625 Result := eNotChanged 3627 3626 else if Command >= sExecute then 3628 3627 begin 3629 3628 RW[Player].TaxRate := Subject and $F * 10; 3630 3629 RW[Player].LuxRate := Subject shr 4 * 10; 3631 end 3630 end; 3632 3631 end; 3633 3632 … … 3636 3635 {$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF} 3637 3636 if RW[Player].Government = gAnarchy then 3638 result := eInvalid3637 Result := eInvalid 3639 3638 else 3640 3639 begin … … 3658 3657 if (Mode = moPlaying) and (Subject = adMilitary) and 3659 3658 (DevModelTurn[Player] <> GTurn) then 3660 result := eNoModel3659 Result := eNoModel 3661 3660 else if Subject <> adMilitary then 3662 3661 begin … … 3664 3663 begin 3665 3664 if Tech[Subject] >= MaxFutureTech_Computing then 3666 result := eInvalid;3665 Result := eInvalid; 3667 3666 end 3668 3667 else if Subject in FutureTech then 3669 3668 begin 3670 3669 if Tech[Subject] >= MaxFutureTech then 3671 result := eInvalid;3670 Result := eInvalid; 3672 3671 end 3673 3672 else if Tech[Subject] >= tsApplicable then 3674 result := eInvalid; // already discovered3673 Result := eInvalid; // already discovered 3675 3674 if Tech[Subject] <> tsSeen then // look if preqs met 3676 3675 if AdvPreq[Subject, 2] <> preNone then 3677 3676 begin // 2 of 3 required 3678 i:= 0;3679 for j:= 0 to 2 do3680 if Tech[AdvPreq[Subject, j]] >= tsApplicable then3681 inc(i);3682 if i< 2 then3683 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; 3684 3683 end 3685 3684 else if (AdvPreq[Subject, 0] <> preNone) and … … 3687 3686 (AdvPreq[Subject, 1] <> preNone) and 3688 3687 (Tech[AdvPreq[Subject, 1]] < tsApplicable) then 3689 result := eNoPreq;3688 Result := eNoPreq; 3690 3689 end; 3691 if ( result = eOK) and (Command >= sExecute) then3690 if (Result = eOK) and (Command >= sExecute) then 3692 3691 begin 3693 3692 if (Mode = moPlaying) and (Subject = adMilitary) then … … 3698 3697 end 3699 3698 else 3700 result := eViolation;3699 Result := eViolation; 3701 3700 end; 3702 3701 … … 3706 3705 {$ENDIF} 3707 3706 if RW[Player].Happened and phStealTech = 0 then 3708 result := eInvalid3707 Result := eInvalid 3709 3708 else if (Subject >= nAdv) or (Subject in FutureTech) or 3710 3709 (RW[Player].Tech[Subject] >= tsSeen) or 3711 3710 (RW[GStealFrom].Tech[Subject] < tsApplicable) then 3712 result := eInvalid3711 Result := eInvalid 3713 3712 else if Command >= sExecute then 3714 3713 begin 3715 3714 SeeTech(Player, Subject); 3716 dec(RW[Player].Happened, phStealTech);3715 Dec(RW[Player].Happened, phStealTech); 3717 3716 end; 3718 3717 end; … … 3725 3724 if (Subject >= nAttitude) or (p1 >= nPl) or 3726 3725 (RW[Player].EnemyReport[p1] = nil) then 3727 result := eInvalid3726 Result := eInvalid 3728 3727 else if RW[Player].Treaty[p1] = trNoContact then 3729 result := eNoPreq3728 Result := eNoPreq 3730 3729 else if RW[Player].Attitude[p1] = Subject then 3731 result := eNotChanged3730 Result := eNotChanged 3732 3731 else if Command >= sExecute then 3733 3732 begin … … 3740 3739 if (LastEndClientCommand <> scReject) or 3741 3740 (RW[Player].Treaty[pContacted] < trPeace) then 3742 result := eInvalid3741 Result := eInvalid 3743 3742 else if (ServerVersion[Player] >= $010100) and 3744 3743 (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns) 3745 3744 then 3746 result := eCancelTreatyRush3745 Result := eCancelTreatyRush 3747 3746 else if Command >= sExecute then 3748 3747 begin … … 3752 3751 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3753 3752 begin 3754 i:= pContacted shl 4 + Player;3755 CallPlayer(cShowSupportAllianceAgainst, p2, i);3753 I := pContacted shl 4 + Player; 3754 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3756 3755 end; 3757 3756 for p2 := 0 to nPl - 1 do 3758 3757 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3759 3758 begin 3760 i:= p2;3761 CallPlayer(cShowCancelTreatyByAlliance, Player, i);3759 I := p2; 3760 CallPlayer(cShowCancelTreatyByAlliance, Player, I); 3762 3761 end; 3763 3762 LastEndClientCommand := sTurn; … … 3772 3771 {$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF} 3773 3772 if Subject >= 4 then 3774 result := eInvalid3773 Result := eInvalid 3775 3774 else if (upgrade[Subject, 0].Preq <> preNone) and 3776 3775 (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then 3777 result := eNoPreq3776 Result := eNoPreq 3778 3777 else if Command >= sExecute then 3779 3778 begin … … 3786 3785 Upgrades := 0; 3787 3786 FutureMCost := 0; 3788 for i:= 0 to nUpgrade - 1 do3789 with upgrade[Domain, i] do3787 for I := 0 to nUpgrade - 1 do 3788 with upgrade[Domain, I] do 3790 3789 if (Preq = preNone) or (Preq >= 0) and 3791 3790 ((RW[Player].Tech[Preq] >= tsApplicable) or … … 3794 3793 if Preq in FutureTech then 3795 3794 begin 3796 j:= RW[Player].Tech[Preq];3797 inc(FutureMCost, j* Cost);3795 J := RW[Player].Tech[Preq]; 3796 Inc(FutureMCost, J * Cost); 3798 3797 end 3799 3798 else 3800 3799 begin 3801 j:= 1;3800 J := 1; 3802 3801 if Cost > MCost then 3803 3802 MCost := Cost; 3804 3803 end; 3805 inc(Upgrades, 1 shl i);3806 inc(MStrength, j* Strength);3807 inc(MTrans, j* Trans);3804 Inc(Upgrades, 1 shl I); 3805 Inc(MStrength, J * Strength); 3806 Inc(MTrans, J * Trans); 3808 3807 end; 3809 inc(MCost, FutureMCost);3808 Inc(MCost, FutureMCost); 3810 3809 FillChar(Cap, SizeOf(Cap), 0); 3811 3810 Cap[mcOffense] := 2; 3812 3811 Cap[mcDefense] := 1; 3813 for i:= 0 to nFeature - 1 do3814 with Feature[ i] do3812 for I := 0 to nFeature - 1 do 3813 with Feature[I] do 3815 3814 if (1 shl Domain and Domains <> 0) and 3816 3815 ((Preq = preNone) or (Preq = preSun) and 3817 3816 (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and 3818 (RW[Player].Tech[Preq] >= tsApplicable)) and ( iin AutoFeature)3817 (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature) 3819 3818 then 3820 Cap[ i] := 1;3819 Cap[I] := 1; 3821 3820 MaxWeight := 5; 3822 3821 if (WeightPreq7[Domain] <> preNA) and … … 3840 3839 {$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF} 3841 3840 if Subject >= nFeature then 3842 result := eInvalid3841 Result := eInvalid 3843 3842 else if DevModelTurn[Player] = GTurn then 3844 3843 begin … … 3846 3845 with RW[Player].DevModel do 3847 3846 if 1 shl Domain and Feature[Subject].Domains = 0 then 3848 result := eDomainMismatch3847 Result := eDomainMismatch 3849 3848 else if not((Feature[Subject].Preq = preNone) or 3850 3849 (Feature[Subject].Preq = preSun) and … … 3852 3851 (Feature[Subject].Preq >= 0) and 3853 3852 (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then 3854 result := eNoPreq3853 Result := eNoPreq 3855 3854 else 3856 3855 begin … … 3868 3867 MaxCap := 3; 3869 3868 if RW[Player].Tech[adSteel] >= tsApplicable then 3870 inc(MaxCap);3869 Inc(MaxCap); 3871 3870 end 3872 3871 else … … 3878 3877 if (NewCap < MinCap) or (NewCap > MaxCap) or 3879 3878 (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then 3880 result := eViolation3879 Result := eViolation 3881 3880 else if Command >= sExecute then 3882 3881 begin … … 3921 3920 end 3922 3921 else 3923 result := eNoModel;3922 Result := eNoModel; 3924 3923 end; 3925 3924 … … 3932 3931 {$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3933 3932 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3934 result := eInvalid3933 Result := eInvalid 3935 3934 else 3936 3935 begin 3937 result := eRemoved;3936 Result := eRemoved; 3938 3937 Loc0 := RW[Player].Un[Subject].Loc; 3939 3938 if RealMap[Loc0] and fCity <> 0 then { check utilize } … … 3947 3946 (Project and cpImp = 0) and 3948 3947 (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then 3949 result := eUtilized;3948 Result := eUtilized; 3950 3949 if Command >= sExecute then 3951 3950 begin 3952 if result = eUtilized then3951 if Result = eUtilized then 3953 3952 begin 3954 3953 with RW[Player].Un[Subject] do 3955 3954 begin 3956 Cost := integer(RW[Player].Model[mix].Cost) * Health *3955 Cost := Integer(RW[Player].Model[mix].Cost) * Health * 3957 3956 BuildCostMod[Difficulty[Player]] div 1200; 3958 3957 if RW[Player].Model[mix].Cap[mcLine] > 0 then … … 3960 3959 end; 3961 3960 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 3962 inc(RW[Player].Money, Cost)3961 Inc(RW[Player].Money, Cost) 3963 3962 else 3964 3963 begin 3965 inc(Prod, Cost * 2 div 3);3964 Inc(Prod, Cost * 2 div 3); 3966 3965 Project0 := Project0 and not cpCompleted; 3967 3966 if Project0 and not cpAuto <> Project and not cpAuto then … … 3983 3982 {$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3984 3983 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3985 result := eInvalid3984 Result := eInvalid 3986 3985 else 3987 3986 begin 3988 3987 Loc0 := RW[Player].Un[Subject].Loc; 3989 3988 if RealMap[Loc0] and fCity = 0 then 3990 result := eInvalid3989 Result := eInvalid 3991 3990 else 3992 3991 begin 3993 3992 SearchCity(Loc0, Player, cix1); 3994 3993 if RW[Player].City[cix1].Flags and chCaptured <> 0 then 3995 result := eViolation3994 Result := eViolation 3996 3995 else if Command >= sExecute then 3997 3996 RW[Player].Un[Subject].Home := cix1; … … 4010 4009 {$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4011 4010 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4012 result := eInvalid4011 Result := eInvalid 4013 4012 else 4014 result := LoadUnit(Player, Subject, Command < sExecute);4013 Result := LoadUnit(Player, Subject, Command < sExecute); 4015 4014 end; 4016 4015 … … 4019 4018 {$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4020 4019 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4021 result := eInvalid4020 Result := eInvalid 4022 4021 else 4023 result := UnloadUnit(Player, Subject, Command < sExecute);4022 Result := UnloadUnit(Player, Subject, Command < sExecute); 4024 4023 end; 4025 4024 4026 4025 sSelectTransport, sSelectTransport - sExecute: 4027 4026 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4028 result := eInvalid4027 Result := eInvalid 4029 4028 else 4030 4029 with RW[Player].Model[RW[Player].Un[Subject].mix] do 4031 4030 begin 4032 4031 if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then 4033 result := eInvalid4032 Result := eInvalid 4034 4033 else if Command >= sExecute then 4035 4034 uixSelectedTransport := Subject; … … 4042 4041 begin 4043 4042 p1 := Command shr 4 and $F; 4044 Loc1 := integer(Data);4043 Loc1 := Integer(Data); 4045 4044 if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or 4046 4045 (RealMap[Loc1] and fCity <> 0) and 4047 4046 (RealMap[Loc1] shr 27 <> Cardinal(p1)) or 4048 4047 (RW[p1].Model[Subject].Domain < dAir) and 4049 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[ integer(Data)] and4048 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and 4050 4049 fTerrain < fGrass)) then 4051 result := eViolation4050 Result := eViolation 4052 4051 else if Command >= sExecute then 4053 4052 begin 4054 4053 CreateUnit(p1, Subject); 4055 RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);4054 RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data); 4056 4055 PlaceUnit(p1, RW[p1].nUn - 1); 4057 UpdateUnitMap( integer(Data));4056 UpdateUnitMap(Integer(Data)); 4058 4057 end; 4059 4058 end 4060 4059 else 4061 result := eInvalid;4060 Result := eInvalid; 4062 4061 4063 4062 sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16, … … 4076 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} 4077 4076 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4078 result := eInvalid4077 Result := eInvalid 4079 4078 else 4080 result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);4079 Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute); 4081 4080 end; 4082 4081 … … 4089 4088 {$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4090 4089 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4091 result := eInvalid4090 Result := eInvalid 4092 4091 else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind 4093 4092 in [mkSettler, mkSlaves]) and 4094 4093 (RW[Player].Un[Subject].Flags and unConscripts = 0) then 4095 result := eViolation4094 Result := eViolation 4096 4095 else 4097 4096 begin 4098 4097 Loc0 := RW[Player].Un[Subject].Loc; 4099 4098 if RealMap[Loc0] and fCity = 0 then 4100 result := eInvalid4099 Result := eInvalid 4101 4100 else 4102 4101 begin … … 4104 4103 with RW[Player].City[cix1] do 4105 4104 if not CanCityGrow(Player, cix1) then 4106 result := eMaxSize4105 Result := eMaxSize 4107 4106 else if Command >= sExecute then 4108 4107 begin { add to city } … … 4124 4123 begin 4125 4124 Loc0 := RW[Player].Un[Subject].Loc; 4126 i:= Command shr 4 and $3F; // new job4127 {$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} 4128 4127 if (Subject >= RW[Player].nUn) or (Loc0 < 0) then 4129 result := eInvalid4130 else if i>= nJob then4131 result := eInvalid4128 Result := eInvalid 4129 else if I >= nJob then 4130 Result := eInvalid 4132 4131 else 4133 4132 begin 4134 result := StartJob(Player, Subject, i, Command < sExecute);4135 if result = eCity then4133 Result := StartJob(Player, Subject, I, Command < sExecute); 4134 if Result = eCity then 4136 4135 begin // new city 4137 4136 cix1 := RW[Player].nCity - 1; … … 4158 4157 sSetCityProject, sSetCityProject - sExecute: 4159 4158 begin 4160 NewProject := integer(Data) and not cpAuto;4159 NewProject := Integer(Data) and not cpAuto; 4161 4160 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF} 4162 4161 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4163 4162 then 4164 result := eInvalid4163 Result := eInvalid 4165 4164 else 4166 4165 with RW[Player].City[Subject] do 4167 4166 begin 4168 4167 if NewProject = Project then 4169 result := eNotChanged4168 Result := eNotChanged 4170 4169 else 4171 4170 begin … … 4175 4174 begin 4176 4175 if NewProject and cpIndex >= RW[Player].nModel then 4177 result := eInvalid4176 Result := eInvalid 4178 4177 else if (NewProject and cpConscripts <> 0) and 4179 4178 not((RW[Player].Tech[adConscription] >= tsApplicable) and … … 4181 4180 and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout)) 4182 4181 then 4183 result := eViolation4182 Result := eViolation 4184 4183 // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves) 4185 4184 // and (GWonder[woPyramids].EffectiveOwner<>Player) then … … 4187 4186 end 4188 4187 else if NewProject and cpIndex >= nImp then 4189 result := eInvalid4188 Result := eInvalid 4190 4189 else 4191 4190 begin 4192 4191 Preq := Imp[NewProject and cpIndex].Preq; 4193 for i:= 0 to nImpReplacement - 1 do4194 if (ImpReplacement[ i].OldImp = NewProject and cpIndex) and4195 (built[ImpReplacement[ i].NewImp] > 0) then4196 result := eObsolete;4197 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 4198 4197 else if Preq = preNA then 4199 result := eInvalid4198 Result := eInvalid 4200 4199 else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable) 4201 4200 then 4202 result := eNoPreq4201 Result := eNoPreq 4203 4202 else if built[NewProject and cpIndex] > 0 then 4204 result := eInvalid4203 Result := eInvalid 4205 4204 else if (NewProject and cpIndex < nWonder) and 4206 4205 (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then 4207 result := eViolation // wonder already exists4206 Result := eViolation // wonder already exists 4208 4207 else if (NewProject and cpIndex = imSpacePort) and 4209 4208 (RW[Player].NatBuilt[imSpacePort] > 0) then 4210 result := eViolation // space port already exists4209 Result := eViolation // space port already exists 4211 4210 else if (NewProject = cpImp + imBank) and (built[imMarket] = 0) 4212 4211 or (NewProject = cpImp + imUniversity) and … … 4214 4213 (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant) 4215 4214 and (built[imFactory] = 0) then 4216 result := eNoPreq;4215 Result := eNoPreq; 4217 4216 case NewProject - cpImp of 4218 4217 woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform: … … 4225 4224 if (Loc1 >= 0) and (Loc1 < MapSize) and 4226 4225 (RealMap[Loc1] and fTerrain = fShore) then 4227 inc(Preq);4226 Inc(Preq); 4228 4227 end; 4229 4228 if Preq = 0 then 4230 result := eNoPreq;4229 Result := eNoPreq; 4231 4230 end; 4232 4231 woHoover, imHydro: … … 4240 4239 ((RealMap[Loc1] and fTerrain = fMountains) or 4241 4240 (RealMap[Loc1] and fRiver <> 0)) then 4242 inc(Preq);4241 Inc(Preq); 4243 4242 end; 4244 4243 if Preq = 0 then 4245 result := eNoPreq;4244 Result := eNoPreq; 4246 4245 end; 4247 4246 woMIR, imShipComp, imShipPow, imShipHab: 4248 4247 if RW[Player].NatBuilt[imSpacePort] = 0 then 4249 result := eNoPreq;4248 Result := eNoPreq; 4250 4249 end; 4251 4250 if (GTestFlags and tfNoRareNeed = 0) and 4252 4251 (Imp[NewProject and cpIndex].Kind = ikShipPart) then 4253 4252 if RW[Player].Tech[adMassProduction] < tsApplicable then 4254 result := eNoPreq4253 Result := eNoPreq 4255 4254 else 4256 4255 begin // check for rare resources 4257 4256 if NewProject and cpIndex = imShipComp then 4258 j:= 14257 J := 1 4259 4258 else if NewProject and cpIndex = imShipPow then 4260 j:= 24259 J := 2 4261 4260 else { if NewProject and cpIndex=imShipHab then } 4262 j:= 3;4261 J := 3; 4263 4262 // j = rare resource required 4264 4263 Preq := 0; … … 4268 4267 Loc1 := Radius[V21]; 4269 4268 if (Loc1 >= 0) and (Loc1 < MapSize) and 4270 (RealMap[Loc1] shr 25 and 3 = Cardinal( j)) then4271 inc(Preq);4269 (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then 4270 Inc(Preq); 4272 4271 end; 4273 4272 if Preq = 0 then 4274 result := eNoPreq;4273 Result := eNoPreq; 4275 4274 end; 4276 4275 end; 4277 4276 4278 if (Command >= sExecute) and ( result >= rExecuted) then4277 if (Command >= sExecute) and (Result >= rExecuted) then 4279 4278 begin 4280 4279 if pt0 <> ptSelect then … … 4285 4284 and (pt0 <> ptCaravan) then 4286 4285 begin 4287 inc(RW[Player].Money, Prod0);4286 Inc(RW[Player].Money, Prod0); 4288 4287 Prod := 0; 4289 4288 Prod0 := 0; … … 4292 4291 else 4293 4292 Prod := Prod0 * 2 div 3; 4294 Project := NewProject 4293 Project := NewProject; 4295 4294 end; 4296 4295 end; … … 4303 4302 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4304 4303 then 4305 result := eInvalid4304 Result := eInvalid 4306 4305 else 4307 4306 with RW[Player].City[Subject] do 4308 4307 if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0) 4309 4308 then 4310 result := eOutOfControl4309 Result := eOutOfControl 4311 4310 else if (Project and cpImp <> 0) and 4312 4311 ((Project and cpIndex = imTrGoods) or 4313 4312 (Imp[Project and cpIndex].Kind = ikShipPart)) then 4314 result := eInvalid // don't buy colony ship4313 Result := eInvalid // don't buy colony ship 4315 4314 else 4316 4315 begin … … 4331 4330 Cost := Cost * 4; 4332 4331 if Cost <= 0 then 4333 result := eNotChanged4332 Result := eNotChanged 4334 4333 else if Cost > RW[Player].Money then 4335 result := eViolation4334 Result := eViolation 4336 4335 else if Command >= sExecute then 4337 4336 IntServer(sIntBuyMaterial, Player, Subject, Cost); … … 4346 4345 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4347 4346 then 4348 result := eInvalid4347 Result := eInvalid 4349 4348 else if Command >= sExecute then 4350 4349 with RW[Player].City[Subject] do 4351 4350 begin 4352 inc(RW[Player].Money, Prod0);4351 Inc(RW[Player].Money, Prod0); 4353 4352 Prod := 0; 4354 4353 Prod0 := 0; … … 4358 4357 sSellCityImprovement, sSellCityImprovement - sExecute: 4359 4358 begin 4360 {$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} 4361 4360 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4362 4361 then 4363 result := eInvalid4362 Result := eInvalid 4364 4363 else 4365 4364 with RW[Player].City[Subject] do 4366 if built[ integer(Data)] = 0 then4367 result := eInvalid4365 if built[Integer(Data)] = 0 then 4366 Result := eInvalid 4368 4367 else if (RW[Player].Government = gAnarchy) or 4369 4368 (Flags and chCaptured <> 0) then 4370 result := eOutOfControl4369 Result := eOutOfControl 4371 4370 else if Flags and chImprovementSold <> 0 then 4372 result := eOnlyOnce4371 Result := eOnlyOnce 4373 4372 else if Command >= sExecute then 4374 4373 begin 4375 inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod4374 Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod 4376 4375 [Difficulty[Player]] div 12); 4377 built[ integer(Data)] := 0;4378 if Imp[ integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then4376 built[Integer(Data)] := 0; 4377 if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then 4379 4378 begin 4380 RW[Player].NatBuilt[ integer(Data)] := 0;4381 case integer(Data) of4379 RW[Player].NatBuilt[Integer(Data)] := 0; 4380 case Integer(Data) of 4382 4381 imGrWall: 4383 4382 GrWallContinent[Player] := -1; … … 4386 4385 end; 4387 4386 end; 4388 inc(Flags, chImprovementSold);4387 Inc(Flags, chImprovementSold); 4389 4388 end; 4390 4389 end; … … 4392 4391 sRebuildCityImprovement, sRebuildCityImprovement - sExecute: 4393 4392 begin 4394 OldImp := integer(Data);4393 OldImp := Integer(Data); 4395 4394 {$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF} 4396 4395 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4397 4396 then 4398 result := eInvalid4397 Result := eInvalid 4399 4398 else 4400 4399 begin 4401 4400 if (OldImp < 0) or (OldImp >= nImp) or 4402 4401 not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then 4403 result := eInvalid4402 Result := eInvalid 4404 4403 else 4405 4404 with RW[Player].City[Subject] do … … 4407 4406 not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal, 4408 4407 ikNatGlobal]) then 4409 result := eInvalid4408 Result := eInvalid 4410 4409 else if (RW[Player].Government = gAnarchy) or 4411 4410 (Flags and chCaptured <> 0) then 4412 result := eOutOfControl4411 Result := eOutOfControl 4413 4412 else if Flags and chImprovementSold <> 0 then 4414 result := eOnlyOnce4413 Result := eOnlyOnce 4415 4414 else if Command >= sExecute then 4416 4415 begin 4417 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]4416 Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]] 4418 4417 div 12 * 2 div 3); 4419 4418 Project0 := Project0 and not cpCompleted; … … 4432 4431 end; 4433 4432 end; 4434 inc(Flags, chImprovementSold);4433 Inc(Flags, chImprovementSold); 4435 4434 end; 4436 4435 end; … … 4439 4438 sSetCityTiles, sSetCityTiles - sExecute: 4440 4439 begin 4441 {$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} 4442 4441 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4443 4442 then 4444 result := eInvalid4443 Result := eInvalid 4445 4444 else 4446 result := SetCityTiles(Player, Subject, integer(Data),4445 Result := SetCityTiles(Player, Subject, Integer(Data), 4447 4446 Command < sExecute); 4448 4447 end; … … 4461 4460 end 4462 4461 else 4463 result := eUnknown;4462 Result := eUnknown; 4464 4463 end; { case command } 4465 4464 4466 4465 // do not log invalid and non-relevant commands 4467 if result = eZOC_EnemySpotted then4466 if Result = eZOC_EnemySpotted then 4468 4467 begin 4469 assert(Mode = moPlaying);4468 Assert(Mode = moPlaying); 4470 4469 CL.State := FormerCLState; 4471 4470 IntServer(sIntDiscoverZOC, Player, 0, ZOCTile); 4472 4471 end 4473 else if result and rEffective = 0 then4472 else if Result and rEffective = 0 then 4474 4473 if Mode < moPlaying then 4475 4474 begin 4476 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [ result]) + CmdInfo;4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo; 4477 4476 {$ENDIF} 4478 LoadOK := false;4477 LoadOK := False; 4479 4478 end 4480 4479 else … … 4482 4481 if logged then 4483 4482 CL.State := FormerCLState; 4484 if ( result < rExecuted) and (Command >= sExecute) then4483 if (Result < rExecuted) and (Command >= sExecute) then 4485 4484 PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)', 4486 4485 [Player, Command, Subject])); … … 4488 4487 4489 4488 if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient) 4490 and ( result >= rExecuted) then4489 and (Result >= rExecuted) then 4491 4490 LastEndClientCommand := Command; 4492 {$IFOPT O-} dec(nHandoverStack, 2); {$ENDIF}4493 end; { <<<server }4491 {$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF} 4492 end; 4494 4493 4495 4494 -
branches/highdpi/Global.pas
r412 r465 24 24 ((CevoVersionBugFix and $ff) shl 0); 25 25 26 27 26 implementation 28 27 29 28 end. 30 29 30 -
branches/highdpi/Graphics/System2.grs
r349 r465 9 9 <Height>26</Height> 10 10 </Item> 11 <Item> 12 <Name>BrainNoTerm</Name> 13 <Left>1</Left> 14 <Top>111</Top> 15 <Width>64</Width> 16 <Height>64</Height> 17 </Item> 18 <Item> 19 <Name>BrainSuperVirtual</Name> 20 <Left>66</Left> 21 <Top>111</Top> 22 <Width>64</Width> 23 <Height>64</Height> 24 </Item> 25 <Item> 26 <Name>BrainTerm</Name> 27 <Left>131</Left> 28 <Top>111</Top> 29 <Width>64</Width> 30 <Height>64</Height> 31 </Item> 32 <Item> 33 <Name>BrainRandom</Name> 34 <Left>131</Left> 35 <Top>46</Top> 36 <Width>64</Width> 37 <Height>64</Height> 38 </Item> 11 39 </Items> 12 40 </GraphicSet> -
branches/highdpi/IPQ.pas
r303 r465 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 11 TIntegerArray = array [0 .. $40000000 div sizeof(integer)] of integer; 10 TIntegerArray = array [0 .. $40000000 div SizeOf(Integer)] of Integer; 12 11 PIntegerArray = ^TIntegerArray; 13 12 14 13 TheapItem = record 15 Item: integer;16 Value: integer;14 Item: Integer; 15 Value: Integer; 17 16 end; 18 17 19 TItemArray = array [0 .. $40000000 div sizeof(TheapItem)] of TheapItem;18 TItemArray = array [0 .. $40000000 div SizeOf(TheapItem)] of TheapItem; 20 19 PItemArray = ^TItemArray; 21 20 22 21 TIPQ = class 23 constructor Create( max: integer);22 constructor Create(Max: Integer); 24 23 destructor Destroy; override; 25 24 procedure Empty; 26 function Put(Item, Value: integer): boolean;27 function TestPut(Item, Value: integer): boolean;28 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; 29 28 private 30 29 // n - is the size of the heap. 31 30 // fmax - is the max size of the heap. 32 n, fmax: integer;31 N, fmax: Integer; 33 32 34 33 // bh - stores (Value, Item) pairs of the heap. … … 40 39 implementation 41 40 42 constructor TIPQ.Create( max: integer);41 constructor TIPQ.Create(Max: Integer); 43 42 begin 44 43 inherited Create; 45 fmax := max;46 GetMem(bh, fmax * sizeof(TheapItem));47 GetMem(Ix, fmax * sizeof(integer));48 n:= -1;44 fmax := Max; 45 GetMem(bh, fmax * SizeOf(TheapItem)); 46 GetMem(Ix, fmax * SizeOf(Integer)); 47 N := -1; 49 48 Empty; 50 49 end; … … 59 58 procedure TIPQ.Empty; 60 59 begin 61 if n<> 0 then60 if N <> 0 then 62 61 begin 63 FillChar(Ix^, fmax * sizeof(integer), 255);64 n:= 0;62 FillChar(Ix^, fmax * SizeOf(Integer), 255); 63 N := 0; 65 64 end; 66 65 end; 67 66 68 67 // Parent(i) = (i-1)/2. 69 function TIPQ.Put(Item, Value: integer): boolean; // O(lg(n))68 function TIPQ.Put(Item, Value: Integer): Boolean; // O(lg(n)) 70 69 var 71 i, j: integer;70 I, J: Integer; 72 71 lbh: PItemArray; 73 72 lIx: PIntegerArray; … … 75 74 lIx := Ix; 76 75 lbh := bh; 77 i:= lIx[Item];78 if i>= 0 then76 I := lIx[Item]; 77 if I >= 0 then 79 78 begin 80 if lbh[ i].Value <= Value then79 if lbh[I].Value <= Value then 81 80 begin 82 result := False;83 exit;81 Result := False; 82 Exit; 84 83 end; 85 84 end 86 85 else 87 86 begin 88 i := n;89 Inc( n);87 I := N; 88 Inc(N); 90 89 end; 91 90 92 while i> 0 do91 while I > 0 do 93 92 begin 94 j := (i- 1) shr 1; // Parent(i) = (i-1)/295 if Value >= lbh[ j].Value then96 break;97 lbh[ i] := lbh[j];98 lIx[lbh[ i].Item] := i;99 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; 100 99 end; 101 100 // Insert the new Item at the insertion point found. 102 lbh[ i].Value := Value;103 lbh[ i].Item := Item;104 lIx[lbh[ i].Item] := i;105 result := True;101 lbh[I].Value := Value; 102 lbh[I].Item := Item; 103 lIx[lbh[I].Item] := I; 104 Result := True; 106 105 end; 107 106 108 function TIPQ.TestPut(Item, Value: integer): boolean;107 function TIPQ.TestPut(Item, Value: Integer): Boolean; 109 108 var 110 i: integer;109 I: Integer; 111 110 begin 112 i:= Ix[Item];113 result := (i < 0) or (bh[i].Value > Value);111 I := Ix[Item]; 112 Result := (I < 0) or (bh[I].Value > Value); 114 113 end; 115 114 116 115 // Left(i) = 2*i+1. 117 116 // Right(i) = 2*i+2 => Left(i)+1 118 function TIPQ.Get(var Item, Value: integer): boolean; // O(lg(n))117 function TIPQ.Get(var Item, Value: Integer): Boolean; // O(lg(n)) 119 118 var 120 i, j: integer;121 last: TheapItem;119 I, J: Integer; 120 Last: TheapItem; 122 121 lbh: PItemArray; 123 122 begin 124 if n= 0 then123 if N = 0 then 125 124 begin 126 result := False;127 exit;125 Result := False; 126 Exit; 128 127 end; 129 128 … … 134 133 Ix[Item] := -1; 135 134 136 dec(n);137 if n> 0 then135 Dec(N); 136 if N > 0 then 138 137 begin 139 last := lbh[n];140 i:= 0;141 j:= 1;142 while j < ndo138 Last := lbh[N]; 139 I := 0; 140 J := 1; 141 while J < N do 143 142 begin 144 143 // Right(i) = Left(i)+1 145 if ( j < n - 1) and (lbh[j].Value > lbh[j+ 1].Value) then146 Inc( j);147 if last.Value <= lbh[j].Value then148 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; 149 148 150 lbh[ i] := lbh[j];151 Ix[lbh[ i].Item] := i;152 i := j;153 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 154 153 end; 155 154 156 155 // Insert the root in the correct place in the heap. 157 lbh[ i] := last;158 Ix[ last.Item] := i;156 lbh[I] := Last; 157 Ix[Last.Item] := I; 159 158 end; 160 result := True159 Result := True; 161 160 end; 162 161 -
branches/highdpi/Inp.pas
r412 r465 21 21 procedure CenterToRect(Rect: TRect); 22 22 private 23 Center: boolean;23 Center: Boolean; 24 24 end; 25 25 26 26 var 27 27 InputDlg: TInputDlg; 28 28 29 29 30 implementation … … 53 54 9, Caption); 54 55 { Corner(canvas,1,1,0,MainTexture); 55 Corner( canvas,ClientWidth-9,1,1,MainTexture);56 Corner( canvas,1,ClientHeight-9,2,MainTexture);57 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); } 58 59 end; 59 60 -
branches/highdpi/Install/rpm/c-evo.spec
r405 r465 11 11 Requires: sox 12 12 13 #BuildRequires: lazarus 13 BuildRequires: lazarus >= 2.0.12 14 14 15 15 %description 16 Turn-based empire building game inspired by Civilization.16 A turn-based empire building game inspired by Civilization. 17 17 18 18 %global debug_package %{nil} … … 72 72 /usr/bin/c-evo 73 73 /usr/share/applications/c-evo.desktop 74 /usr/share/c-evo/ *74 /usr/share/c-evo/ 75 75 /usr/share/pixmaps/c-evo.png 76 76 -
branches/highdpi/Install/snap/local/build.sh
r405 r465 4 4 5 5 pushd ../../.. 6 snapcraft --debug --use-lxd 6 snapcraft --debug --use-lxd $@ 7 7 popd 8 8 -
branches/highdpi/Install/snap/snapcraft.yaml
r405 r465 5 5 description: | 6 6 This is a fork and Lazarus/FPC port of the original C-evo 1.2.0 game. 7 Now it is finally possible to play C-evo natively on Linux. 7 Now it is finally possible to play C-evo natively on Linux. 8 8 * Zoomable map by mouse wheel with three tile sizes 9 9 * Many sample maps included 10 * All available localizations include 10 * Multiple localizations included 11 * Support for user defined key mapping 11 12 * Many other small improvements 12 confinement: strict13 base: core2 013 confinement: devmode 14 base: core22 14 15 grade: stable 15 16 icon: Graphics/c-evo_64x64.png 16 17 license: NLPL 17 18 18 environment: 19 LD_LIBRARY_PATH: $SNAP /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio19 environment: 20 LD_LIBRARY_PATH: $SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio 20 21 PULSE_SERVER: unix:/run/user/1000/pulse/native 21 22 22 23 layout: 23 24 /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox: 24 bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox 25 bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox 25 26 26 27 parts: … … 29 30 source: . 30 31 source-type: local 31 build-packages: 32 - fpc 33 - lazarus 34 - lcl 35 - lcl-utils 36 stage-packages: 32 after: [lazarus] 33 stage-packages: 37 34 - sox 38 35 - libsox-fmt-mp3 … … 72 69 override-build: | 73 70 snapcraftctl build 74 (cd AI/StdAI &&lazbuild --build-mode= ReleaseStdAI.lpi)71 (cd AI/StdAI &&lazbuild --build-mode=Debug StdAI.lpi) 75 72 mv AI/StdAI/libstdai.so AI/StdAI/libstdai-amd64.so 76 lazbuild --build-mode=Release Integrated.lpi 77 ROOT=/root/parts/c-evo/install 78 install -d -m 755 $ROOT/usr/share/c-evo 79 install -s -m 755 c-evo $ROOT/usr/share/c-evo 80 install -m 644 Language.txt $ROOT/usr/share/c-evo 81 install -m 644 Language2.txt $ROOT/usr/share/c-evo 82 install -m 644 Fonts.txt $ROOT/usr/share/c-evo 83 install -d -m 755 $ROOT/usr/share/applications 84 install -m 755 Install/deb/c-evo.desktop $ROOT/usr/share/applications 85 install -d -m 755 $ROOT/usr/share/mime/packages 86 install -m 755 Install/deb/c-evo.xml $ROOT/usr/share/mime/packages 87 install -d -m 755 $ROOT/usr/share/pixmaps 88 install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/c-evo.png 89 install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/application-cevo.png 90 install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/application-cevomap.png 91 install -d -m 755 $ROOT/usr/share/c-evo/AI/StdAI 92 install -m 644 AI/StdAI/libstdai-amd64.so $ROOT/usr/share/c-evo/AI/StdAI 93 install -m 644 AI/StdAI/StdAI.ai.txt $ROOT/usr/share/c-evo/AI/StdAI 94 install -m 644 AI/StdAI/StdAI.png $ROOT/usr/share/c-evo/AI/StdAI 95 cp -r Graphics $ROOT/usr/share/c-evo 96 cp -r Help $ROOT/usr/share/c-evo 97 cp -r Sounds $ROOT/usr/share/c-evo 98 cp -r Tribes $ROOT/usr/share/c-evo 99 cp -r Localization $ROOT/usr/share/c-evo 100 cp -r Maps $ROOT/usr/share/c-evo 101 cp -r Saved $ROOT/usr/share/c-evo 102 cp -r "AI Template" $ROOT/usr/share/c-evo 73 lazbuild --build-mode=Debug Integrated.lpi 74 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 75 install -s -m 755 c-evo $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 76 install -m 644 Language.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 77 install -m 644 Language2.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 78 install -m 644 Fonts.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 79 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications 80 install -m 755 Install/deb/c-evo.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications 81 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/mime/packages 82 install -m 644 Install/deb/c-evo.xml $SNAPCRAFT_PART_INSTALL/usr/share/mime/packages 83 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps 84 install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/c-evo.png 85 install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/application-cevo.png 86 install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/application-cevomap.png 87 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI 88 install -m 644 AI/StdAI/libstdai-amd64.so $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI 89 install -m 644 AI/StdAI/StdAI.ai.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI 90 install -m 644 AI/StdAI/StdAI.png $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI 91 cp -r Graphics $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 92 cp -r Help $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 93 cp -r Sounds $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 94 cp -r Tribes $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 95 cp -r Localization $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 96 cp -r Maps $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 97 cp -r Saved $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 98 cp -r "AI Template" $SNAPCRAFT_PART_INSTALL/usr/share/c-evo 103 99 stage: 104 100 - etc … … 107 103 - usr/share/applications/c-evo.desktop 108 104 - usr/share/mime/packages/c-evo.xml 109 105 lazarus: 106 plugin: nil 107 source: . 108 source-type: local 109 build-packages: 110 - wget 111 - libgtk2.0-dev 112 override-build: | 113 wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/lazarus-project_2.2.2-0_amd64.deb 114 wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/fpc-laz_3.2.2-210709_amd64.deb 115 wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/fpc-src_3.2.2-210709_amd64.deb 116 apt install ./lazarus-project_2.2.2-0_amd64.deb ./fpc-laz_3.2.2-210709_amd64.deb ./fpc-src_3.2.2-210709_amd64.deb 117 stage: [-*] 118 prime: [-*] 119 110 120 apps: 111 121 c-evo: 112 122 command: usr/share/c-evo/c-evo 113 desktop: usr/share/applications/c-evo.desktop 123 desktop: usr/share/applications/c-evo.desktop 114 124 plugs: 115 125 - home -
branches/highdpi/Integrated.lpi
r405 r465 2 2 <CONFIG> 3 3 <ProjectOptions> 4 <Version Value="1 1"/>4 <Version Value="12"/> 5 5 <PathDelim Value="\"/> 6 6 <General> … … 9 9 <MainUnitHasCreateFormStatements Value="False"/> 10 10 <MainUnitHasTitleStatement Value="False"/> 11 <CompatibilityMode Value="True"/> 11 12 </Flags> 12 13 <SessionStorage Value="InProjectDir"/> 13 <MainUnit Value="0"/>14 14 <Title Value="Integrated"/> 15 15 <UseAppBundle Value="False"/> … … 59 59 <Debugging> 60 60 <GenerateDebugInfo Value="False"/> 61 <DebugInfoType Value="dsDwarf2Set"/> 61 62 </Debugging> 62 63 <LinkSmart Value="True"/> … … 106 107 </Item4> 107 108 </RequiredPackages> 108 <Units Count="4 8">109 <Units Count="47"> 109 110 <Unit0> 110 111 <Filename Value="Integrated.lpr"/> … … 344 345 </Unit40> 345 346 <Unit41> 346 <Filename Value="LocalPlayer\ UKeyBindings.pas"/>347 <Filename Value="LocalPlayer\KeyBindings.pas"/> 347 348 <IsPartOfProject Value="True"/> 348 349 </Unit41> 349 350 <Unit42> 350 <Filename Value=" UMiniMap.pas"/>351 <Filename Value="MiniMap.pas"/> 351 352 <IsPartOfProject Value="True"/> 352 353 </Unit42> 353 354 <Unit43> 354 <Filename Value=" UBrain.pas"/>355 <Filename Value="Brain.pas"/> 355 356 <IsPartOfProject Value="True"/> 356 357 </Unit43> 357 358 <Unit44> 358 <Filename Value="Network\ UNetworkServer.pas"/>359 <Filename Value="Network\NetworkServer.pas"/> 359 360 <IsPartOfProject Value="True"/> 360 361 </Unit44> 361 362 <Unit45> 362 <Filename Value="Network\ UNetworkClient.pas"/>363 <Filename Value="Network\NetworkClient.pas"/> 363 364 <IsPartOfProject Value="True"/> 364 365 </Unit45> 365 366 <Unit46> 366 <Filename Value="Network\ UNetworkCommon.pas"/>367 <Filename Value="Network\NetworkCommon.pas"/> 367 368 <IsPartOfProject Value="True"/> 368 369 </Unit46> 369 <Unit47>370 <Filename Value="ULanguages.pas"/>371 <IsPartOfProject Value="True"/>372 </Unit47>373 370 </Units> 374 371 </ProjectOptions> … … 404 401 <Linking> 405 402 <Debugging> 403 <DebugInfoType Value="dsDwarf2Set"/> 404 <UseHeaptrc Value="True"/> 406 405 <UseExternalDbgSyms Value="True"/> 407 406 </Debugging> -
branches/highdpi/Integrated.lpr
r405 r465 6 6 cthreads, clocale, 7 7 {$ENDIF} 8 UDpiControls,Forms, Interfaces, SysUtils, Protocol, GameServer, Direct, Start, Messg, Inp,8 Forms, Interfaces, SysUtils, Protocol, GameServer, Direct, Start, Messg, Inp, 9 9 Back, Log, LocalPlayer, ClientTools, Tribes, IsoEngine, Term, CityScreen, Nego, 10 NoTerm, ScreenTools, Directories ;10 NoTerm, ScreenTools, Directories, UDpiControls; 11 11 12 12 {$if declared(UseHeapTrace)} … … 26 26 DotNetClient := nil; 27 27 DpiApplication.Initialize; 28 DpiApplication.Title := 'c-evo'; 28 DpiApplication.Title := 'C-evo'; 29 DpiApplication.TaskBarBehavior := tbMultiButton; 29 30 Directories.UnitInit; 30 31 ScreenTools.UnitInit; -
branches/highdpi/Language.txt
r405 r465 140 140 #TITLE_SPYMISSION Covert Operation 141 141 #TITLE_SUICIDE Suicide Mission 142 #TITLE_MESSAGE Message 142 143 #FRMILREP Military Report 143 144 -
branches/highdpi/LocalPlayer/Battle.pas
r361 r465 32 32 uix, ToLoc: Integer; 33 33 Forecast: TBattleForecastEx; 34 IsSuicideQuery: boolean; 35 end; 36 37 var 38 BattleDlg: TBattleDlg; 34 IsSuicideQuery: Boolean; 35 end; 36 39 37 40 38 implementation … … 62 60 TextSize: TSize; 63 61 LabelText: string; 64 FirstStrike: boolean;62 FirstStrike: Boolean; 65 63 begin 66 64 MaxBar := 65; … … 112 110 VLightGradient(ca, xm - 8, ym + 8 + LABaseDamage, LADamage - LABaseDamage, 113 111 FanaticColor); 114 DpiBit Canvas(ca, xm - 12, ym - 12, 24, 24,112 DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24, 115 113 HGrSystem.Mask.Canvas, 26, 146, SRCAND); 116 DpiBit Canvas(ca, xm - 12, ym - 12, 24, 24,114 DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24, 117 115 HGrSystem.Data.Canvas, 26, 146, SRCPAINT); 118 116 … … 137 135 if Forecast.EndHealthDef <= 0 then 138 136 begin 139 DpiBit Canvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,137 DpiBitBltCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17, 140 138 HGrSystem.Mask.Canvas, 51, 153, SRCAND); 141 DpiBit Canvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,139 DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17, 142 140 HGrSystem.Mask.Canvas, 51, 153, SRCAND); 143 DpiBit Canvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,141 DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17, 144 142 HGrSystem.Data.Canvas, 51, 153, SRCPAINT); 145 143 end; … … 149 147 begin 150 148 if Forecast.EndHealthDef > 0 then 151 RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText) 149 RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText); 152 150 end 153 151 else … … 157 155 if Forecast.EndHealthAtt <= 0 then 158 156 begin 159 DpiBit Canvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,157 DpiBitBltCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17, 160 158 HGrSystem.Mask.Canvas, 51, 153, SRCAND); 161 DpiBit Canvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,159 DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17, 162 160 HGrSystem.Mask.Canvas, 51, 153, SRCAND); 163 DpiBit Canvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,161 DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17, 164 162 HGrSystem.Data.Canvas, 51, 153, SRCPAINT); 165 163 end; … … 171 169 if Forecast.EndHealthAtt > 0 then 172 170 RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage, 173 LabelText) 171 LabelText); 174 172 end 175 173 else … … 178 176 179 177 IsoMap.SetOutput(Buffer); 180 DpiBit Canvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,178 DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4, 181 179 ym - 8 - 12 - 48); 182 180 { if TerrType<fForest then … … 190 188 end; } 191 189 IsoMap.PaintUnit(1, 0, UnitInfo, 0); 192 DpiBit Canvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,190 DpiBitBltCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas, 193 191 0, 0); 194 192 195 DpiBit Canvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,193 DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66, 196 194 ym + 8 + 12); 197 MakeUnitInfo( me, MyUn[uix], UnitInfo);195 MakeUnitInfo(Me, MyUn[uix], UnitInfo); 198 196 UnitInfo.Flags := UnitInfo.Flags and not unFortified; 199 197 IsoMap.PaintUnit(1, 0, UnitInfo, 0); 200 DpiBit Canvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);201 end; { PaintBattleOutcome }198 DpiBitBltCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0); 199 end; 202 200 203 201 procedure TBattleDlg.FormCreate(Sender: TObject); … … 215 213 ClientWidth := 300; 216 214 ClientHeight := 288; 217 OKBtn.Visible := true;218 CancelBtn.Visible := true;215 OKBtn.Visible := True; 216 CancelBtn.Visible := True; 219 217 Left := (DpiScreen.Width - ClientWidth) div 2; // center on screen 220 218 Top := (DpiScreen.Height - ClientHeight) div 2; … … 224 222 ClientWidth := 178; 225 223 ClientHeight := 178; 226 OKBtn.Visible := false;227 CancelBtn.Visible := false;224 OKBtn.Visible := False; 225 CancelBtn.Visible := False; 228 226 end; 229 227 end; … … 231 229 procedure TBattleDlg.FormPaint(Sender: TObject); 232 230 var 233 ym, cix, p: Integer;234 s, s1: string;231 ym, cix, P: Integer; 232 S, s1: string; 235 233 begin 236 234 with Canvas do … … 240 238 Brush.Style := bsClear; 241 239 PaintBackground(self, 3 + Border, 3 + Border, 242 ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border)) 240 ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border)); 243 241 end; 244 242 Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border), … … 252 250 begin 253 251 Canvas.Font.Assign(UniFont[ftCaption]); 254 s:= Phrases.Lookup('TITLE_SUICIDE');255 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,256 7 + Border, s);252 S := Phrases.Lookup('TITLE_SUICIDE'); 253 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 254 7 + Border, S); 257 255 Canvas.Font.Assign(UniFont[ftNormal]); 258 s:= Phrases.Lookup('SUICIDE');259 p := pos('\', s);260 if p= 0 then261 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))262 div 2, 205, s)256 S := Phrases.Lookup('SUICIDE'); 257 P := Pos('\', S); 258 if P = 0 then 259 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) 260 div 2, 205, S) 263 261 else 264 262 begin 265 s1 := copy(s, 1, p- 1);263 s1 := Copy(S, 1, P - 1); 266 264 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2, 267 265 205 - MessageLineSpacing div 2, s1); 268 s1 := copy(s, p+ 1, 255);266 s1 := Copy(S, P + 1, 255); 269 267 RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2, 270 268 205 + (MessageLineSpacing - MessageLineSpacing div 2), s1); 271 269 end; 272 ym := 110 270 ym := 110; 273 271 end 274 272 else … … 297 295 begin 298 296 if not IsSuicideQuery then 299 Close 297 Close; 300 298 end; 301 299 … … 309 307 if Key <> VK_ESCAPE then 310 308 MainScreen.FormKeyDown(Sender, Key, Shift); 311 end 309 end; 312 310 end; 313 311 -
branches/highdpi/LocalPlayer/CityScreen.pas
r405 r465 5 5 6 6 uses 7 UDpiControls, {$IFDEF LINUX}LMessages,{$ENDIF}8 Protocol, ClientTools, Term, ScreenTools, IsoEngine, BaseWin,9 LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,10 Button A, ButtonC, Area, GraphType, UTexture;7 UDpiControls, {$IFDEF UNIX}LMessages,{$ENDIF} 8 Protocol, ClientTools, ScreenTools, IsoEngine, BaseWin, LCLIntf, LCLType, 9 Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA, 10 ButtonC, Area, GraphType, Texture; 11 11 12 12 const … … 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); … … 49 49 procedure PrevCityBtnClick(Sender: TObject); 50 50 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 51 // procedure AdviceBtnClick(Sender: TObject);52 51 procedure PageUpBtnClick(Sender: TObject); 53 52 procedure PageDownBtnClick(Sender: TObject); 54 53 private 55 c: TCity;54 C: TCity; 56 55 Report: TCityReportNew; 57 56 cOwner: Integer; … … 70 69 Optimize_cixTileChange: Integer; 71 70 Optimize_TilesBeforeChange: Integer; 72 Happened: cardinal;73 imix: array [0 .. 15] of integer;71 Happened: Cardinal; 72 imix: array [0 .. 15] of Integer; 74 73 CityAreaInfo: TCityAreaInfo; 75 74 AreaMap: TIsoMap; … … 89 88 procedure InitZoomCityMap; 90 89 procedure ChooseProject; 91 procedure ChangeCity( d: integer);92 procedure ChangeResourceWeights(iResourceWeights: integer);90 procedure ChangeCity(D: Integer); 91 procedure ChangeResourceWeights(iResourceWeights: Integer); 93 92 procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND; 94 93 public 95 RestoreUnFocus: integer;94 RestoreUnFocus: Integer; 96 95 CloseAction: TCityCloseAction; 97 96 procedure OffscreenPaint; override; 98 procedure ShowNewContent(NewMode , Loc: integer; ShowEvent: cardinal);97 procedure ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal); 99 98 procedure Reset; 100 99 procedure CheckAge; 101 100 end; 102 101 103 var104 CityDlg: TCityDlg;105 106 102 107 103 implementation 108 104 109 105 uses 110 Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound ;106 Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound, Term; 111 107 112 108 {$R *.lfm} … … 148 144 wZoomEnvironment = 68; 149 145 150 ImpPosition: array [28 .. nImp - 1] of integer = (-1, // imTrGoods 146 ImpPosition: array [28 .. nImp - 1] of Integer = ( 147 -1, // imTrGoods 151 148 21, // imBarracks 152 149 6, // imGranary … … 192 189 193 190 var 194 ImpSorted: array [0 .. nImp - 1] of integer;191 ImpSorted: array [0 .. nImp - 1] of Integer; 195 192 196 193 procedure TCityDlg.FormCreate(Sender: TObject); … … 201 198 NoMap := TIsoMap.Create; 202 199 AreaMap := TIsoMap.Create; 203 AreaMap.SetOutput( offscreen);200 AreaMap.SetOutput(Offscreen); 204 201 AreaMap.SetPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192, 205 202 ymArea + 96); 206 SmallMapMode := smImprovements; 207 ZoomArea := 1; 208 ProdHint := false; 203 Reset; 204 ProdHint := False; 209 205 RestoreUnFocus := -1; 210 206 OpenSoundEvent := -1; … … 279 275 280 276 UnshareBitmap(Back); 281 DpiBit Canvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,277 DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight, 282 278 MainTexture.Image.Canvas, 0, 0); 283 279 ImageOp_B(Back, Template, 0, 0, 0, 0, ClientWidth, ClientHeight); … … 292 288 procedure TCityDlg.InitSmallCityMap; 293 289 var 294 i, iix, cli1, Color0, Color1, Color2: integer;290 I, iix, cli1, Color0, Color1, Color2: Integer; 295 291 begin 296 292 if cix >= 0 then 297 c:= MyCity[cix];293 C := MyCity[cix]; 298 294 case MyMap[cLoc] and fTerrain of 299 295 fPrairie: cli1 := cliPrairie; … … 307 303 Color2 := Colors.Canvas.Pixels[clkAge0 + Age, cliHouse]; 308 304 SmallCityMap.Canvas.FillRect(0, 0, SmallCityMap.Width, SmallCityMap.Height); 309 DpiBit Canvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap,305 DpiBitBltCanvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap, 310 306 SmallCityMapTemplate.Canvas, 83 * SizeClass, 0); 311 307 if IsPort then 312 308 begin 313 DpiBit Canvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,309 DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap, 314 310 SmallCityMapTemplate.Canvas, 332 + 15, 0); 315 311 ImageOp_CCC(SmallCityMap, 0, 0, 83, hSmallMap, Color0, Color1, Color2); … … 319 315 else 320 316 begin 321 DpiBit Canvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,317 DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap, 322 318 SmallCityMapTemplate.Canvas, 332, 0); 323 319 ImageOp_CCC(SmallCityMap, 0, 0, wSmallMap, hSmallMap, Color0, … … 328 324 begin 329 325 Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImp]; 330 for i:= 0 to 29 do326 for I := 0 to 29 do 331 327 begin 332 328 for iix := nWonder to nImp - 1 do 333 if (ImpPosition[iix] = i) and (c.Built[iix] > 0) then329 if (ImpPosition[iix] = I) and (C.Built[iix] > 0) then 334 330 begin 335 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),336 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),337 11 + 12 * ( imod 18 div 3)));338 break;331 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 332 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 333 11 + 12 * (I mod 18 div 3))); 334 Break; 339 335 end; 340 336 end; 341 i:= 30;337 I := 30; 342 338 for iix := 0 to nImp do 343 if ( c.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then339 if (C.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then 344 340 begin 345 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),346 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),347 11 + 12 * ( imod 18 div 3)));348 inc(i);349 if i= 36 then350 break; // area is full341 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 342 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 343 11 + 12 * (I mod 18 div 3))); 344 Inc(I); 345 if I = 36 then 346 Break; // area is full 351 347 end; 352 if c.Project and cpImp <> 0 then353 begin 354 iix := c.Project and cpIndex;348 if C.Project and cpImp <> 0 then 349 begin 350 iix := C.Project and cpIndex; 355 351 if iix <> imTrGoods then 356 352 begin 357 353 if (iix >= nWonder) and (ImpPosition[iix] >= 0) then 358 i:= ImpPosition[iix];359 if i< 36 then354 I := ImpPosition[iix]; 355 if I < 36 then 360 356 begin 361 brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];362 FillRect(Rect(5 + 16 * ( i mod 3) + 48 * (idiv 18),363 3 + 12 * ( i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (idiv 18),364 11 + 12 * ( imod 18 div 3)));357 Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject]; 358 FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18), 359 3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18), 360 11 + 12 * (I mod 18 div 3))); 365 361 end; 366 362 end; 367 363 end; 368 brush.style := bsClear;364 Brush.style := bsClear; 369 365 end; 370 366 end; … … 373 369 begin 374 370 UnshareBitmap(ZoomCityMap); 375 DpiBit Canvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap,371 DpiBitBltCanvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap, 376 372 Back.Canvas, xZoomMap, yZoomMap); 377 373 if SmallMapMode = smImprovements then begin … … 383 379 112 * (ZoomArea - 3), wZoomMap - wZoomEnvironment, hZoomMap); 384 380 ImageOp_B(ZoomCityMap, CityMapTemplate, wZoomMap - wZoomEnvironment, 0, 385 1504 + wZoomEnvironment * byte(IsPort), 112 * (ZoomArea - 3),381 1504 + wZoomEnvironment * Byte(IsPort), 112 * (ZoomArea - 3), 386 382 wZoomEnvironment, hZoomMap); 387 383 end; … … 391 387 procedure TCityDlg.OffscreenPaint; 392 388 393 procedure FillBar( x, y, pos, Growth, max, Kind: integer;394 IndicateComplete: boolean);389 procedure FillBar(X, Y, Pos, Growth, Max, Kind: Integer; 390 IndicateComplete: Boolean); 395 391 begin 396 392 BarTex.Assign(MainTexture); … … 399 395 BarTex.ColorBevelShade := BarTex.ColorBevelLight; 400 396 end; 401 PaintRelativeProgressBar( offscreen.Canvas, Kind, x - 3, y, wBar - 4, pos,402 Growth, max, IndicateComplete, BarTex);403 end; 404 405 procedure PaintResources( x, y, Loc: integer; Add4Happy: boolean);397 PaintRelativeProgressBar(Offscreen.Canvas, Kind, X - 3, Y, wBar - 4, Pos, 398 Growth, Max, IndicateComplete, BarTex); 399 end; 400 401 procedure PaintResources(X, Y, Loc: Integer; Add4Happy: Boolean); 406 402 var 407 d, i, Total, xGr, yGr: integer;403 D, I, Total, xGr, yGr: Integer; 408 404 TileInfo: TTileInfo; 409 rare: boolean;405 rare: Boolean; 410 406 begin 411 407 with AreaMap do begin 412 if Server(sGetCityTileInfo, me, Loc, TileInfo) <> eOk then413 begin 414 assert(cix < 0);415 exit408 if Server(sGetCityTileInfo, Me, Loc, TileInfo) <> eOk then 409 begin 410 Assert(cix < 0); 411 Exit 416 412 end; 417 413 Total := TileInfo.Food + TileInfo.Prod + TileInfo.Trade; 418 414 rare := MyMap[Loc] and $06000000 > 0; 419 415 if rare then 420 inc(Total);416 Inc(Total); 421 417 if Add4Happy then 422 inc(Total, 4);418 Inc(Total, 4); 423 419 if Total > 1 then 424 d:= (xxt - 11) div (Total - 1);425 if d< 1 then426 d:= 1;427 if d> 4 then428 d:= 4;429 for i:= 0 to Total - 1 do420 D := (xxt - 11) div (Total - 1); 421 if D < 1 then 422 D := 1; 423 if D > 4 then 424 D := 4; 425 for I := 0 to Total - 1 do 430 426 begin 431 427 yGr := 115; 432 if Add4Happy and ( i>= Total - 4) then428 if Add4Happy and (I >= Total - 4) then 433 429 begin 434 430 xGr := 132; 435 431 yGr := 126 436 432 end 437 else if rare and ( i= Total - 1) then433 else if rare and (I = Total - 1) then 438 434 xGr := 66 + 110 439 else if i>= TileInfo.Food + TileInfo.Prod then435 else if I >= TileInfo.Food + TileInfo.Prod then 440 436 xGr := 66 + 44 441 else if i>= TileInfo.Prod then437 else if I >= TileInfo.Prod then 442 438 xGr := 66 443 439 else 444 440 xGr := 66 + 22; 445 Sprite( offscreen, HGrSystem, x + xxt - 5 + d * (2 * i+ 1 - Total),446 y+ yyt - 5, 10, 10, xGr, yGr);441 Sprite(Offscreen, HGrSystem, X + xxt - 5 + D * (2 * I + 1 - Total), 442 Y + yyt - 5, 10, 10, xGr, yGr); 447 443 end; 448 444 end; 449 445 end; 450 446 var 451 line, MessageCount: integer;452 453 procedure CheckMessage(Flag: integer);447 Line, MessageCount: Integer; 448 449 procedure CheckMessage(Flag: Integer); 454 450 var 455 i, test: integer;456 s: string;451 I, Test: Integer; 452 S: string; 457 453 begin 458 454 if Happened and Flag <> 0 then 459 455 begin 460 i:= 0;461 test := 1;462 while test < Flag do456 I := 0; 457 Test := 1; 458 while Test < Flag do 463 459 begin 464 inc(i);465 inc(test, test)460 Inc(I); 461 Inc(Test, Test); 466 462 end; 467 463 468 464 if AllowChange and (Sounds <> nil) and (OpenSoundEvent = -1) then 469 465 begin 470 s := CityEventSoundItem[i];471 if s<> '' then472 s := Sounds.Lookup(s);473 if (Flag = chProduction) or ( s <> '') and (s[1] <> '*') and (s[1] <> '[')466 S := CityEventSoundItem[I]; 467 if S <> '' then 468 S := Sounds.Lookup(S); 469 if (Flag = chProduction) or (S <> '') and (S[1] <> '*') and (S[1] <> '[') 474 470 then 475 OpenSoundEvent := i471 OpenSoundEvent := I; 476 472 end; 477 473 478 s := CityEventName(i);474 S := CityEventName(I); 479 475 { if Flag=chNoGrowthWarning then 480 if c.Built[imAqueduct]=0 then481 s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])482 else s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }483 RisedTextOut( offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +484 16 * line, s);485 inc(line)476 if C.Built[imAqueduct]=0 then 477 S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)]) 478 else S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); } 479 RisedTextOut(Offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount + 480 16 * Line, S); 481 Inc(Line); 486 482 end; 487 483 end; 488 484 489 485 var 490 x, y, xGr, i, j, iix, d, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,491 HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: integer;492 av: integer;493 PrName, s: string;486 X, Y, xGr, I, J, iix, D, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix, 487 HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: Integer; 488 av: Integer; 489 PrName, S: string; 494 490 UnitInfo: TUnitInfo; 495 491 UnitReport: TUnitReport; 496 IsCityAlive, CanGrow: boolean;492 IsCityAlive, CanGrow: Boolean; 497 493 begin 498 494 inherited; 499 495 if cix >= 0 then 500 c:= MyCity[cix];496 C := MyCity[cix]; 501 497 Report.HypoTiles := -1; 502 498 Report.HypoTaxRate := -1; 503 499 Report.HypoLuxuryRate := -1; 504 500 if cix >= 0 then 505 Server(sGetCityReportNew, me, cix, Report) // own city501 Server(sGetCityReportNew, Me, cix, Report) // own city 506 502 else 507 Server(sGetEnemyCityReportNew, me, cLoc, Report); // enemy city508 TrueFood := c.Food;509 TrueProd := c.Prod;510 TruePoll := c.Pollution;511 if supervising or (cix < 0) then503 Server(sGetEnemyCityReportNew, Me, cLoc, Report); // enemy city 504 TrueFood := C.Food; 505 TrueProd := C.Prod; 506 TruePoll := C.Pollution; 507 if Supervising or (cix < 0) then 512 508 begin // normalize city from after-turn state 513 dec(TrueFood, Report.FoodSurplus);509 Dec(TrueFood, Report.FoodSurplus); 514 510 if TrueFood < 0 then 515 511 TrueFood := 0; // shouldn't happen 516 dec(TrueProd, Report.Production);512 Dec(TrueProd, Report.Production); 517 513 if TrueProd < 0 then 518 514 TrueProd := 0; // shouldn't happen 519 dec(TruePoll, Report.AddPollution);515 Dec(TruePoll, Report.AddPollution); 520 516 if TruePoll < 0 then 521 517 TruePoll := 0; // shouldn't happen 522 518 end; 523 IsCityAlive := (cGov <> gAnarchy) and ( c.Flags and chCaptured = 0);519 IsCityAlive := (cGov <> gAnarchy) and (C.Flags and chCaptured = 0); 524 520 if not IsCityAlive then 525 Report.Working := c.Size;521 Report.Working := C.Size; 526 522 527 523 RedTex.Assign(MainTexture); … … 531 527 RedTex.ColorTextShade := $0000FF; 532 528 533 DpiBit Canvas(offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);529 DpiBitBltCanvas(Offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0); 534 530 535 531 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 536 RisedTextOut( offscreen.Canvas, 42, 7, Caption);537 with offscreen.Canvas do532 RisedTextOut(Offscreen.Canvas, 42, 7, Caption); 533 with Offscreen.Canvas do 538 534 begin // city size 539 brush.Color := $000000;535 Brush.Color := $000000; 540 536 FillRect(Rect(8 + 1, 7 + 1, 36 + 1, 32 + 1)); 541 brush.Color := $FFFFFF;537 Brush.Color := $FFFFFF; 542 538 FillRect(Rect(8, 7, 36, 32)); 543 brush.style := bsClear;539 Brush.style := bsClear; 544 540 Font.Color := $000000; 545 s := inttostr(c.Size);546 TextOut(8 + 14 - textwidth(s) div 2, 7, s);541 S := IntToStr(C.Size); 542 TextOut(8 + 14 - TextWidth(S) div 2, 7, S); 547 543 end; 548 544 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); … … 552 548 MakeRed(Offscreen, 18, 280, 298, 40); 553 549 if cGov = gAnarchy then 554 s:= Phrases.Lookup('GOVERNMENT', gAnarchy)550 S := Phrases.Lookup('GOVERNMENT', gAnarchy) 555 551 else { if c.Flags and chCaptured<>0 then } 556 s:= Phrases.Lookup('CITYEVENTS', 14);557 RisedTextOut( offscreen.Canvas, 167 - BiColorTextWidth(offscreen.Canvas, s)558 div 2, ymOpt - 9, s);552 S := Phrases.Lookup('CITYEVENTS', 14); 553 RisedTextOut(Offscreen.Canvas, 167 - BiColorTextWidth(Offscreen.Canvas, S) 554 div 2, ymOpt - 9, S); 559 555 end 560 556 else if AllowChange then 561 557 begin 562 OptiType := c.Status shr 4 and $0F;563 Sprite( offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,558 OptiType := C.Status shr 4 and $0F; 559 Sprite(Offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64, 564 560 1 + OptiType mod 3 * 64, 217 + OptiType div 3 * 64); 565 561 566 562 { display messages now } 567 563 MessageCount := 0; 568 for i:= 0 to 31 do569 if Happened and ($FFFFFFFF - chCaptured) and (1 shl i) <> 0 then570 inc(MessageCount);564 for I := 0 to 31 do 565 if Happened and ($FFFFFFFF - chCaptured) and (1 shl I) <> 0 then 566 Inc(MessageCount); 571 567 if MessageCount > 3 then 572 568 MessageCount := 3; 573 569 if MessageCount > 0 then 574 570 begin 575 MakeBlue( offscreen, 74, 280, 242, 40);576 line := 0;577 for i:= 0 to nCityEventPriority - 1 do578 if line < MessageCount then579 CheckMessage(CityEventPriority[ i]);571 MakeBlue(Offscreen, 74, 280, 242, 40); 572 Line := 0; 573 for I := 0 to nCityEventPriority - 1 do 574 if Line < MessageCount then 575 CheckMessage(CityEventPriority[I]); 580 576 end 581 577 else 582 578 begin 583 s:= Phrases.Lookup('CITYMANAGETYPE', OptiType);584 j := pos('\', s);585 if j= 0 then586 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40,587 ymOpt - 9, s)579 S := Phrases.Lookup('CITYMANAGETYPE', OptiType); 580 J := Pos('\', S); 581 if J = 0 then 582 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, 583 ymOpt - 9, S) 588 584 else 589 585 begin 590 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40,591 ymOpt - 17, copy(s, 1, j- 1));592 LoweredTextout( offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,593 copy(s, j+ 1, 255));586 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, 587 ymOpt - 17, Copy(S, 1, J - 1)); 588 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1, 589 Copy(S, J + 1, 255)); 594 590 end; 595 591 end; … … 601 597 AreaMap.Paint(xmArea - xxt * 2 * rx, ymArea - yyt * 2 * ry - 3 * yyt, 602 598 dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner, 603 false, AllowChange and IsCityAlive and604 ( c.Status and csResourceWeightsMask = 0));605 DpiBit Canvas(offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,599 False, AllowChange and IsCityAlive and 600 (C.Status and csResourceWeightsMask = 0)); 601 DpiBitBltCanvas(Offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas, 606 602 xmArea + 102, 42); 607 603 … … 615 611 ((Loc1 < 0) or (Loc1 >= G.lx * G.ly) or (MyMap[Loc1] and fCity = 0)) 616 612 then 617 Sprite( offscreen, HGrTerrain, xmArea - xxt + xxt * dx,613 Sprite(Offscreen, HGrTerrain, xmArea - xxt + xxt * dx, 618 614 ymArea - yyt + yyt * dy, xxt * 2, yyt * 2, 1 + 5 * (xxt * 2 + 1), 619 615 1 + yyt + 15 * (yyt * 3 + 1)); 620 if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and c.Tiles <> 0) then616 if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and C.Tiles <> 0) then 621 617 PaintResources(xmArea - xxt + xxt * dx, ymArea - yyt + yyt * dy, 622 618 Loc1, (dx = 0) and (dy = 0)); … … 625 621 626 622 if Report.Working > 1 then 627 d:= (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);628 if d> 28 then629 d:= 28;630 for i:= Report.Working - 1 downto 0 do623 D := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1); 624 if D > 28 then 625 D := 28; 626 for I := Report.Working - 1 downto 0 do 631 627 begin 632 628 if IsCityAlive then … … 634 630 else 635 631 xGr := 141; 636 DpiBit Canvas(offscreen.Canvas, xmArea - 192 + 5 + i * d, ymArea - 96 - 29,632 DpiBitBltCanvas(Offscreen.Canvas, xmArea - 192 + 5 + I * D, ymArea - 96 - 29, 637 633 27, 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow } 638 Sprite( offscreen, HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27,634 Sprite(Offscreen, HGrSystem, xmArea - 192 + 4 + I * D, ymArea - 96 - 30, 27, 639 635 30, xGr, 171); 640 636 end; 641 if c.Size - Report.Working > 1 then642 d := (xmArea + 192 - xService - 32) div (c.Size - Report.Working - 1);643 if d> 28 then644 d:= 28;645 for i := 0 to c.Size - Report.Working - 1 do637 if C.Size - Report.Working > 1 then 638 D := (xmArea + 192 - xService - 32) div (C.Size - Report.Working - 1); 639 if D > 28 then 640 D := 28; 641 for I := 0 to C.Size - Report.Working - 1 do 646 642 begin 647 643 xGr := 1 + 112; 648 DpiBit Canvas(offscreen.Canvas, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27,644 DpiBitBltCanvas(Offscreen.Canvas, xmArea + 192 - 27 + 1 - I * D, 29 + 1, 27, 649 645 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow } 650 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30,646 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 - I * D, 29, 27, 30, 651 647 xGr, 171); 652 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10,648 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 4 - I * D, 29 + 32, 10, 653 649 10, 121, 126); 654 Sprite( offscreen, HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10,650 Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 13 - I * D, 29 + 32, 10, 655 651 10, 121, 126); 656 652 // Sprite(offscreen,HGrSystem,xmArea+192-31+18-i*d,ymArea-96-80+32,10,10,88,115); 657 653 end; 658 654 659 if c.Project and cpImp = 0 then660 PrName := Tribe[cOwner].ModelName[ c.Project and cpIndex]655 if C.Project and cpImp = 0 then 656 PrName := Tribe[cOwner].ModelName[C.Project and cpIndex] 661 657 else 662 PrName := Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex);658 PrName := Phrases.Lookup('IMPROVEMENTS', C.Project and cpIndex); 663 659 PrCost := Report.ProjectCost; 664 660 … … 667 663 begin 668 664 if cGov = gFundamentalism then 669 CountBar( offscreen, xHapp, yHapp + dyBar, wBar, 17,665 CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17, 670 666 Phrases.Lookup('FAITH'), Report.CollectedControl, MainTexture) 671 667 else 672 668 begin 673 CountBar( offscreen, xHapp, yHapp + dyBar, wBar, 17,669 CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17, 674 670 Phrases.Lookup('HAPPINESS'), Report.Morale, MainTexture); 675 CountBar( offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,671 CountBar(Offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16, 676 672 Phrases.Lookup('CONTROL'), Report.CollectedControl, MainTexture); 677 673 end; 678 CountBar( offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),674 CountBar(Offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'), 679 675 Report.Luxury, MainTexture); 680 CountBar( offscreen, xHapp + dxBar, yHapp, wBar, 19,676 CountBar(Offscreen, xHapp + dxBar, yHapp, wBar, 19, 681 677 Phrases.Lookup('UNREST'), 2 * Report.Deployed, MainTexture); 682 CountBar( offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,683 Phrases.Lookup('HAPPINESSDEMAND'), c.Size, MainTexture);678 CountBar(Offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17, 679 Phrases.Lookup('HAPPINESSDEMAND'), C.Size, MainTexture); 684 680 if Report.HappinessBalance >= 0 then 685 CountBar( offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,681 CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17, 686 682 Phrases.Lookup('HAPPINESSPLUS'), Report.HappinessBalance, MainTexture) 687 683 else 688 684 begin 689 685 MakeRed(Offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38); 690 CountBar( offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,686 CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18, 691 687 Phrases.Lookup('LACK'), -Report.HappinessBalance, RedTex); 692 688 end; … … 696 692 if IsCityAlive then 697 693 begin 698 CountBar( offscreen, xFood, yFood + dyBar div 2, wBar, 0,694 CountBar(Offscreen, xFood, yFood + dyBar div 2, wBar, 0, 699 695 Phrases.Lookup('FOOD'), Report.CollectedFood, MainTexture); 700 CountBar( offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,701 Phrases.Lookup('DEMAND'), 2 * c.Size, MainTexture);702 CountBar( offscreen, xFood + dxBar, yFood, wBar, 0,696 CountBar(Offscreen, xFood + dxBar, yFood + dyBar, wBar, 0, 697 Phrases.Lookup('DEMAND'), 2 * C.Size, MainTexture); 698 CountBar(Offscreen, xFood + dxBar, yFood, wBar, 0, 703 699 Phrases.Lookup('SUPPORT'), Report.FoodSupport, MainTexture); 704 700 if Report.FoodSurplus >= 0 then 705 if (cGov = gFuture) or ( c.Size >= NeedAqueductSize) and701 if (cGov = gFuture) or (C.Size >= NeedAqueductSize) and 706 702 (Report.FoodSurplus < 2) then 707 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,703 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6, 708 704 Phrases.Lookup('PROFIT'), Report.FoodSurplus, MainTexture) 709 705 else 710 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,706 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0, 711 707 Phrases.Lookup('SURPLUS'), Report.FoodSurplus, MainTexture) 712 708 else 713 709 begin 714 710 MakeRed(Offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38); 715 CountBar( offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,711 CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1, 716 712 Phrases.Lookup('LACK'), -Report.FoodSurplus, RedTex); 717 713 end; 718 714 end; 719 CanGrow := ( c.Size < MaxCitySize) and (cGov <> gFuture) and720 (Report.FoodSurplus > 0) and (( c.Size < NeedAqueductSize) or721 ( c.Built[imAqueduct] = 1) and (c.Size < NeedSewerSize) or722 ( c.Built[imSewer] = 1));715 CanGrow := (C.Size < MaxCitySize) and (cGov <> gFuture) and 716 (Report.FoodSurplus > 0) and ((C.Size < NeedAqueductSize) or 717 (C.Built[imAqueduct] = 1) and (C.Size < NeedSewerSize) or 718 (C.Built[imSewer] = 1)); 723 719 FillBar(xFood + 3, yFood + 102, TrueFood, 724 CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, c.Size),720 CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, C.Size), 725 721 Report.Storage, 1, CanGrow); 726 LoweredTextout( offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,722 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood + 3 - 5, 727 723 yFood + 102 - 20, Format('%d/%d', [TrueFood, Report.Storage])); 728 LoweredTextout( offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,724 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66, 729 725 Phrases.Lookup('STORAGE')); 730 726 … … 732 728 if IsCityAlive then 733 729 begin 734 CountBar( offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),730 CountBar(Offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'), 735 731 Report.CollectedMaterial, MainTexture); 736 CountBar( offscreen, xProd + dxBar, yProd, wBar, 2,732 CountBar(Offscreen, xProd + dxBar, yProd, wBar, 2, 737 733 Phrases.Lookup('SUPPORT'), Report.MaterialSupport, MainTexture); 738 734 if Report.Production >= 0 then 739 if c.Project and (cpImp + cpIndex) = cpImp + imTrGoods then740 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,735 if C.Project and (cpImp + cpIndex) = cpImp + imTrGoods then 736 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6, 741 737 Phrases.Lookup('PROFIT'), Report.Production, MainTexture) 742 738 else 743 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,739 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2, 744 740 Phrases.Lookup('PROD'), Report.Production, MainTexture) 745 741 else 746 742 begin 747 743 MakeRed(Offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38); 748 CountBar( offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,744 CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3, 749 745 Phrases.Lookup('LACK'), -Report.Production, RedTex); 750 746 end; 751 747 end; 752 if c.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then753 with offscreen.Canvas do754 begin 755 i:= Report.Production;756 if ( i< 0) or not IsCityAlive then757 i:= 0;758 FillBar(xProd + 3, yProd + 16 + 63, TrueProd, i, PrCost, 4, true);759 LoweredTextout( offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,748 if C.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then 749 with Offscreen.Canvas do 750 begin 751 I := Report.Production; 752 if (I < 0) or not IsCityAlive then 753 I := 0; 754 FillBar(xProd + 3, yProd + 16 + 63, TrueProd, I, PrCost, 4, True); 755 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xProd + 3 - 5, 760 756 yProd + 16 + 43, Format('%d/%d', [TrueProd, PrCost])); 761 if BiColorTextWidth( offscreen.Canvas, PrName) > wBar + dxBar then757 if BiColorTextWidth(Offscreen.Canvas, PrName) > wBar + dxBar then 762 758 begin 763 759 repeat 764 Delete(PrName, length(PrName), 1)765 until BiColorTextWidth( offscreen.Canvas, PrName) <= wBar + dxBar;760 Delete(PrName, Length(PrName), 1) 761 until BiColorTextWidth(Offscreen.Canvas, PrName) <= wBar + dxBar; 766 762 PrName := PrName + '.' 767 763 end; 768 764 end; 769 RisedTextOut( offscreen.Canvas, xProd - 2, yProd + 36, PrName);765 RisedTextOut(Offscreen.Canvas, xProd - 2, yProd + 36, PrName); 770 766 771 767 // pollution section … … 773 769 begin 774 770 FillBar(xPoll + 3, yPoll + 20, TruePoll, Report.AddPollution, 775 MaxPollution, 3, true);776 RisedTextOut( offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,771 MaxPollution, 3, True); 772 RisedTextOut(Offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20, 777 773 Phrases.Lookup('POLL')); 778 774 end; … … 781 777 if IsCityAlive and (Report.CollectedTrade > 0) then 782 778 begin 783 CountBar( offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,779 CountBar(Offscreen, xTrade, yTrade + dyBar div 2, wBar, 4, 784 780 Phrases.Lookup('TRADE'), Report.CollectedTrade, MainTexture); 785 CountBar( offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,781 CountBar(Offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5, 786 782 Phrases.Lookup('CORR'), Report.Corruption, MainTexture); 787 CountBar( offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),783 CountBar(Offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'), 788 784 Report.Tax, MainTexture); 789 CountBar( offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,785 CountBar(Offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12, 790 786 Phrases.Lookup('SCIENCE'), Report.Science, MainTexture); 791 787 end; 792 788 793 789 // small map 794 DpiBit Canvas(offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,790 DpiBitBltCanvas(Offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap, 795 791 SmallCityMap.Canvas, 0, 0); 796 792 if SmallMapMode = smImprovements then 797 Frame( offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),793 Frame(Offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3), 798 794 ySmallMap + 24 * (ZoomArea mod 3), xSmallMap + 48 * (ZoomArea div 3) + 49, 799 795 ySmallMap + 24 * (ZoomArea mod 3) + 25, MainTexture.ColorMark, 800 796 MainTexture.ColorMark); 801 Frame( offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,797 Frame(Offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap, 802 798 ySmallMap + hSmallMap, $B0B0B0, $FFFFFF); 803 RFrame( offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +799 RFrame(Offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap + 804 800 1, ySmallMap + hSmallMap + 1, $FFFFFF, $B0B0B0); 805 801 806 Frame( offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,802 Frame(Offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport, 807 803 ySupport + hSupport, $B0B0B0, $FFFFFF); 808 RFrame( offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,804 RFrame(Offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1, 809 805 ySupport + hSupport + 1, $FFFFFF, $B0B0B0); 810 x:= xSupport + wSupport div 2;811 y:= ySupport + hSupport div 2;806 X := xSupport + wSupport div 2; 807 Y := ySupport + hSupport div 2; 812 808 if SmallMapMode = smSupportedUnits then 813 809 begin 814 offscreen.Canvas.brush.Color := MainTexture.ColorMark;815 offscreen.Canvas.FillRect(Rect(x - 27, y - 6, x + 27, y+ 6));816 offscreen.Canvas.brush.style := bsClear;817 end; 818 Sprite( offscreen, HGrSystem, x - 16, y- 5, 10, 10, 88, 115);819 Sprite( offscreen, HGrSystem, x - 5, y- 5, 10, 10, 66, 115);820 Sprite( offscreen, HGrSystem, x + 6, y- 5, 10, 10, 154, 126);821 822 DpiBit Canvas(offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,810 Offscreen.Canvas.Brush.Color := MainTexture.ColorMark; 811 Offscreen.Canvas.FillRect(Rect(X - 27, Y - 6, X + 27, Y + 6)); 812 Offscreen.Canvas.Brush.style := bsClear; 813 end; 814 Sprite(Offscreen, HGrSystem, X - 16, Y - 5, 10, 10, 88, 115); 815 Sprite(Offscreen, HGrSystem, X - 5, Y - 5, 10, 10, 66, 115); 816 Sprite(Offscreen, HGrSystem, X + 6, Y - 5, 10, 10, 154, 126); 817 818 DpiBitBltCanvas(Offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap, 823 819 ZoomCityMap.Canvas, 0, 0); 824 820 825 for i:= 0 to 5 do826 imix[ i] := -1;821 for I := 0 to 5 do 822 imix[I] := -1; 827 823 if SmallMapMode = smImprovements then 828 824 begin … … 831 827 Cnt := 0; 832 828 for iix := 0 to nImp - 1 do 833 if ((iix < nWonder) or (ImpPosition[iix] < 0)) and ( c.Built[iix] > 0) then829 if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (C.Built[iix] > 0) then 834 830 begin 835 i:= Cnt - Page * 6;836 if ( i >= 0) and (i< 6) then837 imix[ i] := iix;838 inc(Cnt);831 I := Cnt - Page * 6; 832 if (I >= 0) and (I < 6) then 833 imix[I] := iix; 834 Inc(Cnt); 839 835 end; 840 836 PageCount := (Cnt + 5) div 6; … … 844 840 for iix := nWonder to nImp - 1 do 845 841 begin 846 i:= ImpPosition[iix] - 6 * ZoomArea;847 if ( i >= 0) and (i < 6) and (c.Built[iix] > 0) then848 imix[ i] := iix;842 I := ImpPosition[iix] - 6 * ZoomArea; 843 if (I >= 0) and (I < 6) and (C.Built[iix] > 0) then 844 imix[I] := iix; 849 845 end; 850 846 PageCount := 0; 851 847 end; 852 for i:= 0 to 5 do853 if imix[ i] >= 0 then848 for I := 0 to 5 do 849 if imix[I] >= 0 then 854 850 begin 855 iix := imix[ i];856 x := xZoomMap + 14 + 72 * (imod 3);857 y := yZoomMap + 14 + 56 * (idiv 3);858 ImpImage( offscreen.Canvas, x, y, iix, cGov, AllowChange and851 iix := imix[I]; 852 X := xZoomMap + 14 + 72 * (I mod 3); 853 Y := yZoomMap + 14 + 56 * (I div 3); 854 ImpImage(Offscreen.Canvas, X, Y, iix, cGov, AllowChange and 859 855 (ClientMode < scContact)); 860 856 if IsCityAlive then … … 862 858 if iix = imColosseum then 863 859 begin 864 Sprite( offscreen, HGrSystem, x + 46, y, 14, 14, 82, 100);860 Sprite(Offscreen, HGrSystem, X + 46, Y, 14, 14, 82, 100); 865 861 end 866 862 else … … 880 876 if HappyGain > 1 then 881 877 begin 882 d:= 30 div (HappyGain - 1);883 if d> 10 then884 d:= 10878 D := 30 div (HappyGain - 1); 879 if D > 10 then 880 D := 10 885 881 end; 886 for j:= 0 to HappyGain - 1 do887 Sprite( offscreen, HGrSystem, x + 50, y + d * j, 10, 10, 132, 126);882 for J := 0 to HappyGain - 1 do 883 Sprite(Offscreen, HGrSystem, X + 50, Y + D * J, 10, 10, 132, 126); 888 884 end; 889 for j:= 0 to Imp[iix].Maint - 1 do890 Sprite( offscreen, HGrSystem, x - 4, y + 29 - 3 * j, 10, 10,885 for J := 0 to Imp[iix].Maint - 1 do 886 Sprite(Offscreen, HGrSystem, X - 4, Y + 29 - 3 * J, 10, 10, 891 887 132, 115); 892 888 end … … 919 915 else { if SmallMapMode = smSupportedUnits then } 920 916 begin 921 LoweredTextout( offscreen.Canvas, -1, MainTexture, xZoomMap + 6,917 LoweredTextout(Offscreen.Canvas, -1, MainTexture, xZoomMap + 6, 922 918 yZoomMap + 2, Phrases.Lookup('SUPUNITS')); 923 FreeSupp := c.Size * SupportFree[cGov] shr 1;919 FreeSupp := C.Size * SupportFree[cGov] shr 1; 924 920 Cnt := 0; 925 for i:= 0 to MyRO.nUn - 1 do926 if (MyUn[ i].Loc >= 0) and (MyUn[i].Home = cix) then927 with MyModel[MyUn[ i].mix] do921 for I := 0 to MyRO.nUn - 1 do 922 if (MyUn[I].Loc >= 0) and (MyUn[I].Home = cix) then 923 with MyModel[MyUn[I].mix] do 928 924 begin 929 Server(sGetUnitReport, me, i, UnitReport);925 Server(sGetUnitReport, Me, I, UnitReport); 930 926 if (Cnt >= 6 * Page) and (Cnt < 6 * (Page + 1)) then 931 927 begin // unit visible in display 932 imix[Cnt - 6 * Page] := i;933 x:= ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;934 y:= ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;935 MakeUnitInfo( me, MyUn[i], UnitInfo);936 NoMap.SetOutput( offscreen);937 NoMap.PaintUnit( x, y, UnitInfo, MyUn[i].Status);938 939 for j:= 0 to UnitReport.FoodSupport - 1 do940 Sprite( offscreen, HGrSystem, x + 38 + 11 * j, y+ 40, 10,928 imix[Cnt - 6 * Page] := I; 929 X := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap; 930 Y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20; 931 MakeUnitInfo(Me, MyUn[I], UnitInfo); 932 NoMap.SetOutput(Offscreen); 933 NoMap.PaintUnit(X, Y, UnitInfo, MyUn[I].Status); 934 935 for J := 0 to UnitReport.FoodSupport - 1 do 936 Sprite(Offscreen, HGrSystem, X + 38 + 11 * J, Y + 40, 10, 941 937 10, 66, 115); 942 for j:= 0 to UnitReport.ProdSupport - 1 do938 for J := 0 to UnitReport.ProdSupport - 1 do 943 939 begin 944 940 if (FreeSupp > 0) and 945 941 (UnitReport.ReportFlags and urfAlwaysSupport = 0) then 946 942 begin 947 Sprite( offscreen, HGrSystem, x + 16 - 11 * j, y+ 40, 10,943 Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10, 948 944 10, 143, 115); 949 dec(FreeSupp);945 Dec(FreeSupp); 950 946 end 951 947 else 952 Sprite( offscreen, HGrSystem, x + 16 - 11 * j, y+ 40, 10,948 Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10, 953 949 10, 88, 115); 954 950 end; 955 951 if UnitReport.ReportFlags and urfDeployed <> 0 then 956 for j:= 0 to 1 do957 Sprite( offscreen, HGrSystem, x + 27 + 11 * j, y+ 40, 10,952 for J := 0 to 1 do 953 Sprite(Offscreen, HGrSystem, X + 27 + 11 * J, Y + 40, 10, 958 954 10, 154, 126) 959 955 end // unit visible in display 960 956 else 961 dec(FreeSupp, UnitReport.ProdSupport);962 inc(Cnt);957 Dec(FreeSupp, UnitReport.ProdSupport); 958 Inc(Cnt); 963 959 end; 964 960 PageCount := (Cnt + 5) div 6; … … 973 969 PageDownBtn.Visible := PageCount > 1; 974 970 975 with offscreen.Canvas do971 with Offscreen.Canvas do 976 972 begin 977 973 { display project now } 978 DLine( offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,974 DLine(Offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10, 979 975 yProd + dyBar + 16, $FFFFFF, $B0B0B0); 980 976 if ProdHint then 981 977 begin 982 ScreenTools.Frame( offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,978 ScreenTools.Frame(Offscreen.Canvas, xView + 9 - 1, yView + 5 - 1, 983 979 xView + 9 + xSizeBig, yView + 5 + ySizeBig, $B0B0B0, $FFFFFF); 984 RFrame( offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,980 RFrame(Offscreen.Canvas, xView + 9 - 2, yView + 5 - 2, 985 981 xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, $FFFFFF, $B0B0B0); 986 with offscreen.Canvas do982 with Offscreen.Canvas do 987 983 begin 988 brush.Color := $000000;984 Brush.Color := $000000; 989 985 FillRect(Rect(xView + 9, yView + 5, xView + 1 + 72 - 8, 990 986 yView + 5 + 40)); 991 brush.style := bsClear;987 Brush.style := bsClear; 992 988 end; 993 989 end 994 else if AllowChange and ( c.Status and 7 <> 0) then990 else if AllowChange and (C.Status and 7 <> 0) then 995 991 begin // city type autobuild 996 FrameImage( offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,997 ySizeBig, ( c.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and992 FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig, 993 ySizeBig, (C.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and 998 994 (ClientMode < scContact)); 999 995 end 1000 else if c.Project and cpImp = 0 then996 else if C.Project and cpImp = 0 then 1001 997 begin // project is unit 1002 FrameImage( offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,998 FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig, 1003 999 ySizeBig, 0, 0, AllowChange and (ClientMode < scContact)); 1004 with Tribe[cOwner].ModelPicture[ c.Project and cpIndex] do1005 Sprite( offscreen, HGr, xView + 5, yView + 1, 64, 44,1000 with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do 1001 Sprite(Offscreen, HGr, xView + 5, yView + 1, 64, 44, 1006 1002 pix mod 10 * 65 + 1, pix div 10 * 49 + 1); 1007 1003 end … … 1009 1005 begin // project is building 1010 1006 if ProdHint then 1011 Paintiix := c.Project0 and cpIndex1007 Paintiix := C.Project0 and cpIndex 1012 1008 else 1013 Paintiix := c.Project and cpIndex;1014 ImpImage( offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,1009 Paintiix := C.Project and cpIndex; 1010 ImpImage(Offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov, 1015 1011 AllowChange and (ClientMode < scContact)); 1016 1012 end; … … 1019 1015 if AllowChange and (ClientMode < scContact) then 1020 1016 begin 1021 i := Server(sBuyCityProject - sExecute, me, cix, nil^);1022 BuyBtn.Visible := ( i = eOk) or (i= eViolation);1017 I := Server(sBuyCityProject - sExecute, Me, cix, nil^); 1018 BuyBtn.Visible := (I = eOk) or (I = eViolation); 1023 1019 end 1024 1020 else 1025 BuyBtn.Visible := false;1021 BuyBtn.Visible := False; 1026 1022 1027 1023 MarkUsedOffscreen(ClientWidth, ClientHeight); 1028 end; { OffscreenPaint }1024 end; 1029 1025 1030 1026 procedure TCityDlg.FormShow(Sender: TObject); 1031 1027 var 1032 dx, dy, Loc1: integer;1028 dx, dy, Loc1: Integer; 1033 1029 GetCityData: TGetCityData; 1034 1030 begin … … 1036 1032 if cix >= 0 then 1037 1033 begin { own city } 1038 c:= MyCity[cix];1039 cOwner := me;1034 C := MyCity[cix]; 1035 cOwner := Me; 1040 1036 cGov := MyRO.Government; 1041 1037 ProdHint := (cGov <> gAnarchy) and 1042 1038 (Happened and (chProduction or chFounded or chCaptured or 1043 1039 chAllImpsMade) <> 0); 1044 Server(sGetCityAreaInfo, me, cix, CityAreaInfo);1040 Server(sGetCityAreaInfo, Me, cix, CityAreaInfo); 1045 1041 NextCityBtn.Visible := WindowMode = wmPersistent; 1046 1042 PrevCityBtn.Visible := WindowMode = wmPersistent; … … 1049 1045 begin 1050 1046 SmallMapMode := smImprovements; 1051 Server(sGetCity, me, cLoc, GetCityData);1052 c := GetCityData.c;1047 Server(sGetCity, Me, cLoc, GetCityData); 1048 C := GetCityData.C; 1053 1049 cOwner := GetCityData.Owner; 1054 1050 cGov := MyRO.EnemyReport[cOwner].Government; 1055 Happened := c.Flags and $7FFFFFFF;1056 ProdHint := false;1057 Server(sGetEnemyCityAreaInfo, me, cLoc, CityAreaInfo);1058 1059 if c.Project and cpImp = 0 then1051 Happened := C.Flags and $7FFFFFFF; 1052 ProdHint := False; 1053 Server(sGetEnemyCityAreaInfo, Me, cLoc, CityAreaInfo); 1054 1055 if C.Project and cpImp = 0 then 1060 1056 begin 1061 1057 emix := MyRO.nEnemyModel - 1; 1062 1058 while (emix > 0) and ((MyRO.EnemyModel[emix].Owner <> cOwner) or 1063 ( integer(MyRO.EnemyModel[emix].mix) <> c.Project and cpIndex)) do1064 dec(emix);1065 if not Assigned(Tribe[cOwner].ModelPicture[ c.Project and cpIndex].HGr) then1059 (Integer(MyRO.EnemyModel[emix].mix) <> C.Project and cpIndex)) do 1060 Dec(emix); 1061 if not Assigned(Tribe[cOwner].ModelPicture[C.Project and cpIndex].HGr) then 1066 1062 InitEnemyModel(emix); 1067 1063 end; 1068 1064 1069 NextCityBtn.Visible := false;1070 PrevCityBtn.Visible := false;1065 NextCityBtn.Visible := False; 1066 PrevCityBtn.Visible := False; 1071 1067 end; 1072 1068 Page := 0; 1073 1069 1074 if c.Size < 5 then1070 if C.Size < 5 then 1075 1071 SizeClass := 0 1076 else if c.Size < 9 then1072 else if C.Size < 9 then 1077 1073 SizeClass := 1 1078 else if c.Size < 13 then1074 else if C.Size < 13 then 1079 1075 SizeClass := 2 1080 1076 else … … 1082 1078 1083 1079 // check if port 1084 IsPort := false;1080 IsPort := False; 1085 1081 for dx := -2 to 2 do 1086 1082 for dy := -2 to 2 do 1087 if abs(dx) + abs(dy) = 2 then1083 if Abs(dx) + Abs(dy) = 2 then 1088 1084 begin 1089 1085 Loc1 := dLoc(cLoc, dx, dy); 1090 1086 if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) and 1091 1087 (MyMap[Loc1] and fTerrain < fGrass) then 1092 IsPort := true;1088 IsPort := True; 1093 1089 end; 1094 1090 … … 1099 1095 end; 1100 1096 1101 Caption := CityName( c.ID);1097 Caption := CityName(C.ID); 1102 1098 1103 1099 InitSmallCityMap; … … 1105 1101 OpenSoundEvent := -1; 1106 1102 OffscreenPaint; 1107 Timer1.Enabled := true;1108 end; 1109 1110 procedure TCityDlg.ShowNewContent(NewMode , Loc: integer; ShowEvent: cardinal);1103 Timer1.Enabled := True; 1104 end; 1105 1106 procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal); 1111 1107 begin 1112 1108 if MyMap[Loc] and fOwned <> 0 then … … 1114 1110 cix := MyRO.nCity - 1; 1115 1111 while (cix >= 0) and (MyCity[cix].Loc <> Loc) do 1116 dec(cix);1117 assert(cix >= 0);1112 Dec(cix); 1113 Assert(cix >= 0); 1118 1114 if (Optimize_cixTileChange >= 0) and 1119 1115 (Optimize_TilesBeforeChange and not MyCity[Optimize_cixTileChange].Tiles … … 1131 1127 else 1132 1128 cix := -1; 1133 AllowChange := not supervising and (cix >= 0);1129 AllowChange := not Supervising and (cix >= 0); 1134 1130 cLoc := Loc; 1135 1131 Happened := ShowEvent; … … 1138 1134 1139 1135 procedure TCityDlg.FormMouseDown(Sender: TObject; Button: TMouseButton; 1140 Shift: TShiftState; x, y: integer);1136 Shift: TShiftState; X, Y: Integer); 1141 1137 var 1142 i, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: integer;1143 Rebuild: boolean;1144 begin 1145 if (ssLeft in Shift) and ( x >= xSmallMap) and (x< xSmallMap + wSmallMap) and1146 ( y >= ySmallMap) and (y< ySmallMap + hSmallMap) then1138 I, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: Integer; 1139 Rebuild: Boolean; 1140 begin 1141 if (ssLeft in Shift) and (X >= xSmallMap) and (X < xSmallMap + wSmallMap) and 1142 (Y >= ySmallMap) and (Y < ySmallMap + hSmallMap) then 1147 1143 begin 1148 1144 SmallMapMode := smImprovements; 1149 ZoomArea := ( y- ySmallMap) * 3 div hSmallMap + 3 *1150 (( x- xSmallMap) * 2 div wSmallMap);1145 ZoomArea := (Y - ySmallMap) * 3 div hSmallMap + 3 * 1146 ((X - xSmallMap) * 2 div wSmallMap); 1151 1147 Page := 0; 1152 1148 InitZoomCityMap; 1153 1149 SmartUpdateContent; 1154 exit;1155 end; 1156 if (ssLeft in Shift) and ( x >= xSupport) and (x< xSupport + wSupport) and1157 ( y >= ySupport) and (y< ySupport + hSupport) then1150 Exit; 1151 end; 1152 if (ssLeft in Shift) and (X >= xSupport) and (X < xSupport + wSupport) and 1153 (Y >= ySupport) and (Y < ySupport + hSupport) then 1158 1154 begin 1159 1155 SmallMapMode := smSupportedUnits; … … 1161 1157 InitZoomCityMap; 1162 1158 SmartUpdateContent; 1163 exit;1159 Exit; 1164 1160 end; 1165 1161 if not AllowChange then 1166 exit; // not an own city1162 Exit; // Not an own city 1167 1163 1168 1164 if (ssLeft in Shift) then 1169 if (ClientMode < scContact) and ( x >= xView) and (y>= yView) and1170 ( x < xView + 73) and (y< yView + 50) then1165 if (ClientMode < scContact) and (X >= xView) and (Y >= yView) and 1166 (X < xView + 73) and (Y < yView + 50) then 1171 1167 if cGov = gAnarchy then 1172 with M essgExDlg do1168 with MainScreen.MessgExDlg do 1173 1169 begin 1174 1170 { MessgText:=Phrases.Lookup('OUTOFCONTROL'); 1175 if c.Project and cpImp=0 then1176 MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[ c.Project and cpIndex]])1177 else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex)]); }1171 if C.Project and cpImp=0 then 1172 MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[C.Project and cpIndex]]) 1173 else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',C.Project and cpIndex)]); } 1178 1174 MessgText := Phrases.Lookup('NOCHANGEINANARCHY'); 1179 1175 Kind := mkOk; … … 1184 1180 if ProdHint then 1185 1181 begin 1186 ProdHint := false;1182 ProdHint := False; 1187 1183 SmartUpdateContent 1188 1184 end; 1189 1185 ChooseProject; 1190 1186 end 1191 else if (SmallMapMode = smImprovements) and ( x >= xZoomMap) and (x< xZoomMap + wZoomMap) and1192 ( y >= yZoomMap) and (y< yZoomMap + hZoomMap) then1193 begin 1194 i:= 5;1195 while ( i >= 0) and not((x >= xZoomMap + 14 + 72 * (imod 3)) and1196 ( x < xZoomMap + 14 + 56 + 72 * (imod 3)) and1197 ( y >= yZoomMap + 14 + 56 * (idiv 3)) and1198 ( y < yZoomMap + 14 + 40 + 56 * (idiv 3))) do1199 dec(i);1200 if i>= 0 then1187 else if (SmallMapMode = smImprovements) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and 1188 (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then 1189 begin 1190 I := 5; 1191 while (I >= 0) and not((X >= xZoomMap + 14 + 72 * (I mod 3)) and 1192 (X < xZoomMap + 14 + 56 + 72 * (I mod 3)) and 1193 (Y >= yZoomMap + 14 + 56 * (I div 3)) and 1194 (Y < yZoomMap + 14 + 40 + 56 * (I div 3))) do 1195 Dec(I); 1196 if I >= 0 then 1201 1197 begin 1202 iix := imix[ i];1198 iix := imix[I]; 1203 1199 if iix >= 0 then 1204 1200 if ssShift in Shift then 1205 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, iix)1201 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, iix) 1206 1202 else if (ClientMode < scContact) then 1207 with M essgExDlg do1203 with MainScreen.MessgExDlg do 1208 1204 begin 1209 1205 IconKind := mikImp; … … 1220 1216 else 1221 1217 begin 1222 SellResult := Server(sSellCityImprovement - sExecute, me,1218 SellResult := Server(sSellCityImprovement - sExecute, Me, 1223 1219 cix, iix); 1224 1220 if SellResult < rExecuted then … … 1235 1231 else 1236 1232 begin 1237 if Server(sRebuildCityImprovement - sExecute, me, cix, iix) < rExecuted1233 if Server(sRebuildCityImprovement - sExecute, Me, cix, iix) < rExecuted 1238 1234 then 1239 1235 begin // no rebuild possible, ask for sell only 1240 Rebuild := false;1236 Rebuild := False; 1241 1237 MessgText := Phrases.Lookup('IMPROVEMENTS', iix); 1242 1238 if not Phrases2FallenBackToEnglish then 1243 1239 MessgText := Format(Phrases2.Lookup('SELL2'), 1244 1240 [MessgText, Imp[iix].Cost * BuildCostMod 1245 [G.Difficulty[ me]] div 12])1241 [G.Difficulty[Me]] div 12]) 1246 1242 else 1247 1243 MessgText := Format(Phrases.Lookup('SELL'), [MessgText]); 1248 1244 if iix = imSpacePort then 1249 with MyRO.Ship[ me] do1245 with MyRO.Ship[Me] do 1250 1246 if Parts[0] + Parts[1] + Parts[2] > 0 then 1251 1247 MessgText := MessgText + ' ' + … … 1258 1254 else 1259 1255 begin 1260 Rebuild := true;1256 Rebuild := True; 1261 1257 MessgText := Phrases.Lookup('IMPROVEMENTS', iix); 1262 1258 if not Phrases2FallenBackToEnglish then 1263 1259 MessgText := Format(Phrases2.Lookup('DISPOSE2'), 1264 1260 [MessgText, Imp[iix].Cost * BuildCostMod 1265 [G.Difficulty[ me]] div 12 * 2 div 3])1261 [G.Difficulty[Me]] div 12 * 2 div 3]) 1266 1262 else 1267 1263 MessgText := Format(Phrases.Lookup('DISPOSE'), 1268 1264 [MessgText]); 1269 1265 if iix = imSpacePort then 1270 with MyRO.Ship[ me] do1266 with MyRO.Ship[Me] do 1271 1267 if Parts[0] + Parts[1] + Parts[2] > 0 then 1272 1268 MessgText := MessgText + ' ' + … … 1282 1278 begin 1283 1279 Play('CITY_REBUILDIMP'); 1284 Server(sRebuildCityImprovement, me, cix, iix);1280 Server(sRebuildCityImprovement, Me, cix, iix); 1285 1281 end 1286 1282 else 1287 1283 begin 1288 1284 Play('CITY_SELLIMP'); 1289 Server(sSellCityImprovement, me, cix, iix);1285 Server(sSellCityImprovement, Me, cix, iix); 1290 1286 end; 1291 1287 CityOptimizer_CityChange(cix); … … 1300 1296 end; 1301 1297 end 1302 else if (SmallMapMode = smSupportedUnits) and ( x >= xZoomMap) and (x< xZoomMap + wZoomMap) and1303 ( y >= yZoomMap) and (y< yZoomMap + hZoomMap) then1304 begin 1305 i:= 5;1306 while ( i >= 0) and not((x >= xZoomMap + 64 * (imod 3)) and1307 ( x < xZoomMap + 64 + 64 * (imod 3)) and1308 ( y >= yZoomMap + 20 + 48 * (idiv 3)) and1309 ( y < yZoomMap + 20 + 52 + 48 * (idiv 3))) do1310 dec(i);1311 if ( i >= 0) and (imix[i] >= 0) then1298 else if (SmallMapMode = smSupportedUnits) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and 1299 (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then 1300 begin 1301 I := 5; 1302 while (I >= 0) and not((X >= xZoomMap + 64 * (I mod 3)) and 1303 (X < xZoomMap + 64 + 64 * (I mod 3)) and 1304 (Y >= yZoomMap + 20 + 48 * (I div 3)) and 1305 (Y < yZoomMap + 20 + 52 + 48 * (I div 3))) do 1306 Dec(I); 1307 if (I >= 0) and (imix[I] >= 0) then 1312 1308 if ssShift in Shift then 1313 1309 else if (cix >= 0) and (ClientMode < scContact) and … … 1316 1312 CloseAction := None; 1317 1313 Close; 1318 MainScreen.CityClosed(imix[ i], false, true);1314 MainScreen.CityClosed(imix[I], False, True); 1319 1315 end; 1320 1316 end 1321 else if ( x >= xmArea - 192) and (x < xmArea + 192) and (y>= ymArea - 96)1322 and ( y< ymArea + 96) then1317 else if (X >= xmArea - 192) and (X < xmArea + 192) and (Y >= ymArea - 96) 1318 and (Y < ymArea + 96) then 1323 1319 with AreaMap do begin 1324 qx := ((4000 * xxt * yyt) + ( x - xmArea) * (yyt * 2) + (y- ymArea + yyt)1320 qx := ((4000 * xxt * yyt) + (X - xmArea) * (yyt * 2) + (Y - ymArea + yyt) 1325 1321 * (xxt * 2)) div (xxt * yyt * 4) - 1000; 1326 qy := ((4000 * xxt * yyt) + ( y - ymArea + yyt) * (xxt * 2) - (x- xmArea)1322 qy := ((4000 * xxt * yyt) + (Y - ymArea + yyt) * (xxt * 2) - (X - xmArea) 1327 1323 * (yyt * 2)) div (xxt * yyt * 4) - 1000; 1328 1324 dx := qx - qy; … … 1334 1330 Loc1 := dLoc(cLoc, dx, dy); 1335 1331 if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) then 1336 HelpOnTerrain(Loc1, FWindowMode or wmPersistent)1332 HelpOnTerrain(Loc1, WindowModeMakePersistent(FWindowMode)) 1337 1333 end 1338 1334 else if (ClientMode < scContact) and (cGov <> gAnarchy) and 1339 ( c.Flags and chCaptured = 0) then1335 (C.Flags and chCaptured = 0) then 1340 1336 begin // toggle exploitation 1341 assert(not supervising);1342 if c.Status and csResourceWeightsMask <> 0 then1337 Assert(not Supervising); 1338 if C.Status and csResourceWeightsMask <> 0 then 1343 1339 begin 1344 with M essgExDlg do1340 with MainScreen.MessgExDlg do 1345 1341 begin 1346 1342 MessgText := Phrases.Lookup('CITYMANAGEOFF'); … … 1350 1346 ShowModal; 1351 1347 end; 1352 if M essgExDlg.ModalResult = mrOK then1348 if MainScreen.MessgExDlg.ModalResult = mrOK then 1353 1349 begin 1354 1350 MyCity[cix].Status := MyCity[cix].Status and 1355 1351 not csResourceWeightsMask; // off 1356 c.Status := MyCity[cix].Status;1352 C.Status := MyCity[cix].Status; 1357 1353 SmartUpdateContent; 1358 1354 end; 1359 exit;1355 Exit; 1360 1356 end; 1361 1357 fix := (dy + 3) shl 2 + (dx + 3) shr 1; 1362 1358 NewTiles := MyCity[cix].Tiles xor (1 shl fix); 1363 if Server(sSetCityTiles, me, cix, NewTiles) >= rExecuted then1359 if Server(sSetCityTiles, Me, cix, NewTiles) >= rExecuted then 1364 1360 begin 1365 1361 SmartUpdateContent; … … 1370 1366 end 1371 1367 else if (ClientMode < scContact) and (cGov <> gAnarchy) and 1372 ( c.Flags and chCaptured = 0) and (x >= xmOpt - 32) and (x< xmOpt + 32)1373 and ( y >= ymOpt - 32) and (y< ymOpt + 32) then1374 begin 1375 i := sqr(x - xmOpt) + sqr(y- ymOpt); // click radius1376 if i<= 32 * 32 then1368 (C.Flags and chCaptured = 0) and (X >= xmOpt - 32) and (X < xmOpt + 32) 1369 and (Y >= ymOpt - 32) and (Y < ymOpt + 32) then 1370 begin 1371 I := sqr(X - xmOpt) + sqr(Y - ymOpt); // click radius 1372 if I <= 32 * 32 then 1377 1373 begin 1378 if i< 16 * 16 then // inner area clicked1379 if c.Status and csResourceWeightsMask <> 0 then1380 i := (c.Status shr 4 and $0F) mod 5 + 1 // rotate except off1374 if I < 16 * 16 then // inner area clicked 1375 if C.Status and csResourceWeightsMask <> 0 then 1376 I := (C.Status shr 4 and $0F) mod 5 + 1 // rotate except off 1381 1377 else 1382 i:= 3 // rwGrowth1378 I := 3 // rwGrowth 1383 1379 else 1384 case trunc(arctan2( x - xmOpt, ymOpt - y) * 180 / pi) of1380 case trunc(arctan2(X - xmOpt, ymOpt - Y) * 180 / pi) of 1385 1381 - 25 - 52 * 2 .. -26 - 52: 1386 i:= 1;1382 I := 1; 1387 1383 -25 - 52 .. -26: 1388 i:= 2;1384 I := 2; 1389 1385 -25 .. 25: 1390 i:= 3;1386 I := 3; 1391 1387 26 .. 25 + 52: 1392 i:= 4;1388 I := 4; 1393 1389 26 + 52 .. 25 + 52 * 2: 1394 i:= 5;1390 I := 5; 1395 1391 180 - 26 .. 180, -180 .. -180 + 26: 1396 i:= 0;1392 I := 0; 1397 1393 else 1398 i:= -1;1394 I := -1; 1399 1395 end; 1400 if i>= 0 then1396 if I >= 0 then 1401 1397 begin 1402 ChangeResourceWeights( i);1398 ChangeResourceWeights(I); 1403 1399 SmartUpdateContent; 1404 1400 if WindowMode <> wmModal then … … 1407 1403 end; 1408 1404 end; 1409 end; { FormMouseDown }1405 end; 1410 1406 1411 1407 procedure TCityDlg.ChooseProject; … … 1422 1418 ); 1423 1419 1424 function ProjectType(Project: integer): TProjectType;1420 function ProjectType(Project: Integer): TProjectType; 1425 1421 begin 1426 1422 if Project and cpCompleted <> 0 then … … 1444 1440 1445 1441 var 1446 NewProject, OldMoney, cix1: integer;1442 NewProject, OldMoney, cix1: Integer; 1447 1443 pt0, pt1: TProjectType; 1448 QueryOk: boolean;1449 begin 1450 Assert(not supervising);1451 M odalSelectDlg.ShowNewContent_CityProject(wmModal, cix);1452 if M odalSelectDlg.result <> -1 then1453 begin 1454 if M odalSelectDlg.result and cpType <> 0 then1444 QueryOk: Boolean; 1445 begin 1446 Assert(not Supervising); 1447 MainScreen.ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix); 1448 if MainScreen.ModalSelectDlg.Result <> -1 then 1449 begin 1450 if MainScreen.ModalSelectDlg.Result and cpType <> 0 then 1455 1451 begin 1456 1452 MyCity[cix].Status := MyCity[cix].Status and not 7 or 1457 (1 + M odalSelectDlg.result and cpIndex);1458 AutoBuild(cix, MyData.ImpOrder[M odalSelectDlg.result and cpIndex]);1453 (1 + MainScreen.ModalSelectDlg.Result and cpIndex); 1454 AutoBuild(cix, MyData.ImpOrder[MainScreen.ModalSelectDlg.Result and cpIndex]); 1459 1455 end 1460 1456 else 1461 1457 begin 1462 NewProject := M odalSelectDlg.Result;1458 NewProject := MainScreen.ModalSelectDlg.Result; 1463 1459 QueryOk := True; 1464 1460 if (NewProject and cpImp <> 0) and (NewProject and cpIndex >= 28) and 1465 1461 (MyRO.NatBuilt[NewProject and cpIndex] > 0) then 1466 with M essgExDlg do1462 with MainScreen.MessgExDlg do 1467 1463 begin 1468 1464 cix1 := MyRO.nCity - 1; … … 1521 1517 then 1522 1518 NewProject := NewProject or cpDisbandCity; 1523 Server(sSetCityProject, me, cix, NewProject);1524 c.Project := MyCity[cix].Project;1519 Server(sSetCityProject, Me, cix, NewProject); 1520 C.Project := MyCity[cix].Project; 1525 1521 if MyRO.Money > OldMoney then 1526 1522 Play('CITY_SELLIMP'); … … 1537 1533 procedure TCityDlg.BuyClick(Sender: TObject); 1538 1534 var 1539 NextProd, Cost: integer;1535 NextProd, Cost: Integer; 1540 1536 begin 1541 1537 if (cix < 0) or (ClientMode >= scContact) then 1542 exit;1543 with MyCity[cix], M essgExDlg do1538 Exit; 1539 with MyCity[cix], MainScreen.MessgExDlg do 1544 1540 begin 1545 1541 Cost := Report.ProjectCost; … … 1548 1544 NextProd := 0; 1549 1545 Cost := Cost - Prod - NextProd; 1550 if (MyRO.Wonder[woMich].EffectiveOwner = me) and (Project and cpImp <> 0)1546 if (MyRO.Wonder[woMich].EffectiveOwner = Me) and (Project and cpImp <> 0) 1551 1547 then 1552 1548 Cost := Cost * 2 … … 1572 1568 if (Kind = mkYesNo) and (ModalResult = mrOK) then 1573 1569 begin 1574 if Server(sBuyCityProject, me, cix, nil^) >= rExecuted then1570 if Server(sBuyCityProject, Me, cix, nil^) >= rExecuted then 1575 1571 begin 1576 1572 Play('CITY_BUYPROJECT'); … … 1585 1581 procedure TCityDlg.FormClose(Sender: TObject; var Action: TCloseAction); 1586 1582 begin 1587 Timer1.Enabled := false;1588 ProdHint := false;1583 Timer1.Enabled := False; 1584 ProdHint := False; 1589 1585 MarkCityLoc := -1; 1590 1586 if Optimize_cixTileChange >= 0 then … … 1615 1611 with Canvas do 1616 1612 begin 1617 DpiBit Canvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas,1613 DpiBitBltCanvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas, 1618 1614 xView + 5, yView + 1); 1619 DpiBit Canvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas,1615 DpiBitBltCanvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas, 1620 1616 xView + 5, yView + 3); 1621 DpiBit Canvas(Canvas, xView + 5 + 62, yView + 3, 2, 42,1617 DpiBitBltCanvas(Canvas, xView + 5 + 62, yView + 3, 2, 42, 1622 1618 Back.Canvas, xView + 5 + 62, yView + 3); 1623 1619 ScreenTools.Frame(Canvas, xView + 9 - 1, yView + 5 - 1, xView + 9 + xSizeBig, … … 1632 1628 else if BlinkTime = 6 then 1633 1629 begin 1634 if AllowChange and ( c.Status and 7 <> 0) then1630 if AllowChange and (C.Status and 7 <> 0) then 1635 1631 begin // city type autobuild 1636 1632 FrameImage(Canvas, bigimp, xView + 9, yView + 5, xSizeBig, ySizeBig, 1637 ( c.Status and 7 - 1 + 3) * xSizeBig, 0, true);1633 (C.Status and 7 - 1 + 3) * xSizeBig, 0, True); 1638 1634 end 1639 else if c.Project and cpImp = 0 then1635 else if C.Project and cpImp = 0 then 1640 1636 begin // project is unit 1641 DpiBit Canvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,1637 DpiBitBltCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig, 1642 1638 Bigimp.Canvas, 0, 0); 1643 with Tribe[cOwner].ModelPicture[ c.Project and cpIndex] do1639 with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do 1644 1640 Sprite(Canvas, HGr, xView + 5, yView + 1, 64, 44, pix mod 10 * 65 + 1, 1645 1641 pix div 10 * 49 + 1); 1646 1642 end 1647 1643 else 1648 ImpImage(Canvas, xView + 9, yView + 5, c.Project0 and cpIndex,1649 cGov, true);1644 ImpImage(Canvas, xView + 9, yView + 5, C.Project0 and cpIndex, 1645 cGov, True); 1650 1646 end; 1651 1647 end; … … 1663 1659 if 1 shl OpenSoundEvent = chProduction then 1664 1660 begin 1665 if c.Project0 and cpImp <> 0 then1666 begin 1667 if c.Project0 and cpIndex >= 28 then1661 if C.Project0 and cpImp <> 0 then 1662 begin 1663 if C.Project0 and cpIndex >= 28 then 1668 1664 // wonders have already extra message with sound 1669 if Imp[ c.Project0 and cpIndex].Kind = ikShipPart then1665 if Imp[C.Project0 and cpIndex].Kind = ikShipPart then 1670 1666 Play('SHIP_BUILT') 1671 1667 else … … 1681 1677 end; 1682 1678 1683 function Prio(iix: integer): integer;1679 function Prio(iix: Integer): Integer; 1684 1680 begin 1685 1681 case Imp[iix].Kind of 1686 1682 ikWonder: 1687 result := iix + 10000;1683 Result := iix + 10000; 1688 1684 ikNatLocal, ikNatGlobal: 1689 1685 case iix of 1690 1686 imPalace: 1691 result := 0;1687 Result := 0; 1692 1688 else 1693 result := iix + 20000;1689 Result := iix + 20000; 1694 1690 end; 1695 1691 else 1696 1692 case iix of 1697 1693 imTownHall, imCourt: 1698 result := iix + 30000;1694 Result := iix + 30000; 1699 1695 imAqueduct, imSewer: 1700 result := iix + 40000;1696 Result := iix + 40000; 1701 1697 imTemple, imTheater, imCathedral: 1702 result := iix + 50000;1703 else 1704 result := iix + 90000;1698 Result := iix + 50000; 1699 else 1700 Result := iix + 90000; 1705 1701 end; 1706 1702 end; … … 1717 1713 end; 1718 1714 1719 procedure TCityDlg.ChangeCity( d: integer);1715 procedure TCityDlg.ChangeCity(D: Integer); 1720 1716 var 1721 cixNew: integer;1717 cixNew: Integer; 1722 1718 begin 1723 1719 cixNew := cix; 1724 1720 repeat 1725 cixNew := (cixNew + MyRO.nCity + d) mod MyRO.nCity;1721 cixNew := (cixNew + MyRO.nCity + D) mod MyRO.nCity; 1726 1722 until (MyCity[cixNew].Loc >= 0) or (cixNew = cix); 1727 1723 if cixNew <> cix then … … 1742 1738 end; 1743 1739 1744 { procedure TCityDlg.AdviceBtnClick(Sender: TObject);1745 begin1746 AdvisorDlg.GiveCityAdvice(cix);1747 end; }1748 1749 1740 procedure TCityDlg.PageUpBtnClick(Sender: TObject); 1750 1741 begin 1751 1742 if Page > 0 then 1752 1743 begin 1753 dec(Page);1744 Dec(Page); 1754 1745 SmartUpdateContent; 1755 1746 end; … … 1760 1751 if Page < PageCount - 1 then 1761 1752 begin 1762 inc(Page);1753 Inc(Page); 1763 1754 SmartUpdateContent; 1764 1755 end; 1765 1756 end; 1766 1757 1767 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: integer);1758 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: Integer); 1768 1759 var 1769 1760 Advice: TCityTileAdviceData; 1770 1761 begin 1771 assert(not supervising);1772 assert(cix >= 0);1762 Assert(not Supervising); 1763 Assert(cix >= 0); 1773 1764 MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or 1774 1765 (iResourceWeights shl 4); 1775 c.Status := MyCity[cix].Status;1766 C.Status := MyCity[cix].Status; 1776 1767 if iResourceWeights > 0 then 1777 1768 begin 1778 1769 Advice.ResourceWeights := OfferedResourceWeights[iResourceWeights]; 1779 Server(sGetCityTileAdvice, me, cix, Advice);1770 Server(sGetCityTileAdvice, Me, cix, Advice); 1780 1771 if Advice.Tiles <> MyCity[cix].Tiles then 1781 Server(sSetCityTiles, me, cix, Advice.Tiles);1772 Server(sSetCityTiles, Me, cix, Advice.Tiles); 1782 1773 end; 1783 1774 end; … … 1785 1776 procedure SortImprovements; 1786 1777 var 1787 i, j, k: integer;1788 begin 1789 for i:= 0 to nImp - 1 do1790 ImpSorted[ i] := i;1791 for i:= 0 to nImp - 2 do1792 for j := i+ 1 to nImp - 1 do1793 if Prio(ImpSorted[ i]) > Prio(ImpSorted[j]) then begin1794 k := ImpSorted[i];1795 ImpSorted[ i] := ImpSorted[j];1796 ImpSorted[ j] := k;1778 I, J, K: Integer; 1779 begin 1780 for I := 0 to nImp - 1 do 1781 ImpSorted[I] := I; 1782 for I := 0 to nImp - 2 do 1783 for J := I + 1 to nImp - 1 do 1784 if Prio(ImpSorted[I]) > Prio(ImpSorted[J]) then begin 1785 K := ImpSorted[I]; 1786 ImpSorted[I] := ImpSorted[J]; 1787 ImpSorted[J] := K; 1797 1788 end; 1798 1789 end; -
branches/highdpi/LocalPlayer/CityType.pas
r361 r465 5 5 6 6 uses 7 UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, LCLIntf, LCLType, 8 SysUtils, Classes, Graphics, Controls, Forms, 9 ButtonB, ExtCtrls; 7 UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, 8 SysUtils, Classes, Graphics, Controls, Forms, ButtonB, ExtCtrls; 10 9 11 10 type … … 18 17 procedure FormShow(Sender: TObject); 19 18 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 20 Shift: TShiftState; x, y: integer);19 Shift: TShiftState; X, Y: Integer); 21 20 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 22 Shift: TShiftState; x, y: integer);21 Shift: TShiftState; X, Y: Integer); 23 22 procedure FormClose(Sender: TObject; var Action: TCloseAction); 24 23 procedure DeleteBtnClick(Sender: TObject); 25 24 public 26 procedure ShowNewContent(NewMode: integer);25 procedure ShowNewContent(NewMode: TWindowMode); 27 26 protected 28 27 procedure OffscreenPaint; override; 29 28 private 30 nPool, dragiix, ctype: integer;31 Pooliix: array [0 .. nImp - 1] of integer;29 nPool, dragiix, ctype: Integer; 30 Pooliix: array [0 .. nImp - 1] of Integer; 32 31 listed: Set of 0 .. nImp; 33 Changed: boolean;34 procedure LoadType(NewType: integer);32 Changed: Boolean; 33 procedure LoadType(NewType: Integer); 35 34 procedure SaveType; 36 35 end; 37 36 38 var39 CityTypeDlg: TCityTypeDlg;40 37 41 38 implementation 42 39 43 uses Help; 40 uses 41 Help, Term; 44 42 45 43 {$R *.lfm} … … 82 80 procedure TCityTypeDlg.OffscreenPaint; 83 81 var 84 i, iix: integer;85 s: string;82 I, iix: Integer; 83 S: string; 86 84 begin 87 85 inherited; 88 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);86 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 89 87 FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow); 90 88 FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow); … … 92 90 yPool - yList - 32 * nListRow); 93 91 94 Frame( offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,92 Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255, 95 93 yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 96 Frame( offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,94 Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow, 97 95 InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight, 98 96 MainTexture.ColorBevelShade); 99 Frame( offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,97 Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow, 100 98 InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight, 101 99 MainTexture.ColorBevelShade); 102 Frame( offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,100 Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1, 103 101 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,102 for I := 0 to nCityType - 1 do 103 begin 104 RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42, 107 105 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,106 if I = ctype then 107 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 108 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade, 111 109 MainTexture.ColorBevelLight) 112 110 else 113 Frame( offscreen.Canvas, xSwitch + 1 + i* 42, ySwitch + 1,114 xSwitch + 38 + i* 42, ySwitch + 22, MainTexture.ColorBevelLight,111 Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1, 112 xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight, 115 113 MainTexture.ColorBevelShade); 116 DpiBit Canvas(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,114 DpiBitBltCanvas(Offscreen.Canvas, xSwitch + 2 + I * 42, ySwitch + 2, 115 xSizeSmall, ySizeSmall, SmallImp.Canvas, (I + 3) * xSizeSmall, 0); 116 end; 117 RisedTextOut(Offscreen.Canvas, 8, yList + 32 * nListRow + 2, 120 118 Phrases.Lookup('BUILDORDER')); 121 RisedTextOut( offscreen.Canvas, 8, ySwitch + 26,119 RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26, 122 120 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);121 S := Phrases.Lookup('BUILDREST'); 122 RisedTextOut(Offscreen.Canvas, 123 (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 124 yList + 72 + 32 * nListRow, S); 125 126 with Offscreen.Canvas do 127 begin 128 for I := 1 to nListRow - 1 do 129 DLine(Offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol, 130 yList - 1 + 32 * I, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 131 for I := 0 to nListCol * nListRow - 1 do 132 begin 133 S := IntToStr(I + 1); 136 134 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,135 Textout(xList + 20 + I mod nListCol * 42 - TextWidth(S) div 2, 136 yList + 15 + I div nListCol * 32 - TextHeight(S) div 2, S); 137 end; 138 end; 139 140 I := 0; 141 while MyData.ImpOrder[ctype, I] >= 0 do 142 begin 143 RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol * 144 42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32, 145 xList + 21 + xSizeSmall div 2 + I mod nListCol * 42, 146 yList + 16 + ySizeSmall div 2 + I div nListCol * 32, 149 147 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 150 DpiBit Canvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +151 i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + idiv nListCol * 32,148 DpiBitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 + 149 I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32, 152 150 xSizeSmall, ySizeSmall, SmallImp.Canvas, 153 MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,154 (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *151 MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall, 152 (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 * 155 153 ySizeSmall); 156 inc(i);154 Inc(I); 157 155 end; 158 156 … … 165 163 begin 166 164 Pooliix[nPool] := iix; 167 RFrame( offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +165 RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 + 168 166 nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 + 169 167 nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 + … … 171 169 nPool div nPoolCol * 32, MainTexture.ColorBevelLight, 172 170 MainTexture.ColorBevelShade); 173 DpiBit Canvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +171 DpiBitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 + 174 172 nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 + 175 173 nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas, 176 174 iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 * 177 175 ySizeSmall); 178 inc(nPool);176 Inc(nPool); 179 177 end; 180 178 DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0; … … 182 180 if dragiix >= 0 then 183 181 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);182 ImpImage(Offscreen.Canvas, xView + 9, yView + 5, dragiix); 183 S := Phrases.Lookup('IMPROVEMENTS', dragiix); 184 RisedTextOut(Offscreen.Canvas, 185 xView + 36 - BiColorTextWidth(Offscreen.Canvas, S) div 2, 186 ySwitch + 26, S); 189 187 end; 190 188 MarkUsedOffscreen(InnerWidth, InnerHeight); 191 end; { MainPaint }192 193 procedure TCityTypeDlg.LoadType(NewType: integer);194 var 195 i: integer;189 end; 190 191 procedure TCityTypeDlg.LoadType(NewType: Integer); 192 var 193 I: Integer; 196 194 begin 197 195 ctype := NewType; 198 196 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;197 I := 0; 198 while MyData.ImpOrder[ctype, I] >= 0 do 199 begin 200 Include(listed, MyData.ImpOrder[ctype, I]); 201 Inc(I); 202 end; 203 Changed := False; 206 204 end; 207 205 208 206 procedure TCityTypeDlg.SaveType; 209 207 var 210 cix: integer;208 cix: Integer; 211 209 begin 212 210 if Changed then … … 215 213 if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then 216 214 AutoBuild(cix, MyData.ImpOrder[ctype]); 217 Changed := false;215 Changed := False; 218 216 end; 219 217 end; … … 226 224 end; 227 225 228 procedure TCityTypeDlg.ShowNewContent(NewMode: integer);226 procedure TCityTypeDlg.ShowNewContent(NewMode: TWindowMode); 229 227 begin 230 228 inherited ShowNewContent(NewMode); … … 232 230 233 231 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) then232 Shift: TShiftState; X, Y: Integer); 233 var 234 I: Integer; 235 begin 236 X := X - SideFrame; 237 Y := Y - WideFrame; 238 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 239 if (I < nImp) and (MyData.ImpOrder[ctype, I] >= 0) and 240 (X > xList + 2 + I mod nListCol * 42) and 241 (Y > yList + 5 + I div nListCol * 32) and 242 (X < xList + 3 + 36 + I mod nListCol * 42) and 243 (Y < yList + 6 + 20 + I div nListCol * 32) then 246 244 begin 247 245 if ssShift in Shift then 248 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp,249 MyData.ImpOrder[ctype, i])246 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, 247 MyData.ImpOrder[ctype, I]) 250 248 else 251 249 begin 252 dragiix := MyData.ImpOrder[ctype, i];250 dragiix := MyData.ImpOrder[ctype, I]; 253 251 DpiScreen.Cursor := crImpDrag; 254 252 SmartUpdateContent; 255 253 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) then254 Exit; 255 end; 256 I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol; 257 if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and 258 (Y > yPool + 5 + I div nPoolCol * 32) and 259 (X < xPool + 3 + 36 + I mod nPoolCol * 42) and 260 (Y < yPool + 6 + 20 + I div nPoolCol * 32) then 263 261 begin 264 262 if ssShift in Shift then 265 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Pooliix[i])263 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I]) 266 264 else 267 265 begin 268 dragiix := Pooliix[ i];266 dragiix := Pooliix[I]; 269 267 DpiScreen.Cursor := crImpDrag; 270 268 SmartUpdateContent; 271 269 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)270 Exit; 271 end; 272 I := (X - xSwitch) div 42; 273 if (I < nCityType) and (X > xSwitch + 2 + I * 42) and 274 (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22) 277 275 then 278 276 begin 279 277 SaveType; 280 LoadType( i);278 LoadType(I); 281 279 SmartUpdateContent; 282 280 end; … … 284 282 285 283 procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 286 Shift: TShiftState; x, y: integer);287 288 procedure UnList(iix: integer);284 Shift: TShiftState; X, Y: Integer); 285 286 procedure UnList(iix: Integer); 289 287 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);288 I: Integer; 289 begin 290 I := 0; 291 while (MyData.ImpOrder[ctype, I] >= 0) and 292 (MyData.ImpOrder[ctype, I] <> iix) do 293 Inc(I); 294 Assert(MyData.ImpOrder[ctype, I] = iix); 295 Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I); 298 296 Exclude(listed, iix); 299 297 end; 300 298 301 299 var 302 i: integer;303 begin 304 x := x- SideFrame;305 y := y- WideFrame;300 I: Integer; 301 begin 302 X := X - SideFrame; 303 Y := Y - WideFrame; 306 304 if dragiix >= 0 then 307 305 begin 308 if ( x >= xList) and (x < xList + nListCol * 42) and (y>= yList) and309 ( y< yList + nListRow * 32) then306 if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and 307 (Y < yList + nListRow * 32) then 310 308 begin 311 309 if dragiix in listed then 312 310 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;311 I := (X - xList) div 42 + (Y - yList) div 32 * nListCol; 312 while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do 313 Dec(I); 314 Move(MyData.ImpOrder[ctype, I], MyData.ImpOrder[ctype, I + 1], 315 nImp - I - 1); 316 MyData.ImpOrder[ctype, I] := dragiix; 317 Include(listed, dragiix); 318 Changed := True; 321 319 end 322 else if (dragiix in listed) and ( x >= xPool) and (x< xPool + nPoolCol * 42)323 and ( y >= yPool) and (y< yPool + nPoolRow * 32) then320 else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42) 321 and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then 324 322 begin 325 323 UnList(dragiix); 326 Changed := true;324 Changed := True; 327 325 end; 328 326 dragiix := -1; … … 340 338 procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject); 341 339 begin 342 fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));340 FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1)); 343 341 listed := []; 344 Changed := true;342 Changed := True; 345 343 SmartUpdateContent; 346 344 end; -
branches/highdpi/LocalPlayer/ClientTools.pas
r405 r465 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; … … 316 316 UnitInfo := MyRO.EnemyUn[uix]; 317 317 end; 318 end; { GetUnitInfo }319 320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);318 end; 319 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-} -
branches/highdpi/LocalPlayer/Diagram.pas
r361 r465 9 9 10 10 type 11 TDiagramKind = (dkChart, dkShip); 12 11 13 TDiaDlg = class(TFramedDlg) 12 14 CloseBtn: TButtonB; … … 19 21 procedure ToggleBtnClick(Sender: TObject); 20 22 procedure PlayerClick(Sender: TObject); 21 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState); 22 23 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 23 24 public 24 25 procedure OffscreenPaint; override; 25 procedure ShowNewContent_Charts(NewMode: integer); 26 procedure ShowNewContent_Ship(NewMode: integer; p: integer = -1); 27 26 procedure ShowNewContent_Charts(NewMode: TWindowMode); 27 procedure ShowNewContent_Ship(NewMode: TWindowMode; P: Integer = -1); 28 28 private 29 Kind: (dkChart, dkShip); 30 Player, Mode: integer; 31 end; 32 33 var 34 DiaDlg: TDiaDlg; 35 36 procedure PaintColonyShip(canvas: TDpiCanvas; Player, Left, Width, Top: integer); 29 Kind: TDiagramKind; 30 Player: Integer; 31 Mode: Integer; 32 end; 33 34 procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer); 35 37 36 38 37 implementation … … 45 44 const 46 45 Border = 24; 47 RoundPixels: array [0 .. nStat - 1] of integer = (0, 0, 0, 5, 5, 5);46 RoundPixels: array [0 .. nStat - 1] of Integer = (0, 0, 0, 5, 5, 5); 48 47 49 48 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: TDpiCanvas; Player, Left, Width, Top: integer);49 xComp: array [0 .. 5] of Integer = (-60, -28, 4, 4, 36, 68); 50 yComp: array [0 .. 5] of Integer = (-40, -40, -79, -1, -40, -40); 51 xPow: array [0 .. 3] of Integer = (-116, -116, -116, -116); 52 yPow: array [0 .. 3] of Integer = (-28, 0, -44, 16); 53 xHab: array [0 .. 1] of Integer = (23, 23); 54 yHab: array [0 .. 1] of Integer = (-81, 1); 55 56 procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer); 58 57 var 59 i, x, r, nComp, nPow, nHab: integer;58 I, X, R, nComp, nPow, nHab: Integer; 60 59 begin 61 60 Canvas.Brush.Color := $000000; 62 61 Canvas.FillRect(Rect(Left, Top, Left + Width, Top + 200)); 63 62 Canvas.Brush.Style := bsClear; 64 ScreenTools.Frame( canvas, Left - 1, Top - 1, Left + Width, Top + 200,63 ScreenTools.Frame(Canvas, Left - 1, Top - 1, Left + Width, Top + 200, 65 64 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 66 RFrame( canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,65 RFrame(Canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1, 67 66 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 68 67 69 68 // stars 70 69 DelphiRandSeed := Player * 11111; 71 for i:= 1 to Width - 16 do70 for I := 1 to Width - 16 do 72 71 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;72 X := DelphiRandom((Width - 16) * 200); 73 R := DelphiRandom(13) + 28; 74 Canvas.Pixels[X div 200 + 8, X mod 200 + Top] := 75 (R * R * R * R div 10001) * $10101; 77 76 end; 78 77 … … 86 85 if nHab > 2 then 87 86 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);87 for I := 0 to nHab - 1 do 88 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xHab[I], 89 Top + 100 + yHab[I], 80, 80, 34, 1); 90 for I := 0 to nComp - 1 do 91 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[I], 92 Top + 100 + yComp[I], 32, 80, 1, 1); 94 93 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);94 for I := 3 downto nPow do 95 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I] + 40, 96 Top + 100 + yPow[I], 16, 27, 1, 82); 97 for I := nPow - 1 downto 0 do 98 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I], 99 Top + 100 + yPow[I], 56, 28, 58, 82); 101 100 if (nComp < 3) and (nHab >= 1) then 102 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,101 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16, 103 102 Top + 100 + 7 + yComp[2], 16, 27, 1, 82); 104 103 if (nComp >= 3) and (nHab < 1) then 105 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,104 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32, 106 105 Top + 100 + 7 + yComp[2], 16, 27, 18, 82); 107 106 if (nComp < 4) and (nHab >= 2) then 108 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,107 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16, 109 108 Top + 100 + 46 + yComp[3], 16, 27, 1, 82); 110 109 if (nComp >= 4) and (nHab < 2) then 111 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,110 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32, 112 111 Top + 100 + 46 + yComp[3], 16, 27, 18, 82); 113 112 if (nComp <> 6) and (nComp <> 2) and not((nComp = 0) and (nPow < 1)) then 114 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],113 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp], 115 114 Top + 100 + 7 + yComp[nComp], 16, 27, 18, 82); 116 115 if (nComp <> 6) and (nComp <> 3) and not((nComp = 0) and (nPow < 2)) then 117 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],116 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp], 118 117 Top + 100 + 46 + yComp[nComp], 16, 27, 18, 82); 119 118 if nComp = 2 then 120 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[3],119 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3], 121 120 Top + 100 + 7 + yComp[3], 16, 27, 18, 82); 122 121 if nComp = 3 then 123 Sprite( canvas, HGrSystem2, Left + Width div 2 + xComp[4],122 Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[4], 124 123 Top + 100 + 7 + yComp[4], 16, 27, 18, 82); 125 124 end; … … 142 141 procedure TDiaDlg.OffscreenPaint; 143 142 var 144 p, T, max, x, y, y0, Stop, r, RoundRange, LineStep: integer;145 s: string;143 P, T, Max, X, Y, y0, Stop, R, RoundRange, LineStep: Integer; 144 S: string; 146 145 List: ^TChart; 147 146 148 function Round(T: integer): integer;147 function Round(T: Integer): Integer; 149 148 var 150 n, i: integer;149 N, I: Integer; 151 150 begin 152 151 if T < RoundRange then 153 n:= T152 N := T 154 153 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,154 N := RoundRange; 155 Result := 0; 156 for I := T - N to T do 157 Inc(Result, List[I]); 158 Result := Result div (N + 1); 159 end; 160 161 procedure ShareBar(X, Y: Integer; Cap: string; val0, val1: Integer); 162 begin 163 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, X - 2, Y, Cap); 164 DLine(Offscreen.Canvas, X - 2, X + 169, Y + 16, MainTexture.ColorTextShade, 166 165 MainTexture.ColorTextLight); 167 166 if val0 > 0 then 168 s:= Format(Phrases.Lookup('SHARE'), [val0, val1])167 S := Format(Phrases.Lookup('SHARE'), [val0, val1]) 169 168 else 170 s:= '0';171 RisedTextOut( offscreen.canvas,172 x + 170 - BiColorTextWidth(offscreen.canvas, s), y, s);169 S := '0'; 170 RisedTextOut(Offscreen.Canvas, 171 X + 170 - BiColorTextWidth(Offscreen.Canvas, S), Y, S); 173 172 end; 174 173 … … 176 175 inherited; 177 176 if Kind = dkChart then 178 with offscreen.canvas do177 with Offscreen.Canvas do 179 178 begin 180 179 Font.Assign(UniFont[ftTiny]); … … 186 185 GetMem(List, 4 * (MyRO.Turn + 2)); 187 186 if Mode = stExplore then 188 max := G.lx * G.ly187 Max := G.lx * G.ly 189 188 else 190 189 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) then190 Max := -1; 191 for P := 0 to nPl - 1 do 192 if (G.Difficulty[P] > 0) and 193 (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then 195 194 for T := 0 to MyRO.Turn - 1 do 196 195 begin 197 r:= Round(T);198 if r > max then199 max := r;196 R := Round(T); 197 if R > Max then 198 Max := R; 200 199 end; 201 200 end; … … 215 214 for T := 0 to (MyRO.Turn - 1) div LineStep do 216 215 begin 217 x:= Border + (InnerWidth - 2 * Border) * T *216 X := Border + (InnerWidth - 2 * Border) * T * 218 217 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);218 MoveTo(X, Border); 219 LineTo(X, InnerHeight - Border); 220 S := IntToStr(abs(TurnToYear(T * LineStep))); 221 Textout(X - TextWidth(S) div 2, Border - 16, S); 223 222 end; 224 223 225 224 y0 := 0; 226 if max > 0 then225 if Max > 0 then 227 226 begin 228 for p:= 0 to nPl - 1 do229 if (G.Difficulty[ p] > 0) and230 (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then227 for P := 0 to nPl - 1 do 228 if (G.Difficulty[P] > 0) and 229 (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then 231 230 begin 232 Pen.Color := Tribe[ p].Color;231 Pen.Color := Tribe[P].Color; 233 232 Stop := MyRO.Turn - 1; 234 233 while (Stop > 0) and (List[Stop] = 0) do 235 dec(Stop);234 Dec(Stop); 236 235 for T := 0 to Stop do 237 236 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;237 R := Round(T); 238 X := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1); 239 Y := InnerHeight - Border - (InnerHeight - 2 * Border) * 240 R div Max; 242 241 if T = 0 then 243 MoveTo( x, y)242 MoveTo(X, Y) 244 243 // else if Mode=stTerritory then 245 244 // begin LineTo(x,y0); LineTo(x,y) end 246 245 else if RoundPixels[Mode] = 0 then 247 246 begin 248 if ( y<> y0) or (T = Stop) then249 LineTo( x, y)247 if (Y <> y0) or (T = Stop) then 248 LineTo(X, Y) 250 249 end 251 250 else 252 LineTo( x, y);253 y0 := y;251 LineTo(X, Y); 252 y0 := Y; 254 253 end; 255 254 end; … … 258 257 end 259 258 else 260 with offscreen.canvas do259 with Offscreen.Canvas do 261 260 begin 262 261 Font.Assign(UniFont[ftSmall]); 263 262 FillOffscreen(0, 0, InnerWidth, InnerHeight); 264 263 265 PaintColonyShip( offscreen.canvas, Player, 8, InnerWidth - 16, yArea);264 PaintColonyShip(Offscreen.Canvas, Player, 8, InnerWidth - 16, yArea); 266 265 267 266 ShareBar(InnerWidth div 2 - 85, InnerHeight - 62, … … 273 272 end; 274 273 MarkUsedOffscreen(InnerWidth, InnerHeight); 275 end; // OffscreenPaint274 end; 276 275 277 276 procedure TDiaDlg.FormPaint(Sender: TObject); 278 277 var 279 s: string;278 S: string; 280 279 begin 281 280 inherited; 282 canvas.Font.Assign(UniFont[ftNormal]);281 Canvas.Font.Assign(UniFont[ftNormal]); 283 282 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);283 S := Phrases.Lookup('DIAGRAM', Mode) 284 else 285 S := Tribe[Player].TPhrase('SHORTNAME'); 286 LoweredTextOut(Canvas, -1, MainTexture, 287 (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S); 289 288 end; 290 289 … … 299 298 end; 300 299 301 procedure TDiaDlg.ShowNewContent_Charts(NewMode: integer);300 procedure TDiaDlg.ShowNewContent_Charts(NewMode: TWindowMode); 302 301 begin 303 302 Kind := dkChart; … … 309 308 end; 310 309 311 procedure TDiaDlg.ShowNewContent_Ship(NewMode , p: integer);310 procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; P: Integer); 312 311 begin 313 312 Kind := dkShip; 314 if p< 0 then315 begin 316 Player := me;313 if P < 0 then 314 begin 315 Player := Me; 317 316 while MyRO.Ship[Player].Parts[spComp] + MyRO.Ship[Player].Parts[spPow] + 318 317 MyRO.Ship[Player].Parts[spHab] = 0 do … … 320 319 end 321 320 else 322 Player := p;321 Player := P; 323 322 ToggleBtn.ButtonIndex := 28; 324 323 ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT'); … … 329 328 procedure TDiaDlg.ToggleBtnClick(Sender: TObject); 330 329 var 331 p1: integer;332 m: TDpiMenuItem;330 p1: Integer; 331 M: TDpiMenuItem; 333 332 begin 334 333 if Kind = dkChart then … … 345 344 MyRO.Ship[p1].Parts[spHab] > 0 then 346 345 begin 347 m:= TDpiMenuItem.Create(Popup);348 m.RadioItem := true;349 m.Caption := Tribe[p1].TPhrase('SHORTNAME');350 m.Tag := p1;351 m.OnClick := PlayerClick;346 M := TDpiMenuItem.Create(Popup); 347 M.RadioItem := True; 348 M.Caption := Tribe[p1].TPhrase('SHORTNAME'); 349 M.Tag := p1; 350 M.OnClick := PlayerClick; 352 351 if p1 = Player then 353 m.Checked := true;354 Popup.Items.Add( m);352 M.Checked := True; 353 Popup.Items.Add(M); 355 354 end; 356 355 Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height); … … 363 362 end; 364 363 365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: word;364 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: Word; 366 365 Shift: TShiftState); 367 366 begin -
branches/highdpi/LocalPlayer/Diplomacy.pas
r210 r465 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 -
branches/highdpi/LocalPlayer/Draft.pas
r361 r465 5 5 6 6 uses 7 UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, 8 9 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, 10 ButtonA, 11 ButtonB, Area; 7 UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils, 8 Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA, ButtonB, Area; 12 9 13 10 type … … 23 20 procedure CloseBtnClick(Sender: TObject); 24 21 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 25 Shift: TShiftState; x, y: integer);22 Shift: TShiftState; X, Y: Integer); 26 23 procedure OKBtnClick(Sender: TObject); 27 24 procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 28 Shift: TShiftState; x, y: integer);25 Shift: TShiftState; X, Y: Integer); 29 26 public 30 procedure ShowNewContent(NewMode: integer);27 procedure ShowNewContent(NewMode: TWindowMode); 31 28 protected 32 29 procedure OffscreenPaint; override; 33 30 private 34 31 Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView, 35 IncCap, DecCap: integer;36 code: array [0 .. nFeature - 1] of integer;32 IncCap, DecCap: Integer; 33 Code: array [0 .. nFeature - 1] of Integer; 37 34 Template, Back: TDpiBitmap; 38 function IsFeatureInList(d, i: integer): boolean; 39 procedure SetDomain(d: integer); 40 end; 41 42 var 43 DraftDlg: TDraftDlg; 35 function IsFeatureInList(D, I: Integer): Boolean; 36 procedure SetDomain(D: Integer); 37 end; 38 44 39 45 40 implementation 46 41 47 uses Help, Tribes, Directories; 42 uses 43 Term, Help, Tribes, Directories; 48 44 49 45 {$R *.lfm} … … 109 105 procedure TDraftDlg.OffscreenPaint; 110 106 111 function DomainAvailable( d: integer): boolean;112 begin 113 result := (upgrade[d, 0].Preq = preNone) or114 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable);107 function DomainAvailable(D: Integer): Boolean; 108 begin 109 Result := (upgrade[D, 0].Preq = preNone) or 110 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable); 115 111 end; 116 112 117 113 procedure PaintTotalBars; 118 114 var 119 i, y, dx, num, w: integer;120 s: string;121 begin 122 with offscreen.Canvas do115 I, Y, dx, num, W: Integer; 116 S: string; 117 begin 118 with Offscreen.Canvas do 123 119 begin 124 120 // strength bar 125 y:= yTotal;126 DarkGradient( offscreen.Canvas, xTotal - 6, y+ 1, 184, 2);127 DarkGradient( offscreen.Canvas, xTotal2 + 172, y+ 1, 95, 2);128 RisedTextOut( offscreen.Canvas, xTotal - 2, y,121 Y := yTotal; 122 DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2); 123 DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2); 124 RisedTextOut(Offscreen.Canvas, xTotal - 2, Y, 129 125 Phrases.Lookup('UNITSTRENGTH')); 130 RisedTextOut( offscreen.Canvas, xTotal + 112 + 30, y,126 RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y, 131 127 'x' + IntToStr(MyRO.DevModel.MStrength)); 132 RisedTextOut( offscreen.Canvas, xTotal2 + 148 + 30, y, '=');133 s:= IntToStr(MyRO.DevModel.Attack) + '/' +128 RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '='); 129 S := IntToStr(MyRO.DevModel.Attack) + '/' + 134 130 IntToStr(MyRO.DevModel.Defense); 135 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 -136 BiColorTextWidth( offscreen.Canvas, s), y, s);131 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 132 BiColorTextWidth(Offscreen.Canvas, S), Y, S); 137 133 138 134 // transport bar 139 135 if MyRO.DevModel.MTrans > 0 then 140 136 begin 141 y:= yTotal + 19;142 DarkGradient( offscreen.Canvas, xTotal - 6, y+ 1, 184, 1);143 DarkGradient( offscreen.Canvas, xTotal2 + 172, y+ 1, 95, 1);144 RisedTextOut( offscreen.Canvas, xTotal - 2, y,137 Y := yTotal + 19; 138 DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1); 139 DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1); 140 RisedTextOut(Offscreen.Canvas, xTotal - 2, Y, 145 141 Phrases.Lookup('UNITTRANSPORT')); 146 RisedTextOut( offscreen.Canvas, xTotal + 112 + 30, y,142 RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y, 147 143 'x' + IntToStr(MyRO.DevModel.MTrans)); 148 RisedTextOut( offscreen.Canvas, xTotal2 + 148 + 30, y, '=');144 RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '='); 149 145 150 146 Font.Color := $000000; 151 147 dx := -237 - 30; 152 for i:= mcFirstNonCap - 1 downto 3 do153 if iin [mcSeaTrans, mcCarrier, mcAirTrans] then148 for I := mcFirstNonCap - 1 downto 3 do 149 if I in [mcSeaTrans, mcCarrier, mcAirTrans] then 154 150 begin 155 num := MyRO.DevModel.Cap[ i] * MyRO.DevModel.MTrans;151 num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans; 156 152 if num > 0 then 157 153 begin 158 inc(dx, 15);154 Inc(dx, 15); 159 155 Brush.Color := $C0C0C0; 160 FrameRect(Rect(xTotal2 - 3 - dx, y+ 2,161 xTotal2 + 11 - dx, y+ 16));156 FrameRect(Rect(xTotal2 - 3 - dx, Y + 2, 157 xTotal2 + 11 - dx, Y + 16)); 162 158 Brush.Style := bsClear; 163 Sprite( offscreen, HGrSystem, xTotal2 - 1 - dx, y+ 4, 10, 10,164 66 + i mod 11 * 11, 137 + idiv 11 * 11);159 Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10, 160 66 + I mod 11 * 11, 137 + I div 11 * 11); 165 161 if num > 1 then 166 162 begin 167 s:= IntToStr(num);168 w := TextWidth(s);169 inc(dx, w+ 1);163 S := IntToStr(num); 164 W := TextWidth(S); 165 Inc(dx, W + 1); 170 166 Brush.Color := $FFFFFF; 171 FillRect(Rect(xTotal2 - 3 - dx, y+ 2,172 xTotal2 + w - 1 - dx, y+ 16));167 FillRect(Rect(xTotal2 - 3 - dx, Y + 2, 168 xTotal2 + W - 1 - dx, Y + 16)); 173 169 Brush.Style := bsClear; 174 Textout(xTotal2 - 3 - dx + 1, y, s);170 Textout(xTotal2 - 3 - dx + 1, Y, S); 175 171 end; 176 172 end; 177 end 173 end; 178 174 end; 179 175 180 176 // speed bar 181 y:= yTotal + 38;182 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,177 Y := yTotal + 38; 178 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 183 179 Phrases.Lookup('UNITSPEED')); 184 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,180 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 185 181 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 186 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,182 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 187 183 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 188 s:= MovementToString(MyRO.DevModel.Speed);189 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 -190 TextWidth( s), y, s);184 S := MovementToString(MyRO.DevModel.Speed); 185 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 186 TextWidth(S), Y, S); 191 187 192 188 // cost bar 193 y:= yTotal + 57;194 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,189 Y := yTotal + 57; 190 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 195 191 Phrases.Lookup('UNITCOST')); 196 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,192 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y, 197 193 'x' + IntToStr(MyRO.DevModel.MCost)); 198 LoweredTextOut( offscreen.Canvas, -1, MainTexture,199 xTotal2 + 148 + 30, y, '=');200 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,194 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 195 xTotal2 + 148 + 30, Y, '='); 196 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 201 197 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 202 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,198 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 203 199 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 204 s:= IntToStr(MyRO.DevModel.Cost);205 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -206 TextWidth( s), y, s);207 Sprite( offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y+ 4, 10,200 S := IntToStr(MyRO.DevModel.Cost); 201 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 - 202 TextWidth(S), Y, S); 203 Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10, 208 204 10, 88, 115); 209 205 210 if G.Difficulty[ me] <> 2 then206 if G.Difficulty[Me] <> 2 then 211 207 begin // corrected cost bar 212 y:= yTotal + 76;213 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xTotal - 2, y,214 Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[ me])));215 LoweredTextOut( offscreen.Canvas, -1, MainTexture,216 xTotal2 + 148 + 30, y, '=');217 DLine( offscreen.Canvas, xTotal - 2, xTotal + 174, y+ 16,208 Y := yTotal + 76; 209 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y, 210 Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me]))); 211 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 212 xTotal2 + 148 + 30, Y, '='); 213 DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16, 218 214 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 219 DLine( offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y+ 16,215 DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16, 220 216 MainTexture.ColorBevelShade, MainTexture.ColorBevelLight); 221 s:= IntToStr(MyRO.DevModel.Cost * BuildCostMod222 [G.Difficulty[ me]] div 12);223 RisedTextOut( offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -224 TextWidth( s), y, s);225 Sprite( offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y+ 4, 10,217 S := IntToStr(MyRO.DevModel.Cost * BuildCostMod 218 [G.Difficulty[Me]] div 12); 219 RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 - 220 TextWidth(S), Y, S); 221 Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10, 226 222 10, 88, 115); 227 223 end; … … 230 226 231 227 var 232 i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;228 I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer; 233 229 begin 234 230 inherited; … … 239 235 // assemble background from 2 texture tiles 240 236 begin 241 DpiBit Canvas(Back.Canvas, 0, 0, ClientWidth, 64,237 DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, 64, 242 238 MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2, 243 239 MainTexture.Height - 64); 244 DpiBit Canvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,240 DpiBitBltCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64, 245 241 MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2, 246 242 0); 247 243 end 248 244 else 249 DpiBit Canvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,245 DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight, 250 246 MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2, 251 247 (MainTexture.Height - ClientHeight) div 2); … … 254 250 Template.Height - 64 - Cut); 255 251 256 DpiBit Canvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,252 DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight, 257 253 Back.Canvas, 0, 0); 258 254 259 offscreen.Canvas.Font.Assign(UniFont[ftCaption]);260 RisedTextOut( offscreen.Canvas, 10, 7, Caption);261 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);255 Offscreen.Canvas.Font.Assign(UniFont[ftCaption]); 256 RisedTextOut(Offscreen.Canvas, 10, 7, Caption); 257 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 262 258 263 259 with MyRO.DevModel do 264 260 begin 265 261 DomainCount := 0; 266 for d:= 0 to nDomains - 1 do267 if DomainAvailable( d) then268 inc(DomainCount);262 for D := 0 to nDomains - 1 do 263 if DomainAvailable(D) then 264 Inc(DomainCount); 269 265 if DomainCount > 1 then 270 266 begin 271 for d:= 0 to nDomains - 1 do272 if DomainAvailable( d) then267 for D := 0 to nDomains - 1 do 268 if DomainAvailable(D) then 273 269 begin 274 x := xDomain + d* DomainPitch;275 if d= Domain then276 ImageOp_BCC( offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,270 X := xDomain + D * DomainPitch; 271 if D = Domain then 272 ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36, 277 273 36, 0, $00C0FF) 278 274 else 279 ImageOp_BCC( offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,275 ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36, 280 276 36, 0, $606060); 281 277 end; 282 Frame( offscreen.Canvas, xDomain - 11, yDomain - 3,278 Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3, 283 279 xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF); 284 RFrame( offscreen.Canvas, xDomain - 12, yDomain - 4,280 RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4, 285 281 xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0); 286 282 end; … … 295 291 296 292 // display weight 297 with offscreen.Canvas do298 begin 299 for i:= 0 to MaxWeight - 1 do300 if i< Weight then301 ImageOp_BCC( offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),293 with Offscreen.Canvas do 294 begin 295 for I := 0 to MaxWeight - 1 do 296 if I < Weight then 297 ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight), 302 298 WeightOn.BoundsRect, 0, $949494) 303 299 else 304 ImageOp_BCC( offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),300 ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight), 305 301 WeightOff.BoundsRect, 0, $949494); 306 302 end; 307 303 308 with offscreen.Canvas do309 for i:= 0 to Lines - 1 do304 with Offscreen.Canvas do 305 for I := 0 to Lines - 1 do 310 306 begin 311 if not( code[i] in AutoFeature) then307 if not(Code[I] in AutoFeature) then 312 308 begin 313 309 // paint +/- butttons 314 if code[i] < mcFirstNonCap then310 if Code[I] < mcFirstNonCap then 315 311 begin 316 Dump( offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *317 i, 12, 12, 169, 172);318 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *319 i, 12, 12, 169, 159);320 RFrame( offscreen.Canvas, xFeature - (21 + 1),321 yFeature + 2 + LinePitch * i- 1, xFeature - (21 - 24),322 yFeature + 2 + LinePitch * i+ 12, MainTexture.ColorBevelShade,312 Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch * 313 I, 12, 12, 169, 172); 314 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 315 I, 12, 12, 169, 159); 316 RFrame(Offscreen.Canvas, xFeature - (21 + 1), 317 yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24), 318 yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade, 323 319 MainTexture.ColorBevelLight); 324 320 end 325 321 else 326 322 begin 327 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *328 i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);329 RFrame( offscreen.Canvas, xFeature - (9 + 1),330 yFeature + 2 + LinePitch * i- 1, xFeature - (21 - 24),331 yFeature + 2 + LinePitch * i+ 12, MainTexture.ColorBevelShade,323 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 324 I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]); 325 RFrame(Offscreen.Canvas, xFeature - (9 + 1), 326 yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24), 327 yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade, 332 328 MainTexture.ColorBevelLight); 333 329 end; 334 330 335 331 // paint cost 336 LightGradient( offscreen.Canvas, xFeature + 34,337 yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels332 LightGradient(Offscreen.Canvas, xFeature + 34, 333 yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels 338 334 [187, 137]); 339 if (Domain = dGround) and ( code[i] = mcDefense) then335 if (Domain = dGround) and (Code[I] = mcDefense) then 340 336 CapWeight := 2 341 337 else 342 CapWeight := Feature[ code[i]].Weight;343 n := CapWeight + Feature[code[i]].Cost;344 d:= 6;345 while ( n - 1) * d* 2 > 48 - 10 do346 dec(d);347 for j := 0 to n- 1 do348 if j< CapWeight then349 Sprite( offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,350 yFeature + 2 + LinePitch * i+ 1, 10, 10, 88, 126)338 CapWeight := Feature[Code[I]].Weight; 339 N := CapWeight + Feature[Code[I]].Cost; 340 D := 6; 341 while (N - 1) * D * 2 > 48 - 10 do 342 Dec(D); 343 for J := 0 to N - 1 do 344 if J < CapWeight then 345 Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D, 346 yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126) 351 347 else 352 Sprite( offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,353 yFeature + 2 + LinePitch * i+ 1, 10, 10, 88, 115);348 Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D, 349 yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115); 354 350 end; // if not (code[i] in AutoFeature) 355 DarkGradient( offscreen.Canvas, xFeature + 17,356 yFeature + LinePitch * i, 16, 1);357 ScreenTools.Frame( offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,358 xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,351 DarkGradient(Offscreen.Canvas, xFeature + 17, 352 yFeature + LinePitch * I, 16, 1); 353 ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I, 354 xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I, 359 355 $C0C0C0, $C0C0C0); 360 Sprite( offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch361 * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);362 363 if MyRO.DevModel.Cap[ code[i]] > 0 then356 Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch 357 * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11); 358 359 if MyRO.DevModel.Cap[Code[I]] > 0 then 364 360 TextColor := MainTexture.ColorLitText 365 361 else 366 362 TextColor := -1; 367 363 368 if code[i] < mcFirstNonCap then369 LoweredTextOut( offscreen.Canvas, TextColor, MainTexture, xFeature + 7,370 yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));371 LoweredTextOut( offscreen.Canvas, TextColor, MainTexture, xFeature + 88,372 yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));364 if Code[I] < mcFirstNonCap then 365 LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7, 366 yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]])); 367 LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88, 368 yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I])); 373 369 end; 374 370 end; 375 371 376 372 // free features 377 j:= 0;378 for i:= 0 to nFeature - 1 do379 if ( i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and380 (Feature[ i].Preq <> preNA) and381 ((Feature[ i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)382 or (Feature[ i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)383 ) and not((Feature[ i].Preq = adSteamEngine) and373 J := 0; 374 for I := 0 to nFeature - 1 do 375 if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and 376 (Feature[I].Preq <> preNA) and 377 ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me) 378 or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable) 379 ) and not((Feature[I].Preq = adSteamEngine) and 384 380 (MyRO.Tech[adNuclearPower] >= tsApplicable)) then 385 381 begin 386 DarkGradient( offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch387 * j, 16, 1);388 Frame( offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,389 xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);390 Sprite( offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,391 10, 10, 66 + i mod 11 * 11, 137 + idiv 11 * 11);392 LoweredTextOut( offscreen.Canvas, -1, MainTexture, xWeight + 26,393 yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));394 inc(j);395 end; 396 397 with Tribe[ me].ModelPicture[MyRO.nModel] do398 begin 399 FrameImage( offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,382 DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch 383 * J, 16, 1); 384 Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J, 385 xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0); 386 Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J, 387 10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11); 388 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26, 389 yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I)); 390 Inc(J); 391 end; 392 393 with Tribe[Me].ModelPicture[MyRO.nModel] do 394 begin 395 FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig, 400 396 ySizeBig, 0, 0); 401 Sprite( offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,397 Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1, 402 398 pix div 10 * 49 + 1); 403 399 end; 404 400 MarkUsedOffscreen(ClientWidth, ClientHeight); 405 end; { MainPaint }406 407 procedure TDraftDlg.SetDomain( d: integer);408 409 function Prio(fix: integer): integer;401 end; 402 403 procedure TDraftDlg.SetDomain(D: Integer); 404 405 function Prio(fix: Integer): Integer; 410 406 var 411 FeaturePreq: integer;407 FeaturePreq: Integer; 412 408 begin 413 409 FeaturePreq := Feature[fix].Preq; 414 assert(FeaturePreq <> preNA);410 Assert(FeaturePreq <> preNA); 415 411 if fix < mcFirstNonCap then 416 result := 10000 + fix412 Result := 10000 + fix 417 413 else if FeaturePreq = preNone then 418 result := 20000414 Result := 20000 419 415 else if FeaturePreq < 0 then 420 result := 40000416 Result := 40000 421 417 else 422 result := 30000 + AdvValue[FeaturePreq];418 Result := 30000 + AdvValue[FeaturePreq]; 423 419 if not(fix in AutoFeature) then 424 inc(result, 90000);420 Inc(Result, 90000); 425 421 end; 426 422 427 423 var 428 i, j, x: integer;429 begin 430 Domain := d;424 I, J, X: Integer; 425 begin 426 Domain := D; 431 427 Lines := 0; 432 for i:= 0 to nFeature - 1 do433 if IsFeatureInList(Domain, i) then434 begin 435 code[Lines] := i;436 inc(Lines)428 for I := 0 to nFeature - 1 do 429 if IsFeatureInList(Domain, I) then 430 begin 431 Code[Lines] := I; 432 Inc(Lines); 437 433 end; 438 434 yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2; 439 435 440 436 // sort features 441 for i:= 0 to Lines - 2 do442 for j := i+ 1 to Lines - 1 do443 if Prio( code[i]) > Prio(code[j]) then437 for I := 0 to Lines - 2 do 438 for J := I + 1 to Lines - 1 do 439 if Prio(Code[I]) > Prio(Code[J]) then 444 440 begin // exchange 445 x := code[i];446 code[i] := code[j];447 code[j] := x441 X := Code[I]; 442 Code[I] := Code[J]; 443 Code[J] := X; 448 444 end; 449 445 end; 450 446 451 function TDraftDlg.IsFeatureInList( d, i: integer): boolean;452 begin 453 result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and454 (Feature[ i].Preq <> preNA) and455 ((Feature[ i].Preq = preNone) or (Feature[i].Preq = preSun) and456 (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and457 (MyRO.Tech[Feature[ i].Preq] >= tsApplicable));447 function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean; 448 begin 449 Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and 450 (Feature[I].Preq <> preNA) and 451 ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and 452 (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and 453 (MyRO.Tech[Feature[I].Preq] >= tsApplicable)); 458 454 end; 459 455 460 456 procedure TDraftDlg.FormShow(Sender: TObject); 461 457 var 462 count, d, i: integer;458 count, D, I: Integer; 463 459 begin 464 460 Domain := dGround; 465 461 while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and 466 462 (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do 467 inc(Domain);463 Inc(Domain); 468 464 469 465 // count max number of features in any domain 470 466 MaxLines := 0; 471 for d:= 0 to nDomains - 1 do472 if (upgrade[ d, 0].Preq = preNone) or473 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable) then467 for D := 0 to nDomains - 1 do 468 if (upgrade[D, 0].Preq = preNone) or 469 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then 474 470 begin 475 471 count := 0; 476 for i:= 0 to nFeature - 1 do477 if IsFeatureInList( d, i) then478 inc(count);472 for I := 0 to nFeature - 1 do 473 if IsFeatureInList(D, I) then 474 Inc(count); 479 475 if count > MaxLines then 480 476 MaxLines := count; … … 494 490 495 491 SetDomain(Domain); 496 Server(sCreateDevModel, me, Domain, nil^);492 Server(sCreateDevModel, Me, Domain, nil^); 497 493 MyModel[MyRO.nModel] := MyRO.DevModel; 498 InitMyModel(MyRO.nModel, false);494 InitMyModel(MyRO.nModel, False); 499 495 OffscreenPaint; 500 496 IncCap := -1; … … 502 498 end; 503 499 504 procedure TDraftDlg.ShowNewContent(NewMode: integer);500 procedure TDraftDlg.ShowNewContent(NewMode: TWindowMode); 505 501 begin 506 502 inherited ShowNewContent(NewMode); … … 508 504 509 505 procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 510 Shift: TShiftState; x, y: integer);506 Shift: TShiftState; X, Y: Integer); 511 507 var 512 i, d: integer;508 I, D: Integer; 513 509 begin 514 510 if Button = mbLeft then 515 511 begin 516 for d:= 0 to nDomains - 1 do517 if ( d <> Domain) and ((upgrade[d, 0].Preq = preNone) or518 (MyRO.Tech[upgrade[ d, 0].Preq] >= tsApplicable)) and519 ( x >= xDomain + d* DomainPitch) and520 ( x < xDomain + d * DomainPitch + 36) and (y>= yDomain) and521 ( y< yDomain + 36) then512 for D := 0 to nDomains - 1 do 513 if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or 514 (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and 515 (X >= xDomain + D * DomainPitch) and 516 (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and 517 (Y < yDomain + 36) then 522 518 begin 523 SetDomain( d);524 Server(sCreateDevModel, me, Domain, nil^);519 SetDomain(D); 520 Server(sCreateDevModel, Me, Domain, nil^); 525 521 MyModel[MyRO.nModel] := MyRO.DevModel; 526 InitMyModel(MyRO.nModel, false);522 InitMyModel(MyRO.nModel, False); 527 523 SmartUpdateContent; 528 524 end; 529 525 530 if ( y >= yFeature) and (y< yFeature + LinePitch * Lines) then531 begin 532 i := (y- yFeature) div LinePitch;533 if ( x >= xFeature - 21) and (x< ClientWidth) and (ssShift in Shift) then534 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkFeature, code[i])535 else if not( code[i] in AutoFeature) then526 if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then 527 begin 528 I := (Y - yFeature) div LinePitch; 529 if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then 530 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I]) 531 else if not(Code[I] in AutoFeature) then 536 532 begin 537 if ( code[i] < mcFirstNonCap) and (x>= xFeature - 21) and538 ( x< xFeature - 21 + 12) then533 if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and 534 (X < xFeature - 21 + 12) then 539 535 begin 540 IncCap := code[i];541 Dump( offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *542 i, 12, 12, 182, 172);536 IncCap := Code[I]; 537 Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch * 538 I, 12, 12, 182, 172); 543 539 SmartInvalidate; 544 540 end 545 else if ( x >= xFeature - 9) and (x< xFeature - 9 + 12) then541 else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then 546 542 begin 547 DecCap := code[i];548 if code[i] < mcFirstNonCap then549 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *550 i, 12, 12, 182, 159)543 DecCap := Code[I]; 544 if Code[I] < mcFirstNonCap then 545 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 546 I, 12, 12, 182, 159) 551 547 else 552 Dump( offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *553 i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);548 Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch * 549 I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]); 554 550 SmartInvalidate; 555 551 end; 556 end 557 end 558 end 552 end; 553 end; 554 end; 559 555 end; 560 556 561 557 procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton; 562 Shift: TShiftState; x, y: integer);558 Shift: TShiftState; X, Y: Integer); 563 559 var 564 NewValue: integer;560 NewValue: Integer; 565 561 begin 566 562 if IncCap >= 0 then 567 563 begin 568 564 NewValue := MyRO.DevModel.Cap[IncCap] + 1; 569 Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);565 Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^); 570 566 MyModel[MyRO.nModel] := MyRO.DevModel; 571 InitMyModel(MyRO.nModel, false);567 InitMyModel(MyRO.nModel, False); 572 568 SmartUpdateContent; 573 569 IncCap := -1; … … 580 576 if DecCap >= mcFirstNonCap then 581 577 NewValue := -NewValue; 582 Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);578 Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^); 583 579 MyModel[MyRO.nModel] := MyRO.DevModel; 584 InitMyModel(MyRO.nModel, false);580 InitMyModel(MyRO.nModel, False); 585 581 end; 586 582 SmartUpdateContent; -
branches/highdpi/LocalPlayer/Enhance.pas
r361 r465 5 5 6 6 uses 7 UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, Term, LCLIntf, LCLType, 8 9 SysUtils, Classes, Graphics, Controls, Forms, IsoEngine, 10 ButtonB, ButtonC, Menus; 7 UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, LCLIntf, LCLType, SysUtils, 8 Classes, Graphics, Controls, Forms, IsoEngine, ButtonB, ButtonC, Menus; 11 9 12 10 type … … 39 37 NoMap: TIsoMap; 40 38 public 41 procedure ShowNewContent(NewMode: integer; TerrType: integer = -1);39 procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1); 42 40 protected 43 Page: integer;41 Page: Integer; 44 42 procedure OffscreenPaint; override; 45 43 end; 46 44 47 var48 EnhanceDlg: TEnhanceDlg;49 50 45 51 46 implementation 52 47 53 48 uses 54 Help, UKeyBindings;49 Help, KeyBindings, Term; 55 50 56 51 {$R *.lfm} … … 58 53 procedure TEnhanceDlg.FormCreate(Sender: TObject); 59 54 var 60 TerrType: integer;61 m: TDpiMenuItem;55 TerrType: Integer; 56 M: TDpiMenuItem; 62 57 begin 63 58 inherited; … … 73 68 if TerrType <> fJungle then 74 69 begin 75 m:= TDpiMenuItem.Create(Popup);76 m.RadioItem := true;70 M := TDpiMenuItem.Create(Popup); 71 M.RadioItem := True; 77 72 if TerrType = fGrass then 78 m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),73 M.Caption := Format(Phrases.Lookup('TWOTERRAINS'), 79 74 [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN', 80 75 fGrass + 12)]) 81 76 else if TerrType = fForest then 82 m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),77 M.Caption := Format(Phrases.Lookup('TWOTERRAINS'), 83 78 [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN', 84 79 fJungle)]) 85 80 else 86 m.Caption := Phrases.Lookup('TERRAIN', TerrType);87 m.Tag := TerrType;88 m.OnClick := TerrClick;89 Popup.Items.Add( m);81 M.Caption := Phrases.Lookup('TERRAIN', TerrType); 82 M.Tag := TerrType; 83 M.OnClick := TerrClick; 84 Popup.Items.Add(M); 90 85 end; 91 86 end; … … 98 93 procedure TEnhanceDlg.FormPaint(Sender: TObject); 99 94 var 100 i: integer;95 I: Integer; 101 96 begin 102 97 inherited; … … 105 100 BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width, 106 101 job3.Top + job3.Height), MainTexture); 107 for i:= 0 to ControlCount - 1 do108 if Controls[ i] is TButtonC then109 DpiBit Canvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,110 HGrSystem.Data.Canvas, 121 + Controls[ i].Tag mod 7 * 9,111 1 + Controls[ i].Tag div 7 * 9);102 for I := 0 to ControlCount - 1 do 103 if Controls[I] is TButtonC then 104 DpiBitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8, 105 HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9, 106 1 + Controls[I].Tag div 7 * 9); 112 107 end; 113 108 … … 117 112 end; 118 113 119 procedure TEnhanceDlg.ShowNewContent(NewMode , TerrType: integer);114 procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer); 120 115 begin 121 116 if (TerrType < fGrass) or (TerrType > fMountains) then … … 128 123 procedure TEnhanceDlg.OffscreenPaint; 129 124 var 130 i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;131 s: string;132 Done: Set of jNone .. jTrans;133 TypeChanged: boolean;125 I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer; 126 S: string; 127 Done: set of jNone .. jTrans; 128 TypeChanged: Boolean; 134 129 begin 135 130 OffscreenUser := self; 136 offscreen.Canvas.Font.Assign(UniFont[ftSmall]);131 Offscreen.Canvas.Font.Assign(UniFont[ftSmall]); 137 132 FillOffscreen(0, 0, InnerWidth, InnerHeight); 138 133 139 134 EndStage := 0; 140 135 while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do 141 inc(EndStage);136 Inc(EndStage); 142 137 with NoMap do 143 x:= InnerWidth div 2 - xxt - (xxt + 3) * EndStage;138 X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage; 144 139 145 140 TerrType := Page; … … 151 146 if stage > 0 then 152 147 begin 153 Sprite( offscreen, HGrSystem, x- 10, 66, 14, 14, 80, 1);148 Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1); 154 149 case MyData.EnhancementJobs[Page, stage - 1] of 155 150 jRoad: 156 151 begin 157 inc(Cost, Terrain[TerrType].MoveCost * RoadWork);152 Inc(Cost, Terrain[TerrType].MoveCost * RoadWork); 158 153 TileImp := TileImp or fRoad; 159 154 end; 160 155 jRR: 161 156 begin 162 inc(Cost, Terrain[TerrType].MoveCost * RRWork);157 Inc(Cost, Terrain[TerrType].MoveCost * RRWork); 163 158 TileImp := TileImp or fRR; 164 159 end; 165 160 jIrr: 166 161 begin 167 inc(Cost, Terrain[TerrType].IrrClearWork);162 Inc(Cost, Terrain[TerrType].IrrClearWork); 168 163 TileImp := TileImp and not fTerImp or tiIrrigation; 169 164 end; 170 165 jFarm: 171 166 begin 172 inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);167 Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork); 173 168 TileImp := TileImp and not fTerImp or tiFarm; 174 169 end; 175 170 jMine: 176 171 begin 177 inc(Cost, Terrain[TerrType].MineAfforestWork);172 Inc(Cost, Terrain[TerrType].MineAfforestWork); 178 173 TileImp := TileImp and not fTerImp or tiMine; 179 174 end; 180 175 jClear: 181 176 begin 182 inc(Cost, Terrain[TerrType].IrrClearWork);177 Inc(Cost, Terrain[TerrType].IrrClearWork); 183 178 TerrType := Terrain[TerrType].ClearTerrain; 184 179 end; 185 180 jAfforest: 186 181 begin 187 inc(Cost, Terrain[TerrType].MineAfforestWork);182 Inc(Cost, Terrain[TerrType].MineAfforestWork); 188 183 TerrType := Terrain[TerrType].AfforestTerrain; 189 184 end; 190 185 jTrans: 191 186 begin 192 inc(Cost, Terrain[TerrType].TransWork);187 Inc(Cost, Terrain[TerrType].TransWork); 193 188 TerrType := Terrain[TerrType].TransTerrain; 194 189 end; 195 190 end; 196 include(Done, MyData.EnhancementJobs[Page, stage - 1]);191 Include(Done, MyData.EnhancementJobs[Page, stage - 1]); 197 192 end; 198 193 199 194 with NoMap do begin 200 195 if TerrType < fForest then 201 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,196 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 202 197 1 + TerrType * (xxt * 2 + 1), 1 + yyt) 203 198 else 204 199 begin 205 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,200 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 206 201 1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1)); 207 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,202 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 208 203 1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) * 209 204 (yyt * 3 + 1)); 210 205 end; 211 206 if TileImp and fTerImp = tiFarm then 212 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,207 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 213 208 1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1)) 214 209 else if TileImp and fTerImp = tiIrrigation then 215 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,210 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1, 216 211 1 + yyt + 12 * (yyt * 3 + 1)); 217 212 if TileImp and fRR <> 0 then 218 213 begin 219 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,214 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 220 215 1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1)); 221 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,216 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 222 217 1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1)); 223 218 end 224 219 else if TileImp and fRoad <> 0 then 225 220 begin 226 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,221 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 227 222 1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1)); 228 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,223 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 229 224 1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1)); 230 225 end; 231 226 if TileImp and fTerImp = tiMine then 232 Sprite( offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,227 Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 233 228 1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1)); 234 inc(x, xxt * 2 + 6);235 end; 236 end; 237 238 for i:= 0 to Popup.Items.Count - 1 do239 if Popup.Items[ i].Tag = Page then240 s := Popup.Items[i].Caption;229 Inc(X, xxt * 2 + 6); 230 end; 231 end; 232 233 for I := 0 to Popup.Items.Count - 1 do 234 if Popup.Items[I].Tag = Page then 235 S := Popup.Items[I].Caption; 241 236 if Cost > 0 then 242 s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);243 LoweredTextOut( offscreen.Canvas, -1, MainTexture,244 (InnerWidth - BiColorTextWidth( offscreen.Canvas, s)) div 2, 12, s);237 S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]); 238 LoweredTextOut(Offscreen.Canvas, -1, MainTexture, 239 (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S); 245 240 246 241 if EndStage > 0 then … … 291 286 (Terrain[TerrType].MineEff > 0); 292 287 job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and 293 ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or288 ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or 294 289 (LastJob = jClear); 295 290 job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0) … … 299 294 300 295 MarkUsedOffscreen(InnerWidth, InnerHeight); 301 end; { OffscreenPaint }296 end; 302 297 303 298 procedure TEnhanceDlg.CloseBtnClick(Sender: TObject); … … 308 303 procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject); 309 304 var 310 i: integer;311 begin 312 for i:= 0 to Popup.Items.Count - 1 do313 Popup.Items[ i].Checked := Popup.Items[i].Tag = Page;305 I: Integer; 306 begin 307 for I := 0 to Popup.Items.Count - 1 do 308 Popup.Items[I].Checked := Popup.Items[I].Tag = Page; 314 309 Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height); 315 310 end; … … 323 318 procedure TEnhanceDlg.JobClick(Sender: TObject); 324 319 var 325 stage, NewJob: integer;320 Stage, NewJob: Integer; 326 321 Done: Set of jNone .. jTrans; 327 322 328 procedure RemoveJob( j: integer);323 procedure RemoveJob(J: Integer); 329 324 begin // remove job 330 stage := 0;331 while ( stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do332 begin 333 if (MyData.EnhancementJobs[Page, stage] = j) or (j= jRoad) and334 (MyData.EnhancementJobs[Page, stage] = jRR) or (j= jIrr) and335 (MyData.EnhancementJobs[Page, stage] = jFarm) then325 Stage := 0; 326 while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do 327 begin 328 if (MyData.EnhancementJobs[Page, Stage] = J) or (J = jRoad) and 329 (MyData.EnhancementJobs[Page, Stage] = jRR) or (J = jIrr) and 330 (MyData.EnhancementJobs[Page, Stage] = jFarm) then 336 331 begin 337 if stage < 4 then338 move(MyData.EnhancementJobs[Page, stage + 1],339 MyData.EnhancementJobs[Page, stage], 4 - stage);332 if Stage < 4 then 333 Move(MyData.EnhancementJobs[Page, Stage + 1], 334 MyData.EnhancementJobs[Page, Stage], 4 - Stage); 340 335 MyData.EnhancementJobs[Page, 4] := jNone; 341 336 end 342 337 else 343 inc(stage);338 Inc(Stage); 344 339 end; 345 340 end; … … 348 343 NewJob := TButtonC(Sender).Tag; 349 344 Done := []; 350 stage := 0;351 while ( stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do345 Stage := 0; 346 while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do 352 347 begin 353 include(Done, MyData.EnhancementJobs[Page, stage]);354 inc(stage);348 Include(Done, MyData.EnhancementJobs[Page, Stage]); 349 Inc(Stage); 355 350 end; 356 351 if NewJob in Done then … … 364 359 if (NewJob = jRR) and not(jRoad in Done) then 365 360 begin 366 MyData.EnhancementJobs[Page, stage] := jRoad;367 inc(stage);361 MyData.EnhancementJobs[Page, Stage] := jRoad; 362 Inc(Stage); 368 363 end; 369 364 if (NewJob = jFarm) and not(jIrr in Done) then 370 365 begin 371 MyData.EnhancementJobs[Page, stage] := jIrr;372 inc(stage);373 end; 374 MyData.EnhancementJobs[Page, stage] := NewJob;366 MyData.EnhancementJobs[Page, Stage] := jIrr; 367 Inc(Stage); 368 end; 369 MyData.EnhancementJobs[Page, Stage] := NewJob; 375 370 end; 376 371 SmartUpdateContent; … … 384 379 ShortCut := KeyToShortCut(Key, Shift); 385 380 if BHelp.Test(ShortCut) then 386 HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,387 HelpDlg.TextIndex('MACRO'))381 MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkText, 382 MainScreen.HelpDlg.TextIndex('MACRO')) 388 383 end; 389 384 -
branches/highdpi/LocalPlayer/Help.pas
r412 r465 7 7 UDpiControls, Protocol, ScreenTools, BaseWin, StringTables, Math, LCLIntf, LCLType, 8 8 Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, 9 ButtonB, PVSB, Types, fgl, IsoEngine;9 ButtonB, PVSB, Types, Generics.Collections, IsoEngine; 10 10 11 11 const 12 12 MaxHist = 16; 13 13 14 { link categories } 15 hkNoLink = 0; 16 hkAdv = 1; 17 hkImp = 2; 18 hkTer = 3; 19 hkFeature = 4; 20 hkInternet = 5; 21 hkModel = 6; 22 hkMisc = 7; 23 hkCrossLink = $40; 24 hkText = $80; 25 26 liInvalid = $3FFF; // link index indicates invalid link 27 28 { link indices for category hkMisc } 29 miscMain = 0; 30 miscCredits = 1; 31 miscGovList = 2; 32 miscJobList = 3; 33 miscSearchResult = 7; 34 35 fJungle = 8; // pseudo terrain 14 fJungle = 8; // Pseudo terrain 36 15 37 16 type 17 { Link categories } 18 TLinkCategory = ( 19 hkNoLink, 20 hkAdv, 21 hkImp, 22 hkTer, 23 hkFeature , 24 hkInternet, 25 hkModel, 26 hkMisc, 27 hkText); 28 29 { Link indices for category hkMisc } 30 TMiscLinkIndex = ( 31 miscMain, 32 miscCredits, 33 miscGovList, 34 miscJobList, 35 miscSearchResult); 36 37 TTextFormat = ( 38 pkNormal, 39 pkCaption, 40 pkSmallIcon, 41 pkBigIcon, 42 pkAdvIcon, 43 pkTer, 44 pkBigTer, 45 pkFeature, 46 pkDot, 47 pkNormal_Dot, 48 pkDomain, 49 pkSection, 50 pkBigFeature, 51 pkExp, 52 pkAITStat, 53 pkExternal, 54 pkModel, 55 pkNormal_64, 56 pkIllu, 57 pkLogo, 58 pkTerImp, 59 pkRightIcon, 60 pkAdvIcon_AsPreq, 61 pkSmallIcon_AsPreq, 62 pkSpecialIcon, 63 pkGov); 38 64 39 65 { THyperText } … … 41 67 THyperText = class(TStringList) 42 68 public 43 procedure AddLine( s: String = ''; Format: integer = 0; Picpix: Integer = 0;44 LinkCategory: integer = 0; LinkIndex: integer = 0);69 procedure AddLine(S: String = ''; Format: TTextFormat = pkNormal; Picpix: Integer = 0; 70 LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0; CrossLink: Boolean = False); 45 71 procedure LineFeed; 46 72 procedure AppendList(Source: THyperText); 47 destructor Destroy; override;48 73 end; 49 74 … … 51 76 52 77 THistItem = class 53 Kind: Integer;78 Kind: TLinkCategory; 54 79 No: Integer; 55 80 Pos: Integer; … … 60 85 { THistItems } 61 86 62 THistItems = class(T FPGObjectList<THistItem>)63 function AddNew(Kind ,No, Pos: Integer; SearchContent: string): THistItem;87 THistItems = class(TObjectList<THistItem>) 88 function AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string): THistItem; 64 89 end; 65 90 … … 78 103 procedure CloseBtnClick(Sender: TObject); 79 104 procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 80 x, y: integer);105 X, Y: Integer); 81 106 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 82 Shift: TShiftState; x, y: integer);107 Shift: TShiftState; X, Y: Integer); 83 108 procedure BackBtnClick(Sender: TObject); 84 109 procedure TopBtnClick(Sender: TObject); … … 89 114 procedure OffscreenPaint; override; 90 115 private 91 Kind: Integer;92 no: Integer;116 Kind: TLinkCategory; 117 No: Integer; 93 118 Sel: Integer; 94 119 CaptionColor: Integer; … … 100 125 SearchResult: THyperText; 101 126 HelpText: TStringTable; 102 ExtPic, TerrIcon: TDpiBitmap; 127 ExtPic: TDpiBitmap; 128 TerrIcon: TDpiBitmap; 103 129 ScrollBar: TPVScrollbar; 104 130 NoMap: TIsoMap; 105 131 x0: array [-2..180] of Integer; 106 procedure PaintTerrIcon( x, y, xSrc, ySrc: Integer);132 procedure PaintTerrIcon(X, Y, xSrc, ySrc: Integer); 107 133 procedure ScrollBarUpdate(Sender: TObject); 108 procedure Line( ca: TDpiCanvas; i: Integer; lit: Boolean);134 procedure Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean); 109 135 procedure Prepare(sbPos: Integer = 0); 110 procedure ShowNewContentProcExecute(NewMode: Integer; HelpContext: string);136 procedure ShowNewContentProcExecute(NewMode: TWindowMode; HelpContext: string); 111 137 procedure WaterSign(x0, y0, iix: Integer); 112 138 procedure Search(SearchString: string); … … 117 143 Difficulty: Integer; 118 144 procedure ClearHistory; 119 procedure ShowNewContent(NewMode , Category,Index: Integer);145 procedure ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory; Index: Integer); 120 146 function TextIndex(Item: string): Integer; 121 147 end; 122 148 123 var124 HelpDlg: THelpDlg;125 126 149 127 150 implementation 128 151 129 152 uses 130 Directories, ClientTools, Term, Tribes, Inp, Messg, UPixelPointer, Global,131 UKeyBindings;153 Directories, ClientTools, Term, Tribes, Inp, Messg, PixelPointer, Global, 154 KeyBindings; 132 155 133 156 {$R *.lfm} … … 138 161 139 162 THelpLineInfo = class 140 Format: Byte;163 Format: TTextFormat; 141 164 Picpix: Byte; 142 Link: Word; 165 Category: TLinkCategory; 166 Index: Integer; 167 CrossLink: Boolean; 143 168 procedure Assign(Source: THelpLineInfo); 144 169 end; 145 170 146 { THelpLineInfo } 147 148 procedure THelpLineInfo.Assign(Source: THelpLineInfo); 149 begin 150 Format := Source.Format; 151 PicPix := Source.PicPix; 152 Link := Source.Link; 153 end; 154 155 { THistItem } 156 157 procedure THistItem.Assign(Source: THistItem); 158 begin 159 Kind := Source.Kind; 160 No := Source.No; 161 Pos := Source.Pos; 162 SearchContent := Source.SearchContent; 163 end; 164 165 { THistItems } 166 167 function THistItems.AddNew(Kind, No, Pos: Integer; SearchContent: string 168 ): THistItem; 169 begin 170 Result := THistItem.Create; 171 Result.Kind := Kind; 172 Result.No := No; 173 Result.Pos := Pos; 174 Result.SearchContent := SearchContent; 175 Add(Result); 176 end; 177 178 procedure THyperText.AddLine(s: String; Format: integer; Picpix: integer; 179 LinkCategory: integer; LinkIndex: integer); 180 var 181 HelpLineInfo: THelpLineInfo; 182 begin 183 HelpLineInfo := THelpLineInfo.Create; 184 if LinkIndex < 0 then 185 LinkIndex := liInvalid; 186 HelpLineInfo.Format := Format; 187 HelpLineInfo.Picpix := Picpix; 188 HelpLineInfo.Link := LinkCategory shl 8 + LinkIndex; 189 AddObject(s, TObject(HelpLineInfo)); 190 end; 191 192 procedure THyperText.LineFeed; 193 begin 194 AddLine; 195 end; 196 197 procedure THyperText.AppendList(Source: THyperText); 198 var 199 I: Integer; 200 HelpLineInfo: THelpLineInfo; 201 begin 202 for I := 0 to Source.Count - 1 do begin 203 HelpLineInfo := THelpLineInfo.Create; 204 HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I])); 205 AddObject(Source.Strings[I], HelpLineInfo); 206 end; 207 end; 208 209 destructor THyperText.Destroy; 210 begin 211 inherited; 212 end; 171 TSeeAlso = record 172 Kind: TLinkCategory; 173 No: Integer; 174 SeeKind: TLinkCategory; 175 SeeNo: Integer; 176 end; 213 177 214 178 const 215 { text formats } 216 pkNormal = 0; 217 pkCaption = 1; 218 pkSmallIcon = 2; 219 pkBigIcon = 3; 220 pkAdvIcon = 4; 221 pkTer = 5; 222 pkBigTer = 6; 223 pkFeature = 7; 224 pkDot = 8; 225 pkNormal_Dot = 9; 226 pkDomain = 10; 227 pkSection = 11; 228 pkBigFeature = 12; 229 pkExp = 13; 230 pkAITStat = 14; 231 pkExternal = 15; 232 pkModel = 16; 233 pkNormal_64 = 17; 234 pkIllu = 18; 235 pkLogo = 19; 236 pkTerImp = 20; 237 pkRightIcon = 21; 238 pkAdvIcon_AsPreq = 22; 239 pkSmallIcon_AsPreq = 23; 240 pkSpecialIcon = 24; 241 pkGov = 25; 242 243 nSeeAlso = 14; 244 SeeAlso: array [0 .. nSeeAlso - 1] of record 245 Kind: Integer; 246 no: Integer; 247 SeeKind: Integer; 248 SeeNo: Integer; 249 end = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature; 179 SeeAlso: array[0..13] of TSeeAlso = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature; 250 180 SeeNo: mcArtillery), (Kind: hkImp; no: imHydro; SeeKind: hkImp; 251 181 SeeNo: woHoover), (Kind: hkImp; no: imWalls; SeeKind: hkImp; … … 262 192 SeeKind: hkFeature; SeeNo: mcDefense)); 263 193 264 nTerrainHelp = 14; 265 TerrainHelp: array [0 .. nTerrainHelp - 1] of integer = (fGrass, fGrass + 12, 194 TerrainHelp: array[0..13] of Integer = (fGrass, fGrass + 12, 266 195 fPrairie, fForest, fJungle, fHills, fMountains, fSwamp, fTundra, fArctic, 267 fDesert, 3 * 12 { DeadLands } , fShore, fOcean); 268 269 nJobHelp = 8; 270 JobHelp: array [0 .. nJobHelp - 1] of integer = (jRoad, jRR, jCanal, jIrr, 196 fDesert, 3 * 12 { DeadLands }, fShore, fOcean); 197 198 JobHelp: array[0..7] of Integer = (jRoad, jRR, jCanal, jIrr, 271 199 jFarm, jMine, jFort, jBase); 272 200 201 { THelpLineInfo } 202 203 procedure THelpLineInfo.Assign(Source: THelpLineInfo); 204 begin 205 Format := Source.Format; 206 PicPix := Source.PicPix; 207 Category := Source.Category; 208 Index := Source.Index; 209 end; 210 211 { THistItem } 212 213 procedure THistItem.Assign(Source: THistItem); 214 begin 215 Kind := Source.Kind; 216 No := Source.No; 217 Pos := Source.Pos; 218 SearchContent := Source.SearchContent; 219 end; 220 221 { THistItems } 222 223 function THistItems.AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string 224 ): THistItem; 225 begin 226 Result := THistItem.Create; 227 Result.Kind := Kind; 228 Result.No := No; 229 Result.Pos := Pos; 230 Result.SearchContent := SearchContent; 231 Add(Result); 232 end; 233 234 procedure THyperText.AddLine(S: String; Format: TTextFormat; Picpix: Integer; 235 LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0; 236 CrossLink: Boolean = False); 237 var 238 HelpLineInfo: THelpLineInfo; 239 begin 240 HelpLineInfo := THelpLineInfo.Create; 241 HelpLineInfo.Format := Format; 242 HelpLineInfo.Picpix := Picpix; 243 HelpLineInfo.Category := LinkCategory; 244 HelpLineInfo.Index := LinkIndex; 245 HelpLineInfo.CrossLink := CrossLink; 246 AddObject(S, HelpLineInfo); 247 end; 248 249 procedure THyperText.LineFeed; 250 begin 251 AddLine; 252 end; 253 254 procedure THyperText.AppendList(Source: THyperText); 255 var 256 I: Integer; 257 HelpLineInfo: THelpLineInfo; 258 begin 259 for I := 0 to Source.Count - 1 do begin 260 HelpLineInfo := THelpLineInfo.Create; 261 HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I])); 262 AddObject(Source.Strings[I], HelpLineInfo); 263 end; 264 end; 265 273 266 procedure THelpDlg.FormCreate(Sender: TObject); 274 267 begin 275 inherited;276 268 NoMap := TIsoMap.Create; 277 269 … … 280 272 CaptionLeft := BackBtn.Left + BackBtn.Width; 281 273 CaptionRight := SearchBtn.Left; 282 inc(ModalFrameIndent, 29);274 Inc(ModalFrameIndent, 29); 283 275 MainText := THyperText.Create; 284 276 MainText.OwnsObjects := True; … … 290 282 291 283 HelpText := TStringTable.Create; 292 HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + ' help.txt'));284 HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'Help.txt')); 293 285 hADVHELP := HelpText.Gethandle('ADVHELP'); 294 286 hIMPHELP := HelpText.Gethandle('IMPHELP'); … … 316 308 end; 317 309 318 procedure THelpDlg.ShowNewContentProcExecute(NewMode: Integer;310 procedure THelpDlg.ShowNewContentProcExecute(NewMode: TWindowMode; 319 311 HelpContext: string); 320 312 begin 321 HelpDlg.ShowNewContent(NewMode, hkText, 322 HelpDlg.TextIndex(HelpContext)) 313 ShowNewContent(NewMode, hkText, TextIndex(HelpContext)); 323 314 end; 324 315 … … 356 347 if ScrollBar.Process(Msg) then begin 357 348 Sel := -1; 358 SmartUpdateContent( true)349 SmartUpdateContent(True) 359 350 end; 360 351 } … … 364 355 begin 365 356 if Sel <> -1 then begin 366 Line(Canvas, Sel, false);367 Sel := -1 357 Line(Canvas, Sel, False); 358 Sel := -1; 368 359 end; 369 360 end; … … 380 371 end; 381 372 382 procedure THelpDlg.Line( ca: TDpiCanvas; i: Integer; lit: Boolean);373 procedure THelpDlg.Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean); 383 374 var 384 TextColor, x, y: Integer; 375 TextColor: TColor; 376 X, Y: Integer; 385 377 TextSize: TSize; 386 s: string;387 begin 388 s := MainText[ScrollBar.Position + i];389 if s= '' then378 S: string; 379 begin 380 S := MainText[ScrollBar.Position + I]; 381 if S = '' then 390 382 Exit; 391 x := x0[i];392 y := 2 + i* 24;393 if ca= Canvas then394 begin 395 x := x+ SideFrame;396 y := y + WideFrame397 end; 398 if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format383 X := x0[I]; 384 Y := 2 + I * 24; 385 if ACanvas = Canvas then 386 begin 387 X := X + SideFrame; 388 Y := Y + WideFrame; 389 end; 390 if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format 399 391 in [pkCaption, pkBigTer, pkRightIcon, pkBigFeature] then 400 392 begin 401 ca.Font.Assign(CaptionFont);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));406 ca.Brush.Style:=bsClear; }407 DpiBit Canvas(ca, x, y- 4, 24, 24, HGrSystem.Data.Canvas, 1,393 ACanvas.Font.Assign(CaptionFont); 394 { ACanvas.brush.color:=CaptionColor; 395 ACanvas.FillRect(rect(X,I*24,X+24,I*24+24)); 396 ACanvas.Brush.Color:=$FFFFFF; 397 ACanvas.FrameRect(rect(X+1,I*24+1,X+24-1,I*24+24-1)); 398 ACanvas.Brush.Style:=bsClear; } 399 DpiBitBltCanvas(ACanvas, X, Y - 4, 24, 24, HGrSystem.Data.Canvas, 1, 408 400 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));412 ca.Font.Assign(UniFont[ftNormal]);401 BiColorTextOut(ACanvas, $FFFFFF, $7F007F, X + 10 - ACanvas.Textwidth(S[1]) div 2, 402 Y - 3, S[1]); 403 BiColorTextOut(ACanvas, CaptionColor, $7F007F, X + 24, Y - 3, Copy(S, 2, 255)); 404 ACanvas.Font.Assign(UniFont[ftNormal]); 413 405 end 414 else if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format = pkSection 415 then 416 begin 417 ca.Font.Assign(CaptionFont); 418 BiColorTextOut(ca, CaptionColor, $7F007F, x, y - 3, s); 419 ca.Font.Assign(UniFont[ftNormal]); 406 else if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format = pkSection then 407 begin 408 ACanvas.Font.Assign(CaptionFont); 409 BiColorTextOut(ACanvas, CaptionColor, $7F007F, X, Y - 3, S); 410 ACanvas.Font.Assign(UniFont[ftNormal]); 420 411 end 421 412 else 422 413 begin 423 if (Kind = hkMisc) and ( no = miscMain) then424 ca.Font.Assign(CaptionFont);414 if (Kind = hkMisc) and (No = Integer(miscMain)) then 415 ACanvas.Font.Assign(CaptionFont); 425 416 TextColor := Colors.Canvas.Pixels[clkMisc, cliPaperText]; 426 if ca= Canvas then417 if ACanvas = Canvas then 427 418 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,419 TextSize.cx := BiColorTextWidth(ACanvas, S); 420 TextSize.cy := ACanvas.TextHeight(S); 421 if Y + TextSize.cy >= WideFrame + InnerHeight then 422 TextSize.cy := WideFrame + InnerHeight - Y; 423 FillSeamless(ACanvas, X, Y, TextSize.cx, TextSize.cy, -SideFrame, 433 424 ScrollBar.Position * 24 - WideFrame, Paper); 434 425 end; 435 BiColorTextOut( ca, TextColor, $7F007F, x, y, s);426 BiColorTextOut(ACanvas, TextColor, $7F007F, X, Y, S); 436 427 if lit then 437 with cado428 with ACanvas do 438 429 begin 439 Assert( ca= Canvas);430 Assert(ACanvas = Canvas); 440 431 Pen.Color := TextColor; 441 MoveTo( x + 1, y+ TextSize.cy - 2);442 LineTo( x + TextSize.cx, y+ TextSize.cy - 2);432 MoveTo(X + 1, Y + TextSize.cy - 2); 433 LineTo(X + TextSize.cx, Y + TextSize.cy - 2); 443 434 end; 444 if (Kind = hkMisc) and ( no = miscMain) then445 ca.Font.Assign(UniFont[ftNormal]);446 end; 447 end; 448 449 procedure THelpDlg.WaterSign(x0, y0, iix: integer);435 if (Kind = hkMisc) and (No = Integer(miscMain)) then 436 ACanvas.Font.Assign(UniFont[ftNormal]); 437 end; 438 end; 439 440 procedure THelpDlg.WaterSign(x0, y0, iix: Integer); 450 441 const 451 442 nHeaven = 28; 452 443 MaxSum = 9 * 9 * 255 * 75 div 100; 453 444 var 454 x, y, dx, dy, xSrc, ySrc, Sum, xx: integer;455 Heaven: array [0..nHeaven] of integer;445 X, Y, dx, dy, xSrc, ySrc, Sum, xx: Integer; 446 Heaven: array [0..nHeaven] of Integer; 456 447 PaintPtr: TPixelPointer; 457 448 CoalPtr: TPixelPointer; … … 467 458 xSrc := iix mod 7 * xSizeBig; 468 459 ySrc := (iix div 7 + 1) * ySizeBig; 469 PaintPtr := PixelPointer(OffScreen, ScaleToNative(x0), ScaleToNative(y0));470 CoalPtr := PixelPointer(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal));460 PaintPtr := TPixelPointer.Create(OffScreen, ScaleToNative(x0), ScaleToNative(y0)); 461 CoalPtr := TPixelPointer.Create(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal)); 471 462 for dy := -1 to 1 do 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 begin463 ImpPtr[dy] := TPixelPointer.Create(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc)); 464 for Y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin 465 if ((ScaleToNative(y0) + Y) >= 0) and ((ScaleToNative(y0) + Y) < ScaleToNative(InnerHeight)) then begin 475 466 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 begin467 if ((Max(Y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(Y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then 468 ImpPtr[dy].SetXY(0, Max(Y + ScaleToNative(dy), 0) shr 1); 469 for X := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin 479 470 Sum := 0; 480 471 for dx := -1 to 1 do begin 481 xx := Max(( x+ ScaleToNative(dx)), 0) shr 1;472 xx := Max((X + ScaleToNative(dx)), 0) shr 1; 482 473 for dy := -1 to 1 do begin 483 474 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)) and475 if ((Y + ScaleToNative(dy)) shr 1 < 0) or ((Y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or 476 ((X + ScaleToNative(dx)) shr 1 < 0) or ((X + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or 477 ((Y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and 487 478 (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 + 488 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative( y+ ScaleToNative(dy))) shr 1]) then479 ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(Y + ScaleToNative(dy))) shr 1]) then 489 480 Sum := Sum + 9 * 255 490 481 else … … 493 484 end; 494 485 end; 495 if Sum < MaxSum then begin // no saturation486 if Sum < MaxSum then begin // No saturation 496 487 Sum := 1 shl 22 - (MaxSum - Sum) * (256 - CoalPtr.Pixel^.B * 2); 497 488 PaintPtr.Pixel^.B := Min(PaintPtr.Pixel^.B * Sum shr 22, 255); … … 510 501 end; 511 502 512 procedure THelpDlg.PaintTerrIcon( x, y, xSrc, ySrc: integer);503 procedure THelpDlg.PaintTerrIcon(X, Y, xSrc, ySrc: Integer); 513 504 begin 514 505 with NoMap do begin 515 Frame(OffScreen.Canvas, x - 1, y - 1, x + xSizeBig, y+ ySizeBig,506 Frame(OffScreen.Canvas, X - 1, Y - 1, X + xSizeBig, Y + ySizeBig, 516 507 $000000, $000000); 517 508 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,509 Sprite(OffScreen, HGrTerrain, X, Y, 56, 2 * yyt, xSrc, ySrc); 510 Sprite(OffScreen, HGrTerrain, X, Y + 2 * yyt, 56, 40 - 2 * yyt, 520 511 xSrc, ySrc); 521 512 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,513 Sprite(OffScreen, HGrTerrain, X, Y, 56, 40, xSrc, ySrc); 514 Sprite(OffScreen, HGrTerrain, X, Y, xxt, yyt, xSrc + xxt, ySrc + yyt); 515 Sprite(OffScreen, HGrTerrain, X, Y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc); 516 Sprite(OffScreen, HGrTerrain, X + xxt, Y, 56 - xxt, yyt, xSrc, ySrc + yyt); 517 Sprite(OffScreen, HGrTerrain, X + xxt, Y + yyt, 56 - xxt, 40 - yyt, 527 518 xSrc, ySrc); 528 519 end; … … 531 522 procedure THelpDlg.OffscreenPaint; 532 523 var 533 i, j, yl, srcno, ofs, cnt, y: Integer;534 s: string;524 I, J, yl, srcno, ofs, cnt, Y: Integer; 525 S: string; 535 526 HelpLineInfo: THelpLineInfo; 536 527 begin … … 542 533 begin 543 534 Font.Assign(UniFont[ftNormal]); 544 for i:= -ScrollBar.Position to InnerHeight div 24 do545 if ScrollBar.Position + i< MainText.Count then535 for I := -ScrollBar.Position to InnerHeight div 24 do 536 if ScrollBar.Position + I < MainText.Count then 546 537 begin 547 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);538 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]); 548 539 if HelpLineInfo.Format = pkExternal then 549 540 begin 550 541 yl := ExtPic.Height; 551 if 4 + i* 24 + yl > InnerHeight then552 yl := InnerHeight - (4 + i* 24);553 DpiBit Canvas(OffScreen.Canvas, 8, 4 + i* 24, ExtPic.Width, yl, ExtPic.Canvas,542 if 4 + I * 24 + yl > InnerHeight then 543 yl := InnerHeight - (4 + I * 24); 544 DpiBitBltCanvas(OffScreen.Canvas, 8, 4 + I * 24, ExtPic.Width, yl, ExtPic.Canvas, 554 545 0, 0); 555 546 end; 556 547 end; 557 for i:= -2 to InnerHeight div 24 do558 if (ScrollBar.Position + i >= 0) and (ScrollBar.Position + i< MainText.Count) then548 for I := -2 to InnerHeight div 24 do 549 if (ScrollBar.Position + I >= 0) and (ScrollBar.Position + I < MainText.Count) then 559 550 begin 560 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);561 if HelpLineInfo.Link <> 0then551 HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]); 552 if (HelpLineInfo.Category <> hkNoLink) or (HelpLineInfo.Index <> 0) then 562 553 begin 563 if (Kind = hkMisc) and ( no = miscSearchResult) then564 Sprite(OffScreen, HGrSystem, 18, 9 + i* 24, 8, 8, 90, 16)554 if (Kind = hkMisc) and (No = Integer(miscSearchResult)) then 555 Sprite(OffScreen, HGrSystem, 18, 9 + I * 24, 8, 8, 90, 16) 565 556 else if HelpLineInfo.Format in [pkSmallIcon_AsPreq, pkAdvIcon_AsPreq] 566 557 then 567 Sprite(OffScreen, HGrSystem, 12, i* 24 + 5, 14, 14, 65, 20)568 else if HelpLineInfo. Link and (hkCrossLink shl 8) <> 0then569 Sprite(OffScreen, HGrSystem, 12, i* 24 + 5, 14, 14, 80, 1)570 else if not((Kind = hkMisc) and ( no = miscMain)) then571 Sprite(OffScreen, HGrSystem, 10, i* 24 + 6, 14, 14, 65, 1);572 x0[ i] := 24;558 Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 65, 20) 559 else if HelpLineInfo.CrossLink then 560 Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 80, 1) 561 else if not((Kind = hkMisc) and (No = Integer(miscMain))) then 562 Sprite(OffScreen, HGrSystem, 10, I * 24 + 6, 14, 14, 65, 1); 563 x0[I] := 24; 573 564 end 574 565 else 575 x0[ i] := 0;566 x0[I] := 0; 576 567 case HelpLineInfo.Format of 577 568 pkLogo: 578 569 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,570 Server(sGetVersion, 0, 0, J); 571 S := Format('%d.%d.%d', [J shr 16 and $FF, J shr 8 and $FF, 572 J and $FF]); 573 PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, I * 24 + 1, 583 574 HGrSystem.Data.Canvas.Pixels[95, 1], $000000); 584 575 Font.Assign(UniFont[ftSmall]); 585 576 BiColorTextOut(OffScreen.Canvas, $000000, $7F007F, 586 (InnerWidth - Textwidth( s)) div 2, i * 24 + 26, s);577 (InnerWidth - Textwidth(S)) div 2, I * 24 + 26, S); 587 578 Font.Assign(UniFont[ftNormal]); 588 579 end; 589 580 pkSmallIcon, pkSmallIcon_AsPreq: 590 581 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);582 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 583 8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000); 593 584 if HelpLineInfo.Picpix = imPalace then 594 DpiBit Canvas(OffScreen.Canvas, 8 + x0[i], 2 + i* 24,585 DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 595 586 xSizeSmall, ySizeSmall, SmallImp.Canvas, 596 587 0 * xSizeSmall, 1 * ySizeSmall) 597 588 else 598 DpiBit Canvas(OffScreen.Canvas, 8 + x0[i], 2 + i* 24,589 DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 599 590 xSizeSmall, ySizeSmall, SmallImp.Canvas, 600 591 HelpLineInfo.Picpix mod 7 * xSizeSmall, 601 592 (HelpLineInfo.Picpix + SystemIconLines * 7) div 7 * 602 593 ySizeSmall); 603 x0[ i] := x0[i] + (8 + 8 + 36);594 x0[I] := x0[I] + (8 + 8 + 36); 604 595 end; 605 596 pkBigIcon: 606 597 begin 607 FrameImage(OffScreen.Canvas, BigImp, x0[ i] + 12, i* 24 - 7, 56,598 FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 56, 608 599 40, HelpLineInfo.Picpix mod 7 * xSizeBig, 609 600 HelpLineInfo.Picpix div 7 * ySizeBig); 610 x0[ i] := 64 + 8 + 8 + x0[i];601 x0[I] := 64 + 8 + 8 + x0[I]; 611 602 end; 612 603 pkSpecialIcon: … … 615 606 0: 616 607 FrameImage(OffScreen.Canvas, HGrSystem2.Data, 617 12 + x0[ i], -7 + i* 24, 56, 40, 137, 127);608 12 + x0[I], -7 + I * 24, 56, 40, 137, 127); 618 609 1: 619 610 with NoMap do begin 620 PaintTerrIcon(12 + x0[ i], -7 + i* 24,611 PaintTerrIcon(12 + x0[I], -7 + I * 24, 621 612 1 + 3 * (xxt * 2 + 1), 1 + yyt); 622 613 if 2 * yyt < 40 then 623 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,614 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 624 615 56, 2 * yyt, 1 + 3 * (xxt * 2 + 1) + xxt - 28, 625 616 1 + yyt + 1 * (yyt * 3 + 1)) 626 617 else 627 Sprite(OffScreen, HGrTerrain, 12 + x0[ i],628 -7 + 4 + i* 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt618 Sprite(OffScreen, HGrTerrain, 12 + x0[I], 619 -7 + 4 + I * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt 629 620 - 28, 1 + yyt + 1 * (yyt * 3 + 1) + yyt - 20); 630 621 end; 631 622 2: 632 623 with NoMap do begin 633 PaintTerrIcon(12 + x0[ i], -7 + i* 24,624 PaintTerrIcon(12 + x0[I], -7 + I * 24, 634 625 1 + 7 * (xxt * 2 + 1), 1 + yyt + 4 * (yyt * 3 + 1)); 635 626 if 2 * yyt < 40 then 636 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,627 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 637 628 56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28, 638 629 1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16) 639 630 else 640 Sprite(OffScreen, HGrTerrain, 12 + x0[ i], -7 + 4 + i* 24,631 Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24, 641 632 56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28, 642 633 1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16) 643 634 end; 644 635 end; 645 x0[ i] := 64 + 8 + 8 + x0[i];636 x0[I] := 64 + 8 + 8 + x0[I]; 646 637 end; 647 638 pkDomain: 648 639 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,640 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 641 8 + 36 + x0[I], 2 + 20 + I * 24, $000000, $000000); 642 Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20, 652 643 75 + HelpLineInfo.Picpix * 37, 295); 653 x0[ i] := x0[i] + (8 + 8 + 36);644 x0[I] := x0[I] + (8 + 8 + 36); 654 645 end; 655 646 pkAdvIcon, pkAdvIcon_AsPreq: 656 647 begin 657 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[ i], 2 - 1 + i* 24,658 8 + xSizeSmall + x0[ i], 2 + ySizeSmall + i* 24,648 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 649 8 + xSizeSmall + x0[I], 2 + ySizeSmall + I * 24, 659 650 $000000, $000000); 660 651 if AdvIcon[HelpLineInfo.Picpix] < 84 then 661 DpiBit Canvas(OffScreen.Canvas, 8 + x0[i], 2 + i* 24,652 DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, 662 653 xSizeSmall, ySizeSmall, SmallImp.Canvas, 663 654 (AdvIcon[HelpLineInfo.Picpix] + SystemIconLines * 7) mod 7 * … … 665 656 7) div 7 * ySizeSmall) 666 657 else 667 Dump(OffScreen, HGrSystem, 8 + x0[ i], 2 + i* 24, 36, 20,658 Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20, 668 659 1 + (AdvIcon[HelpLineInfo.Picpix] - 84) mod 8 * 37, 669 660 295 + (AdvIcon[HelpLineInfo.Picpix] - 84) div 8 * 21); 670 j:= AdvValue[HelpLineInfo.Picpix] div 1000;671 DpiBit Canvas(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);661 J := AdvValue[HelpLineInfo.Picpix] div 1000; 662 DpiBitBltCanvas(OffScreen.Canvas, x0[I] + 4, 4 + I * 24, 14, 14, 663 HGrSystem.Mask.Canvas, 127 + J * 15, 85, SRCAND); 664 Sprite(OffScreen, HGrSystem, x0[I] + 3, 3 + I * 24, 14, 14, 665 127 + J * 15, 85); 666 x0[I] := x0[I] + (8 + 8 + 36); 676 667 end; 677 668 pkRightIcon: 678 669 begin 679 670 if Imp[HelpLineInfo.Picpix].Kind <> ikWonder then 680 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), i* 24,671 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), I * 24, 681 672 HelpLineInfo.Picpix, gDespotism) 682 673 else 683 WaterSign(InnerWidth - (40 + 2 * xSizeBig), i* 24 - 8,674 WaterSign(InnerWidth - (40 + 2 * xSizeBig), I * 24 - 8, 684 675 HelpLineInfo.Picpix + 7); 685 x0[ i] := x0[i] + 8;676 x0[I] := x0[I] + 8; 686 677 end; 687 678 pkIllu: 688 WaterSign(8, i* 24 - 8, HelpLineInfo.Picpix);679 WaterSign(8, I * 24 - 8, HelpLineInfo.Picpix); 689 680 pkBigFeature: 690 681 begin 691 682 cnt := 0; 692 for j:= nDomains - 1 downto 0 do693 if 1 shl jand Feature[HelpLineInfo.Picpix].Domains <> 0 then683 for J := nDomains - 1 downto 0 do 684 if 1 shl J and Feature[HelpLineInfo.Picpix].Domains <> 0 then 694 685 begin 695 inc(cnt);686 Inc(cnt); 696 687 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);688 I * 24 + 1, 36, 20, 75 + J * 37, 295); 689 ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, I * 24, 690 InnerWidth - 2 - 38 * cnt, I * 24 + 21, $000000, $000000); 700 691 end; 701 692 DarkGradient(OffScreen.Canvas, InnerWidth - 38 - 38 * cnt, 702 i* 24 + 23, cnt * 38 - 2, 1);693 I * 24 + 23, cnt * 38 - 2, 1); 703 694 ofs := InnerWidth - (39 + 7) - 19 * cnt; 704 695 with OffScreen.Canvas do 705 696 begin 706 Brush. color := $C0C0C0;707 FrameRect(Rect(ofs, 1 + 23 + i* 24, ofs + 14,708 15 + 23 + i* 24));697 Brush.Color := $C0C0C0; 698 FrameRect(Rect(ofs, 1 + 23 + I * 24, ofs + 14, 699 15 + 23 + I * 24)); 709 700 Brush.Style := bsClear; 710 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + i* 24, 10, 10,701 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + I * 24, 10, 10, 711 702 66 + HelpLineInfo.Picpix mod 11 * 11, 712 703 137 + HelpLineInfo.Picpix div 11 * 11); 713 704 end; 714 x0[ i] := x0[i] + 8;705 x0[I] := x0[I] + 8; 715 706 end; 716 707 pkTer, pkBigTer: 717 708 with NoMap do begin 718 709 if HelpLineInfo.Format = pkBigTer then 719 y := i* 24 - 3 + yyt710 Y := I * 24 - 3 + yyt 720 711 else 721 y := i* 24 + 13;712 Y := I * 24 + 13; 722 713 if HelpLineInfo.Picpix >= 3 * 12 then 723 714 srcno := 2 * 9 + 6 … … 730 721 if HelpLineInfo.Format = pkTer then 731 722 begin 732 ofs := x0[ i] + 8;733 x0[ i] := 2 * xxt + 8 + ofs;723 ofs := x0[I] + 8; 724 x0[I] := 2 * xxt + 8 + ofs; 734 725 end 735 726 else 736 727 begin 737 728 ofs := InnerWidth - (2 * xxt + 38); 738 x0[ i] := x0[i] + 8;729 x0[I] := x0[I] + 8; 739 730 end; 740 731 if srcno >= fJungle then 741 732 begin 742 Sprite(OffScreen, HGrTerrain, ofs + 4, y- yyt + 2, xxt * 2 - 8,733 Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, 743 734 yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1), 744 735 3 + yyt + 2 * (yyt * 3 + 1)); 745 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,736 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 746 737 yyt * 3 - 2, 1 + srcno mod 9 * (xxt * 2 + 1), 747 738 1 + srcno div 9 * (yyt * 3 + 1)); 748 739 end 749 740 else 750 Sprite(OffScreen, HGrTerrain, ofs + 4, y- yyt + 2, xxt * 2 - 8,741 Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, 751 742 yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1), 752 743 3 + yyt + srcno div 9 * (yyt * 3 + 1)); 753 744 if HelpLineInfo.Picpix >= 3 * 12 then { rare resource } 754 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,745 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 755 746 yyt * 3, 1 + 8 * (xxt * 2 + 1), 756 747 1 + (HelpLineInfo.Picpix - 2 * 12) * (yyt * 3 + 1)) … … 764 755 srcno := 18 + 8 + (HelpLineInfo.Picpix mod 12 - 9) * 18; 765 756 srcno := srcno + HelpLineInfo.Picpix div 12 * 9; 766 Sprite(OffScreen, HGrTerrain, ofs, y- 2 * yyt, xxt * 2,757 Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2, 767 758 yyt * 3, 1 + srcno mod 9 * (xxt * 2 + 1), 768 759 1 + srcno div 9 * (yyt * 3 + 1)); … … 774 765 if HelpLineInfo.Picpix = 5 then 775 766 begin // display mine on hills 776 Sprite(OffScreen, HGrTerrain, ofs + 4, i* 24 + 13 - yyt,767 Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt, 777 768 xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1), 778 769 3 + yyt + 2 * (yyt * 3 + 1)); … … 781 772 else 782 773 srcno := fPrairie; // display on prairie 783 Sprite(OffScreen, HGrTerrain, ofs + 4, i* 24 + 13 - yyt,774 Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt, 784 775 xxt * 2 - 8, yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1), 785 776 3 + yyt + srcno div 9 * (yyt * 3 + 1)); 786 777 if HelpLineInfo.Picpix = 12 then { river } 787 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - yyt, xxt * 2,778 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - yyt, xxt * 2, 788 779 yyt * 2, 1 + 5 * (xxt * 2 + 1), 1 + yyt + 13 * (yyt * 3 + 1)) 789 780 else if HelpLineInfo.Picpix >= 3 then { improvement 2 } 790 781 begin 791 782 if HelpLineInfo.Picpix = 6 then 792 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,783 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 793 784 xxt * 2, yyt * 3, 1 + 7 * (xxt * 2 + 1), 794 785 1 + 12 * (yyt * 3 + 1)); 795 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,786 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 796 787 xxt * 2, yyt * 3, 1 + (HelpLineInfo.Picpix - 3) * 797 788 (xxt * 2 + 1), 1 + 12 * (yyt * 3 + 1)) … … 799 790 else { improvement 1 } 800 791 begin 801 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,792 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 802 793 xxt * 2, yyt * 3, 1 + 2 * (xxt * 2 + 1), 803 794 1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1)); 804 Sprite(OffScreen, HGrTerrain, ofs, i* 24 + 11 - 2 * yyt,795 Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt, 805 796 xxt * 2, yyt * 3, 1 + 5 * (xxt * 2 + 1), 806 797 1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1)) 807 798 end; 808 x0[ i] := x0[i] + 8;799 x0[I] := x0[I] + 8; 809 800 end; 810 801 pkModel: 811 802 begin 812 FrameImage(OffScreen.Canvas, BigImp, x0[ i] + 12, i* 24 - 7,803 FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 813 804 56, 40, 0, 0); 814 Sprite(OffScreen, HGrStdUnits, x0[ i] + 8, i* 24 - 11, 64, 44,805 Sprite(OffScreen, HGrStdUnits, x0[I] + 8, I * 24 - 11, 64, 44, 815 806 1 + HelpLineInfo.Picpix mod 10 * 65, 816 807 1 + HelpLineInfo.Picpix div 10 * 49); 817 x0[ i] := 64 + 8 + 8 + x0[i];808 x0[I] := 64 + 8 + 8 + x0[I]; 818 809 end; 819 810 pkFeature: 820 811 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,812 DarkGradient(OffScreen.Canvas, x0[I] + 8 - 1, 813 7 + I * 24 - 3, 16, 1); 814 ScreenTools.Frame(OffScreen.Canvas, x0[I] + 8, 7 + I * 24 - 2, x0[I] + 8 + 13, 815 7 + I * 24 - 2 + 13, $C0C0C0, $C0C0C0); 816 Sprite(OffScreen, HGrSystem, x0[I] + 8 + 2, 7 + I * 24, 10, 10, 826 817 66 + HelpLineInfo.Picpix mod 11 * 11, 827 818 137 + HelpLineInfo.Picpix div 11 * 11); 828 x0[ i] := x0[i] + 8 + 8 + 2 + 13;819 x0[I] := x0[I] + 8 + 8 + 2 + 13; 829 820 end; 830 821 pkExp: 831 822 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,823 ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + I * 24, 20 + 12, 824 8 + 11 + I * 24, $000000, $000000); 825 Dump(OffScreen, HGrSystem, 20, 8 - 3 + I * 24, 12, 14, 835 826 121 + HelpLineInfo.Picpix * 13, 28); 836 x0[ i] := 20 + 8 + 11;827 x0[I] := 20 + 8 + 11; 837 828 end; 838 829 pkAITStat: 839 830 begin 840 Sprite(OffScreen, HGrSystem, 20, 6 + i* 24, 14, 14,831 Sprite(OffScreen, HGrSystem, 20, 6 + I * 24, 14, 14, 841 832 1 + HelpLineInfo.Picpix * 15, 316); 842 x0[ i] := 20 + 8 + 11;833 x0[I] := 20 + 8 + 11; 843 834 end; 844 835 pkGov: 845 836 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 DpiBit Canvas(OffScreen.Canvas, 8 + x0[i], 2 + i* 24, xSizeSmall,837 ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24, 838 8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000); 839 DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, xSizeSmall, 849 840 ySizeSmall, SmallImp.Canvas, (HelpLineInfo.Picpix - 1) * 850 841 xSizeSmall, ySizeSmall); 851 x0[ i] := x0[i] + (8 + 8 + 36);842 x0[I] := x0[I] + (8 + 8 + 36); 852 843 end; 853 844 pkDot: 854 845 begin 855 Sprite(OffScreen, HGrSystem, x0[ i] + 18, 9 + i* 24, 8,846 Sprite(OffScreen, HGrSystem, x0[I] + 18, 9 + I * 24, 8, 856 847 8, 81, 16); 857 x0[ i] := 20 + 8 + 4;848 x0[I] := 20 + 8 + 4; 858 849 end; 859 850 pkNormal_Dot: 860 x0[ i] := 20 + 8 + 4;851 x0[I] := 20 + 8 + 4; 861 852 pkNormal_64: 862 x0[ i] := 64 + 8 + 8;853 x0[I] := 64 + 8 + 8; 863 854 else 864 x0[ i] := x0[i] + 8;855 x0[I] := x0[I] + 8; 865 856 end; 866 Self.Line(OffScreen.Canvas, i, False)857 Self.Line(OffScreen.Canvas, I, False) 867 858 end; 868 859 end; … … 873 864 begin 874 865 Sel := -1; 875 SmartUpdateContent( true)876 end; 877 878 procedure THelpDlg.Prepare(sbPos: integer = 0);866 SmartUpdateContent(True); 867 end; 868 869 procedure THelpDlg.Prepare(sbPos: Integer = 0); 879 870 var 880 i, j, Special, Domain, Headline, TerrType, TerrSubType: integer;881 s: string;882 ps: pchar;871 I, J, Special, Domain, Headline, TerrType, TerrSubType: Integer; 872 S: string; 873 ps: PChar; 883 874 List: THyperText; 884 875 CheckSeeAlso: Boolean; 885 876 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);877 procedure AddAdvance(I: Integer); 878 begin 879 MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I, 880 hkAdv, I, True); 881 end; 882 883 procedure AddPreqAdv(I: Integer); 884 begin 885 MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon_AsPreq, I, 886 hkAdv, I, True); 887 end; 888 889 procedure AddImprovement(I: Integer); 890 begin 891 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 892 hkImp, I, True); 893 end; 894 895 procedure AddPreqImp(I: Integer); 896 begin 897 MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon_AsPreq, I, 898 hkImp, I, True); 899 end; 900 901 procedure AddTerrain(I: Integer); 911 902 begin 912 903 if MainText.Count > 1 then … … 914 905 MainText.LineFeed; 915 906 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);907 MainText.AddLine(Phrases.Lookup('TERRAIN', I), pkTer, I, hkTer, I); 908 end; 909 910 procedure AddFeature(I: Integer); 911 begin 912 MainText.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I, 913 hkFeature, I, True); 914 end; 915 916 procedure AddModel(I: Integer); 926 917 var 927 pix: integer;918 pix: Integer; 928 919 Name: string; 929 920 begin 930 921 if MainText.Count > 1 then 931 922 MainText.LineFeed; 932 FindStdModelPicture(SpecialModelPictureCode[ i], pix, Name);933 MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, i)923 FindStdModelPicture(SpecialModelPictureCode[I], pix, Name); 924 MainText.AddLine(Name, pkModel, pix, hkModel, I, True); 934 925 end; 935 926 936 927 procedure AddStandardBlock(Item: string); 937 928 var 938 i: integer;929 I: Integer; 939 930 begin 940 931 with MainText do … … 947 938 else if Item = 'TECHFORMULA' then 948 939 begin 949 i:= Difficulty;950 if i= 0 then951 i:= 2;952 AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[ i],953 TechFormula_D[ i]]))940 I := Difficulty; 941 if I = 0 then 942 I := 2; 943 AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[I], 944 TechFormula_D[I]])); 954 945 end 955 946 else if Item = 'EXPERIENCE' then 956 for i:= 0 to nExp - 1 do957 AddLine(Phrases.Lookup('EXPERIENCE', i), pkExp, i)947 for I := 0 to nExp - 1 do 948 AddLine(Phrases.Lookup('EXPERIENCE', I), pkExp, I) 958 949 else if Item = 'MODERN' then 959 for i:= 1 to 3 do950 for I := 1 to 3 do 960 951 begin 961 952 LineFeed; 962 AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + i), pkTer, 3 * 12 + i);953 AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + I), pkTer, 3 * 12 + I); 963 954 end 964 955 else if Item = 'SAVED' then 965 956 AddLine(DataDir + 'Saved', pkNormal) 966 957 else if Item = 'AITSTAT' then 967 for i:= 0 to 3 do968 AddLine(Phrases2.Lookup('AITSTAT', i), pkAITStat, i)969 end 970 end; 971 972 procedure DecodeItem( s: string; var Category,Index: Integer);958 for I := 0 to 3 do 959 AddLine(Phrases2.Lookup('AITSTAT', I), pkAITStat, I) 960 end; 961 end; 962 963 procedure DecodeItem(S: string; var Category: TLinkCategory; var Index: Integer); 973 964 var 974 i: Integer;975 begin 976 if (Length( s) > 0) and (s[1] = ':') then begin965 I: Integer; 966 begin 967 if (Length(S) > 0) and (S[1] = ':') then begin 977 968 Category := hkMisc; 978 969 Index := 0; 979 for i := 3 to length(s) do980 Index := Index * 10 + Ord( s[i]) - 48;981 case s[2] of970 for I := 3 to Length(S) do 971 Index := Index * 10 + Ord(S[I]) - 48; 972 case S[2] of 982 973 'A': Category := hkAdv; 983 974 'B': Category := hkImp; … … 986 977 'E': Category := hkInternet; 987 978 'S': Category := hkModel; 988 'C': Index := miscCredits;989 'J': Index := miscJobList;990 'G': Index := miscGovList;979 'C': Index := Integer(miscCredits); 980 'J': Index := Integer(miscJobList); 981 'G': Index := Integer(miscGovList); 991 982 end; 992 983 if (Category <> hkMisc) and (Index = 0) then … … 994 985 end else begin 995 986 Category := hkText; 996 Index := HelpText.Get handle(Copy(s, 1, 255));987 Index := HelpText.GetHandle(Copy(S, 1, 255)); 997 988 end; 998 989 end; 999 990 1000 procedure AddTextual( s: string);991 procedure AddTextual(S: string); 1001 992 var 1002 i: Integer;1003 p: Integer;1004 l: Integer;993 I: Integer; 994 P: Integer; 995 L: Integer; 1005 996 ofs: Integer; 1006 CurrentFormat: Integer;1007 FollowFormat: Integer;997 CurrentFormat: TTextFormat; 998 FollowFormat: TTextFormat; 1008 999 Picpix: Integer; 1009 LinkCategory: Integer; 1000 LinkCategory: TLinkCategory; 1001 CrossLink: Boolean; 1010 1002 LinkIndex: Integer; 1011 1003 RightMargin: Integer; … … 1013 1005 Text: string; 1014 1006 begin 1007 CrossLink := False; 1015 1008 RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL); 1016 1009 FollowFormat := pkNormal; 1017 while s<> '' do1010 while S <> '' do 1018 1011 begin 1019 1012 Picpix := 0; 1020 LinkCategory := 0;1013 LinkCategory := hkNoLink; 1021 1014 LinkIndex := 0; 1022 if s[1] = '$' then1023 begin // window caption1024 p:= 1;1015 if S[1] = '$' then 1016 begin // Window caption 1017 P := 1; 1025 1018 repeat 1026 inc(p)1027 until ( p > Length(s)) or (s[p] = '\');1028 Caption := Copy( s, 2, p- 2);1029 Delete( s, 1, p);1019 Inc(P); 1020 until (P > Length(S)) or (S[P] = '\'); 1021 Caption := Copy(S, 2, P - 2); 1022 Delete(S, 1, P); 1030 1023 end 1031 else if s[1] = '&' then1032 begin // standard block1033 p:= 1;1024 else if S[1] = '&' then 1025 begin // Standard block 1026 P := 1; 1034 1027 repeat 1035 inc(p)1036 until ( p > Length(s)) or (s[p] = '\');1037 AddStandardBlock(Copy( s, 2, p- 2));1038 Delete( s, 1, p);1028 Inc(P); 1029 until (P > Length(S)) or (S[P] = '\'); 1030 AddStandardBlock(Copy(S, 2, P - 2)); 1031 Delete(S, 1, P); 1039 1032 end 1040 else if s[1] = '@' then1041 begin // image1042 if (Length( s) >= 2) and (s[2] = '@') then1043 begin // generate from icon1033 else if S[1] = '@' then 1034 begin // Image 1035 if (Length(S) >= 2) and (S[2] = '@') then 1036 begin // Generate from icon 1044 1037 Picpix := 0; 1045 p:= 3;1046 while ( p <= Length(s)) and (s[p] <> '\') do1038 P := 3; 1039 while (P <= Length(S)) and (S[P] <> '\') do 1047 1040 begin 1048 Picpix := Picpix * 10 + Ord( s[p]) - 48;1049 inc(p)1041 Picpix := Picpix * 10 + Ord(S[P]) - 48; 1042 Inc(P); 1050 1043 end; 1051 1044 if (Picpix < 0) or (Picpix >= nImp) then … … 1057 1050 else 1058 1051 begin // external image 1059 p:= 1;1052 P := 1; 1060 1053 repeat 1061 Inc( p)1062 until ( p > Length(s)) or (s[p] = '\');1054 Inc(P); 1055 until (P > Length(S)) or (S[P] = '\'); 1063 1056 if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' + 1064 DirectorySeparator + Copy( s, 2, p- 2)) + '.png') then1057 DirectorySeparator + Copy(S, 2, P - 2)) + '.png') then 1065 1058 begin 1066 1059 MainText.AddLine('', pkExternal); 1067 for i:= 0 to (ExtPic.Height - 12) div 24 do1060 for I := 0 to (ExtPic.Height - 12) div 24 do 1068 1061 MainText.LineFeed; 1069 1062 end; 1070 1063 end; 1071 Delete( s, 1, p);1064 Delete(S, 1, P); 1072 1065 end 1073 1066 else 1074 1067 begin 1075 case s[1] of1068 case S[1] of 1076 1069 ':', ';': 1077 1070 begin // link 1078 p:= 1;1071 P := 1; 1079 1072 repeat 1080 inc(p)1081 until ( p > Length(s)) or (s[p] = '\') or (s[p] = ' ');1082 DecodeItem(Copy( s, 2, p- 2), LinkCategory, LinkIndex);1083 CurrentFormat := 0;1073 Inc(P); 1074 until (P > Length(S)) or (S[P] = '\') or (S[P] = ' '); 1075 DecodeItem(Copy(S, 2, P - 2), LinkCategory, LinkIndex); 1076 CurrentFormat := pkNormal; 1084 1077 if (LinkCategory <> hkText) and (LinkIndex < 200) then 1085 1078 // show icon … … 1088 1081 begin 1089 1082 CurrentFormat := pkAdvIcon; 1090 Picpix := LinkIndex 1083 Picpix := LinkIndex; 1091 1084 end; 1092 1085 hkImp: 1093 1086 begin 1094 1087 CurrentFormat := pkSmallIcon; 1095 Picpix := LinkIndex 1088 Picpix := LinkIndex; 1096 1089 end; 1097 1090 hkTer: … … 1103 1096 begin 1104 1097 CurrentFormat := pkFeature; 1105 Picpix := LinkIndex 1098 Picpix := LinkIndex; 1106 1099 end; 1107 1100 hkModel: … … 1112 1105 end; 1113 1106 end; 1114 if s[1] = ':' then1115 LinkCategory := LinkCategory + hkCrossLink;1116 if ( p > Length(s)) or (s[p] = ' ') then1117 Delete( s, 1, p)1107 if S[1] = ':' then 1108 CrossLink := True; 1109 if (P > Length(S)) or (S[P] = ' ') then 1110 Delete(S, 1, P) 1118 1111 else 1119 Delete( s, 1, p- 1)1120 end; 1121 '!': // highli ted1122 if (Length( s) >= 2) and (s[2] = '!') then1112 Delete(S, 1, P - 1) 1113 end; 1114 '!': // highlighted 1115 if (Length(S) >= 2) and (S[2] = '!') then 1123 1116 begin 1124 1117 if MainText.Count > 1 then … … 1126 1119 FollowFormat := pkCaption; 1127 1120 CurrentFormat := pkCaption; 1128 Delete( s, 1, 2);1121 Delete(S, 1, 2); 1129 1122 end 1130 1123 else … … 1132 1125 FollowFormat := pkSection; 1133 1126 CurrentFormat := pkSection; 1134 Delete( s, 1, 1);1127 Delete(S, 1, 1); 1135 1128 end; 1136 1129 '-': … … 1138 1131 FollowFormat := pkNormal_Dot; 1139 1132 CurrentFormat := pkDot; 1140 Delete( s, 1, 1);1133 Delete(S, 1, 1); 1141 1134 end; 1142 1135 else … … 1147 1140 else 1148 1141 ofs := 8; 1149 p:= 0;1142 P := 0; 1150 1143 repeat 1151 1144 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)) <=1145 Inc(P) 1146 until (P > Length(S)) or (S[P] = ' ') or (S[P] = '\'); 1147 if (BiColorTextWidth(OffScreen.Canvas, Copy(S, 1, P - 1)) <= 1155 1148 RightMargin - ofs) then 1156 l := p- 11149 L := P - 1 1157 1150 else 1158 1151 Break; 1159 until ( p >= Length(s)) or (s[l+ 1] = '\');1160 Text := Copy( s, 1, l);1161 if LinkCategory and $3f= hkInternet then begin1152 until (P >= Length(S)) or (S[L + 1] = '\'); 1153 Text := Copy(S, 1, L); 1154 if LinkCategory = hkInternet then begin 1162 1155 if LinkIndex = 1 then Text := AITemplateManual 1163 1156 else if LinkIndex = 2 then Text := CevoHomepageShort … … 1165 1158 end; 1166 1159 MainText.AddLine(Text, CurrentFormat, Picpix, LinkCategory, 1167 LinkIndex );1168 if ( l < Length(s)) and (s[l+ 1] = '\') then1160 LinkIndex, CrossLink); 1161 if (L < Length(S)) and (S[L + 1] = '\') then 1169 1162 FollowFormat := pkNormal; 1170 Delete( s, 1, l+ 1);1171 end 1172 end 1163 Delete(S, 1, L + 1); 1164 end; 1165 end; 1173 1166 end; 1174 1167 … … 1178 1171 end; 1179 1172 1180 procedure AddModelText( i: Integer);1173 procedure AddModelText(I: Integer); 1181 1174 var 1182 1175 pix: Integer; 1183 s: string;1176 S: string; 1184 1177 begin 1185 1178 with MainText do begin … … 1188 1181 LineFeed; 1189 1182 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);1183 FindStdModelPicture(SpecialModelPictureCode[I], pix, S); 1184 AddLine(S, pkSection); 1185 AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[I].Attack, 1186 SpecialModel[I].Defense]), pkNormal_64); 1194 1187 AddLine(Format(HelpText.Lookup('SPEED'), 1195 [MovementToString(SpecialModel[ i].Speed)]), pkModel, pix);1188 [MovementToString(SpecialModel[I].Speed)]), pkModel, pix); 1196 1189 if Difficulty = 0 then 1197 AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[ i].Cost]),1190 AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[I].Cost]), 1198 1191 pkNormal_64) 1199 1192 else 1200 1193 AddLine(Format(HelpText.Lookup('BUILDCOST'), 1201 [SpecialModel[ i].Cost * BuildCostMod[Difficulty] div 12]),1194 [SpecialModel[I].Cost * BuildCostMod[Difficulty] div 12]), 1202 1195 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 then1196 S := HelpText.LookupByHandle(hSPECIALMODEL, I); 1197 if (S <> '') and (S <> '*') then 1198 AddTextual(S); 1199 if SpecialModelPreq[I] >= 0 then 1200 AddPreqAdv(SpecialModelPreq[I]) 1201 else if SpecialModelPreq[I] = preLighthouse then 1209 1202 AddPreqImp(woLighthouse) 1210 else if SpecialModelPreq[ i] = preBuilder then1203 else if SpecialModelPreq[I] = preBuilder then 1211 1204 AddPreqImp(woPyramids) 1212 else if SpecialModelPreq[ i] = preLeo then1205 else if SpecialModelPreq[I] = preLeo then 1213 1206 AddPreqImp(woLeo); 1214 if SpecialModelPreq[ i] <> preNone then1207 if SpecialModelPreq[I] <> preNone then 1215 1208 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1216 1209 [MainText[Count - 1]]); … … 1220 1213 procedure AddJobList; 1221 1214 var 1222 i, JobCost: Integer;1215 I, JobCost: Integer; 1223 1216 begin 1224 1217 with MainText do begin 1225 for i := 0 to nJobHelp- 1 do begin1226 if i> 0 then begin1218 for I := 0 to Length(JobHelp) - 1 do begin 1219 if I > 0 then begin 1227 1220 LineFeed; 1228 1221 LineFeed; 1229 1222 end; 1230 AddLine(Phrases.Lookup('JOBRESULT', JobHelp[ i]), pkSection);1223 AddLine(Phrases.Lookup('JOBRESULT', JobHelp[I]), pkSection); 1231 1224 AddLine; 1232 AddLine('', pkTerImp, i);1225 AddLine('', pkTerImp, I); 1233 1226 AddLine; 1234 AddTextual(HelpText.LookupByHandle(hJOBHELP, i));1227 AddTextual(HelpText.LookupByHandle(hJOBHELP, I)); 1235 1228 JobCost := -1; 1236 case JobHelp[ i] of1229 case JobHelp[I] of 1237 1230 jCanal: JobCost := CanalWork; 1238 1231 jFort: JobCost := FortWork; … … 1244 1237 else 1245 1238 AddTextual(HelpText.Lookup('JOBCOSTVAR')); 1246 if JobPreq[JobHelp[ i]] <> preNone then begin1247 AddPreqAdv(JobPreq[JobHelp[ i]]);1239 if JobPreq[JobHelp[I]] <> preNone then begin 1240 AddPreqAdv(JobPreq[JobHelp[I]]); 1248 1241 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1249 1242 [MainText[Count - 1]]); … … 1255 1248 procedure AddGraphicCredits; 1256 1249 var 1257 i: Integer;1258 s: string;1250 I: Integer; 1251 S: string; 1259 1252 sr: TSearchRec; 1260 1253 List, Plus: TStringList; … … 1271 1264 1272 1265 List.Sort; 1273 i:= 1;1274 while i< List.Count do1275 if List[ i] = List[i- 1] then1276 List.Delete( i)1266 I := 1; 1267 while I < List.Count do 1268 if List[I] = List[I - 1] then 1269 List.Delete(I) 1277 1270 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 -1271 Inc(I); 1272 1273 for I := 0 to List.Count - 1 do begin 1274 S := List[I]; 1275 while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 - 1283 1276 DpiGetSystemMetrics(SM_CXVSCROLL) do 1284 Delete( s, length(s), 1);1285 MainText.AddLine( s);1277 Delete(S, Length(S), 1); 1278 MainText.AddLine(S); 1286 1279 end; 1287 1280 FreeAndNil(List); … … 1290 1283 procedure AddSoundCredits; 1291 1284 var 1292 i: Integer;1293 s: string;1285 I: Integer; 1286 S: string; 1294 1287 List: TStringList; 1295 1288 begin 1296 1289 List := TStringList.Create; 1297 1290 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 -1291 for I := 0 to List.Count - 1 do begin 1292 S := List[I]; 1293 while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 - 1301 1294 DpiGetSystemMetrics(SM_CXVSCROLL) do 1302 Delete( s, length(s), 1);1303 MainText.AddLine( s);1295 Delete(S, Length(S), 1); 1296 MainText.AddLine(S); 1304 1297 end; 1305 1298 FreeAndNil(List); … … 1323 1316 Clear; 1324 1317 Headline := -1; 1325 if ( no >= 200) or not(Kind in [hkAdv, hkImp, hkTer, hkFeature]) then1318 if (No >= 200) or not (Kind in [hkAdv, hkImp, hkTer, hkFeature]) then 1326 1319 LineFeed; 1327 1320 case Kind of 1328 1321 hkText: 1329 AddTextual(HelpText.LookupByHandle( no));1322 AddTextual(HelpText.LookupByHandle(No)); 1330 1323 hkMisc: 1331 1324 begin 1332 case no of1333 miscMain:1325 case No of 1326 Integer(miscMain): 1334 1327 begin 1335 1328 Caption := HelpText.Lookup('HELPTITLE_MAIN'); 1336 1329 AddLine(HelpText.Lookup('HELPTITLE_QUICKSTART'), pkSpecialIcon, 1337 0, { pkBigIcon,22, } hkText, HelpText.Get handle('QUICK'));1330 0, { pkBigIcon,22, } hkText, HelpText.GetHandle('QUICK')); 1338 1331 LineFeed; 1339 1332 AddLine(HelpText.Lookup('HELPTITLE_CONCEPTS'), pkBigIcon, 6, … … 1344 1337 LineFeed; 1345 1338 AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkSpecialIcon, 2, 1346 hkMisc, miscJobList);1339 hkMisc, Integer(miscJobList)); 1347 1340 LineFeed; 1348 1341 AddLine(HelpText.Lookup('HELPTITLE_TECHLIST'), pkBigIcon, 39, 1349 1342 hkAdv, 200); 1350 1343 LineFeed; 1351 FindStdModelPicture(SpecialModelPictureCode[6], i, s);1352 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, i,1344 FindStdModelPicture(SpecialModelPictureCode[6], I, S); 1345 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, I, 1353 1346 hkModel, 0); 1354 1347 LineFeed; … … 1366 1359 LineFeed; 1367 1360 AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkBigIcon, 1368 gDemocracy + 6, hkMisc, miscGovList);1361 gDemocracy + 6, hkMisc, Integer(miscGovList)); 1369 1362 LineFeed; 1370 1363 AddLine(HelpText.Lookup('HELPTITLE_KEYS'), pkBigIcon, 2, hkText, … … 1375 1368 LineFeed; 1376 1369 AddLine(HelpText.Lookup('HELPTITLE_CREDITS'), pkBigIcon, 22, 1377 hkMisc, miscCredits);1370 hkMisc, Integer(miscCredits)); 1378 1371 end; 1379 miscCredits:1372 Integer(miscCredits): 1380 1373 begin 1381 1374 AddItem('CREDITS'); … … 1390 1383 AddItem('AUTHOR'); 1391 1384 end; 1392 miscJobList:1385 Integer(miscJobList): 1393 1386 begin 1394 1387 Caption := HelpText.Lookup('HELPTITLE_JOBLIST'); … … 1399 1392 AddItem('TERIMPCITY'); 1400 1393 end; 1401 miscGovList:1394 Integer(miscGovList): 1402 1395 begin 1403 1396 Caption := HelpText.Lookup('HELPTITLE_GOVLIST'); 1404 for i:= 1 to nGov do1397 for I := 1 to nGov do 1405 1398 begin 1406 AddLine(Phrases.Lookup('GOVERNMENT', imod nGov), pkSection);1399 AddLine(Phrases.Lookup('GOVERNMENT', I mod nGov), pkSection); 1407 1400 LineFeed; 1408 if i= nGov then1401 if I = nGov then 1409 1402 AddLine('', pkBigIcon, 7 * SystemIconLines + imPalace) 1410 1403 else 1411 AddLine('', pkBigIcon, i+ 6);1404 AddLine('', pkBigIcon, I + 6); 1412 1405 LineFeed; 1413 AddTextual(HelpText.LookupByHandle(hGOVHELP, imod nGov));1414 if imod nGov >= 2 then1406 AddTextual(HelpText.LookupByHandle(hGOVHELP, I mod nGov)); 1407 if I mod nGov >= 2 then 1415 1408 begin 1416 AddPreqAdv(GovPreq[ imod nGov]);1409 AddPreqAdv(GovPreq[I mod nGov]); 1417 1410 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1418 1411 [MainText[Count - 1]]); 1419 1412 end; 1420 if i< nGov then1413 if I < nGov then 1421 1414 begin 1422 1415 LineFeed; … … 1425 1418 end; 1426 1419 end; 1427 miscSearchResult:1420 Integer(miscSearchResult): 1428 1421 begin 1429 1422 Caption := HelpText.Lookup('HELPTITLE_SEARCHRESULTS'); … … 1431 1424 MainText.AppendList(SearchResult); 1432 1425 end; 1433 end; // case no1426 end; // case No 1434 1427 end; 1435 1428 1436 1429 hkAdv: 1437 if no = 200 then1430 if No = 200 then 1438 1431 begin // complete advance list 1439 1432 Caption := HelpText.Lookup('HELPTITLE_TECHLIST'); 1440 1433 List := THyperText.Create; 1441 1434 List.OwnsObjects := True; 1442 for j:= 0 to 3 do1435 for J := 0 to 3 do 1443 1436 begin 1444 if j> 0 then1437 if J > 0 then 1445 1438 begin 1446 1439 LineFeed; 1447 1440 LineFeed; 1448 1441 end; 1449 AddLine(HelpText.Lookup('TECHAGE', j), pkSection);1450 if j= 1 then1442 AddLine(HelpText.Lookup('TECHAGE', J), pkSection); 1443 if J = 1 then 1451 1444 AddLine(Phrases.Lookup('ADVANCES', adScience) + ' ' + 1452 1445 HelpText.Lookup('BASETECH'), pkAdvIcon, adScience, hkAdv, 1453 1446 adScience); 1454 if j= 2 then1447 if J = 2 then 1455 1448 AddLine(Phrases.Lookup('ADVANCES', adMassProduction) + ' ' + 1456 1449 HelpText.Lookup('BASETECH'), pkAdvIcon, adMassProduction, hkAdv, 1457 1450 adMassProduction); 1458 1451 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);1452 for I := 0 to nAdv - 1 do 1453 if (I <> adScience) and (I <> adMassProduction) and 1454 (AdvValue[I] div 1000 = J) then 1455 List.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I, 1456 hkAdv, I); 1464 1457 List.Sort; 1465 1458 AppendList(List); … … 1469 1462 else // single advance 1470 1463 begin 1471 Caption := Phrases.Lookup('ADVANCES', no);1464 Caption := Phrases.Lookup('ADVANCES', No); 1472 1465 LineFeed; 1473 AddLine(Phrases.Lookup('ADVANCES', no), pkCaption);1474 if no in FutureTech then1466 AddLine(Phrases.Lookup('ADVANCES', No), pkCaption); 1467 if No in FutureTech then 1475 1468 begin 1476 1469 AddLine(HelpText.Lookup('HELPSPEC_FUTURE')); 1477 1470 LineFeed; 1478 if no = futResearchTechnology then1471 if No = futResearchTechnology then 1479 1472 AddItem('FUTURETECHHELP100') 1480 1473 else … … 1483 1476 else 1484 1477 AddLine(HelpText.Lookup('HELPSPEC_ADV')); 1485 if AdvPreq[ no, 2] <> preNone then1478 if AdvPreq[No, 2] <> preNone then 1486 1479 NextSection('PREREQALT') 1487 1480 else 1488 1481 NextSection('PREREQ'); 1489 for i:= 0 to 2 do1490 if AdvPreq[ no, i] <> preNone then1491 AddPreqAdv(AdvPreq[ no, i]);1482 for I := 0 to 2 do 1483 if AdvPreq[No, I] <> preNone then 1484 AddPreqAdv(AdvPreq[No, I]); 1492 1485 NextSection('GOVALLOW'); 1493 for i:= 2 to nGov - 1 do1494 if GovPreq[ i] = no then1495 AddLine(Phrases.Lookup('GOVERNMENT', i), pkGov, i,1496 hkMisc + hkCrossLink, miscGovList);1486 for I := 2 to nGov - 1 do 1487 if GovPreq[I] = No then 1488 AddLine(Phrases.Lookup('GOVERNMENT', I), pkGov, I, 1489 hkMisc, Integer(miscGovList), True); 1497 1490 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);1491 for I := 0 to nWonder - 1 do 1492 if Imp[I].Preq = No then 1493 AddImprovement(I); 1494 for I := nWonder to nImp - 1 do 1495 if (Imp[I].Preq = No) and (Imp[I].Kind <> ikCommon) then 1496 AddImprovement(I); 1497 for I := nWonder to nImp - 1 do 1498 if (Imp[I].Preq = No) and (Imp[I].Kind = ikCommon) then 1499 AddImprovement(I); 1507 1500 NextSection('MODELALLOW'); 1508 for i:= 0 to nSpecialModel - 1 do1509 if SpecialModelPreq[ i] = no then1510 AddModel( i);1501 for I := 0 to nSpecialModel - 1 do 1502 if SpecialModelPreq[I] = No then 1503 AddModel(I); 1511 1504 NextSection('FEATALLOW'); 1512 for i:= 0 to nFeature - 1 do1513 if Feature[ i].Preq = no then1514 AddFeature( i);1505 for I := 0 to nFeature - 1 do 1506 if Feature[I].Preq = No then 1507 AddFeature(I); 1515 1508 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);1509 for I := 0 to nAdv - 1 do 1510 if (AdvPreq[I, 0] = No) or (AdvPreq[I, 1] = No) or 1511 (AdvPreq[I, 2] = No) then 1512 AddAdvance(I); 1520 1513 NextSection('UPGRADEALLOW'); 1521 1514 for Domain := 0 to nDomains - 1 do 1522 for i:= 1 to nUpgrade - 1 do1523 if upgrade[Domain, i].Preq = no then1515 for I := 1 to nUpgrade - 1 do 1516 if upgrade[Domain, I].Preq = No then 1524 1517 begin 1525 if upgrade[Domain, i].Strength > 0 then1518 if upgrade[Domain, I].Strength > 0 then 1526 1519 AddLine(Format(HelpText.Lookup('STRENGTHUP'), 1527 1520 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, 1528 i].Strength]), pkDomain, Domain);1529 if upgrade[Domain, i].Trans > 0 then1521 I].Strength]), pkDomain, Domain); 1522 if upgrade[Domain, I].Trans > 0 then 1530 1523 AddLine(Format(HelpText.Lookup('TRANSUP'), 1531 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, i].Trans]1524 [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, I].Trans] 1532 1525 ), pkDomain, Domain); 1533 if no in FutureTech then1526 if No in FutureTech then 1534 1527 AddLine(Format(HelpText.Lookup('COSTUP'), 1535 [upgrade[Domain, i].Cost]), pkNormal_Dot)1528 [upgrade[Domain, I].Cost]), pkNormal_Dot) 1536 1529 else 1537 1530 AddLine(Format(HelpText.Lookup('COSTMIN'), 1538 [upgrade[Domain, i].Cost]), pkNormal_Dot)1531 [upgrade[Domain, I].Cost]), pkNormal_Dot) 1539 1532 end; 1540 1533 NextSection('EXPIRATION'); 1541 for i:= 0 to nWonder - 1 do1542 if (Imp[ i].Preq <> preNA) and (Imp[i].Expiration = no) then1543 AddImprovement( i);1534 for I := 0 to nWonder - 1 do 1535 if (Imp[I].Preq <> preNA) and (Imp[I].Expiration = No) then 1536 AddImprovement(I); 1544 1537 NextSection('ADVEFFECT'); 1545 s := HelpText.LookupByHandle(hADVHELP, no);1546 if s<> '*' then1547 AddTextual( s);1538 S := HelpText.LookupByHandle(hADVHELP, No); 1539 if S <> '*' then 1540 AddTextual(S); 1548 1541 NextSection('SEEALSO'); 1549 CheckSeeAlso := true1542 CheckSeeAlso := True; 1550 1543 end; 1551 1544 1552 1545 hkImp: 1553 if no = 200 then1546 if No = 200 then 1554 1547 begin // complete city improvement list 1555 1548 Caption := HelpText.Lookup('HELPTITLE_IMPLIST'); … … 1557 1550 List := THyperText.Create; 1558 1551 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);1552 for I := nWonder to nImp - 1 do 1553 if (I <> imTrGoods) and (Imp[I].Preq <> preNA) and 1554 (Imp[I].Kind = ikCommon) then 1555 List.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, 1556 I, hkImp, I); 1564 1557 List.Sort; 1565 1558 AppendList(List); 1566 1559 FreeAndNil(List); 1567 1560 end 1568 else if no = 201 then1561 else if No = 201 then 1569 1562 begin // complete nat. project list 1570 1563 Caption := HelpText.Lookup('HELPTITLE_UNIQUELIST'); 1571 1564 // 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);1565 for I := nWonder to nImp - 1 do 1566 if (Imp[I].Preq <> preNA) and 1567 ((Imp[I].Kind = ikNatLocal) or (Imp[I].Kind = ikNatGlobal)) then 1568 AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 1569 hkImp, I); 1577 1570 { LineFeed; 1578 1571 LineFeed; 1579 1572 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); }1573 for I:= nWonder to nImp-1 do 1574 if (Imp[I].Preq<>preNA) and (Imp[I].Kind=ikShipPart) then 1575 AddLine(Phrases.Lookup('IMPROVEMENTS',I),pkSmallIcon,I,hkImp,I); } 1583 1576 end 1584 else if no = 202 then1577 else if No = 202 then 1585 1578 begin // complete wonder list 1586 1579 Caption := HelpText.Lookup('HELPTITLE_WONDERLIST'); 1587 1580 // 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);1581 for I := 0 to nWonder - 1 do 1582 if Imp[I].Preq <> preNA then 1583 AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I, 1584 hkImp, I); 1592 1585 end 1593 1586 else 1594 1587 begin // single building 1595 Caption := Phrases.Lookup('IMPROVEMENTS', no);1588 Caption := Phrases.Lookup('IMPROVEMENTS', No); 1596 1589 LineFeed; 1597 AddLine(Phrases.Lookup('IMPROVEMENTS', no), pkRightIcon, no);1598 case Imp[ no].Kind of1590 AddLine(Phrases.Lookup('IMPROVEMENTS', No), pkRightIcon, No); 1591 case Imp[No].Kind of 1599 1592 ikWonder: AddLine(HelpText.Lookup('HELPSPEC_WONDER')); 1600 1593 ikCommon: AddLine(HelpText.Lookup('HELPSPEC_IMP')); … … 1603 1596 AddLine(HelpText.Lookup('HELPSPEC_NAT')) 1604 1597 end; 1605 if Imp[ no].Kind <> ikShipPart then begin1598 if Imp[No].Kind <> ikShipPart then begin 1606 1599 NextSection('EFFECT'); 1607 AddTextual(HelpText.LookupByHandle(hIMPHELP, no));1600 AddTextual(HelpText.LookupByHandle(hIMPHELP, No)); 1608 1601 end; 1609 if no = woSun then begin1602 if No = woSun then begin 1610 1603 AddFeature(mcFirst); 1611 1604 AddFeature(mcWill); 1612 1605 AddFeature(mcAcademy); 1613 1606 end; 1614 if ( no < nWonder) and not Phrases2FallenBackToEnglish then1607 if (No < nWonder) and not Phrases2FallenBackToEnglish then 1615 1608 begin 1616 1609 LineFeed; 1617 if Imp[ no].Expiration >= 0 then1610 if Imp[No].Expiration >= 0 then 1618 1611 AddTextual(Phrases2.Lookup('HELP_WONDERMORALE1')) 1619 1612 else 1620 1613 AddTextual(Phrases2.Lookup('HELP_WONDERMORALE2')); 1621 1614 end; 1622 if Imp[ no].Preq <> preNone then1615 if Imp[No].Preq <> preNone then 1623 1616 begin 1624 1617 NextSection('PREREQ'); 1625 AddPreqAdv(Imp[ no].Preq);1618 AddPreqAdv(Imp[No].Preq); 1626 1619 end; 1627 1620 NextSection('COSTS'); 1628 1621 if Difficulty = 0 then 1629 s := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])1622 S := Format(HelpText.Lookup('BUILDCOST'), [Imp[No].Cost]) 1630 1623 else 1631 s:= Format(HelpText.Lookup('BUILDCOST'),1632 [Imp[ no].Cost * BuildCostMod[Difficulty] div 12]);1633 AddLine( s);1634 if Imp[ no].Maint > 0 then1635 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 then1624 S := Format(HelpText.Lookup('BUILDCOST'), 1625 [Imp[No].Cost * BuildCostMod[Difficulty] div 12]); 1626 AddLine(S); 1627 if Imp[No].Maint > 0 then 1628 AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[No].Maint])); 1629 J := 0; 1630 for I := 0 to nImpReplacement - 1 do 1631 if ImpReplacement[I].NewImp = No then 1632 begin 1633 if J = 0 then 1641 1634 begin 1642 1635 NextSection('REPLACE'); 1643 1636 AddItem('REPLACETEXT'); 1644 j:= 1;1637 J := 1; 1645 1638 end; 1646 AddImprovement(ImpReplacement[ i].OldImp);1647 end; 1648 if Imp[ no].Kind = ikShipPart then1639 AddImprovement(ImpReplacement[I].OldImp); 1640 end; 1641 if Imp[No].Kind = ikShipPart then 1649 1642 begin 1650 1643 LineFeed; 1651 if no = imShipComp then1652 i:= 11653 else if no = imShipPow then1654 i:= 21655 else { if no=imShipHab then }1656 i:= 3;1644 if No = imShipComp then 1645 I := 1 1646 else if No = imShipPow then 1647 I := 2 1648 else { if No=imShipHab then } 1649 I := 3; 1657 1650 AddLine(Format(HelpText.Lookup('RAREREQUIRED'), 1658 [Phrases.Lookup('TERRAIN', 3 * 12 + i)]), pkTer, 3 * 12 + i);1651 [Phrases.Lookup('TERRAIN', 3 * 12 + I)]), pkTer, 3 * 12 + I); 1659 1652 end; 1660 if ( no < nWonder) and (Imp[no].Expiration >= 0) then1653 if (No < nWonder) and (Imp[No].Expiration >= 0) then 1661 1654 begin 1662 1655 NextSection('EXPIRATION'); 1663 s:= Format(HelpText.Lookup('EXPWITH'),1664 [Phrases.Lookup('ADVANCES', Imp[ no].Expiration)]);1665 if no = woPyramids then1666 s := s+ ' ' + HelpText.Lookup('EXPSLAVE');1667 AddTextual( s);1656 S := Format(HelpText.Lookup('EXPWITH'), 1657 [Phrases.Lookup('ADVANCES', Imp[No].Expiration)]); 1658 if No = woPyramids then 1659 S := S + ' ' + HelpText.Lookup('EXPSLAVE'); 1660 AddTextual(S); 1668 1661 end; 1669 1662 NextSection('SEEALSO'); 1670 if ( no < nWonder) and (Imp[no].Expiration >= 0) then1663 if (No < nWonder) and (Imp[No].Expiration >= 0) then 1671 1664 AddImprovement(woEiffel); 1672 for i:= 0 to nImpReplacement - 1 do1673 if ImpReplacement[ i].OldImp = no then1674 AddImprovement(ImpReplacement[ i].NewImp);1675 if no = imSupermarket then1665 for I := 0 to nImpReplacement - 1 do 1666 if ImpReplacement[I].OldImp = No then 1667 AddImprovement(ImpReplacement[I].NewImp); 1668 if No = imSupermarket then 1676 1669 AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0, 1677 hkMisc + hkCrossLink, miscJobList);1678 CheckSeeAlso := true;1670 hkMisc, Integer(miscJobList), True); 1671 CheckSeeAlso := True; 1679 1672 end; 1680 1673 1681 1674 hkTer: 1682 if no = 200 then1675 if No = 200 then 1683 1676 begin // complete terrain type list 1684 1677 Caption := HelpText.Lookup('HELPTITLE_TERLIST'); 1685 1678 // AddLine(HelpText.Lookup('HELPTITLE_TERLIST'),pkSection); 1686 for i := 0 to nTerrainHelp- 1 do1687 AddTerrain(TerrainHelp[ i]);1679 for I := 0 to Length(TerrainHelp) - 1 do 1680 AddTerrain(TerrainHelp[I]); 1688 1681 end 1689 1682 else 1690 1683 begin // sigle terrain type 1691 TerrType := no mod 12;1684 TerrType := No mod 12; 1692 1685 if TerrType = fJungle then 1693 1686 TerrType := fForest; 1694 TerrSubType := no div 12;1695 if no = 3 * 12 then1687 TerrSubType := No div 12; 1688 if No = 3 * 12 then 1696 1689 begin 1697 1690 TerrType := fDesert; … … 1700 1693 with Terrain[TerrType] do 1701 1694 begin 1702 Caption := Phrases.Lookup('TERRAIN', no);1695 Caption := Phrases.Lookup('TERRAIN', No); 1703 1696 LineFeed; 1704 AddLine(Phrases.Lookup('TERRAIN', no), pkBigTer, no);1697 AddLine(Phrases.Lookup('TERRAIN', No), pkBigTer, No); 1705 1698 AddLine(HelpText.Lookup('HELPSPEC_TER')); 1706 1699 LineFeed; … … 1708 1701 AddLine(Format(HelpText.Lookup('RESPROD'), 1709 1702 [ProdRes[TerrSubType]])); 1710 if ( no < 3 * 12) and (MineEff > 0) then1703 if (No < 3 * 12) and (MineEff > 0) then 1711 1704 MainText[Count - 1] := MainText[Count - 1] + ' ' + 1712 1705 Format(HelpText.Lookup('MOREMINE'), [MineEff]); … … 1714 1707 AddLine(Format(HelpText.Lookup('RESFOOD'), 1715 1708 [FoodRes[TerrSubType]])); 1716 if ( no < 3 * 12) and (IrrEff > 0) then1709 if (No < 3 * 12) and (IrrEff > 0) then 1717 1710 MainText[Count - 1] := MainText[Count - 1] + ' ' + 1718 1711 Format(HelpText.Lookup('MOREIRR'), [IrrEff]); … … 1728 1721 else 1729 1722 AddLine(HelpText.Lookup('MOVEPLAIN')); 1730 if no = 3 * 12 then1723 if No = 3 * 12 then 1731 1724 begin 1732 1725 LineFeed; 1733 1726 AddTextual(HelpText.Lookup('DEADLANDS')); 1734 1727 end; 1735 if (TerrType = fDesert) and ( no <> fDesert + 12) then1728 if (TerrType = fDesert) and (No <> fDesert + 12) then 1736 1729 begin 1737 1730 LineFeed; … … 1743 1736 AddTextual(Format(HelpText.Lookup('HOSTILE'), [ArcticThurst])); 1744 1737 end; 1745 if ( no < 3 * 12) and (TransTerrain >= 0) then1738 if (No < 3 * 12) and (TransTerrain >= 0) then 1746 1739 begin 1747 1740 LineFeed; 1748 i:= TransTerrain;1749 if (TerrType <> fGrass) and ( i<> fGrass) then1750 i := i+ TerrSubType * 12;1741 I := TransTerrain; 1742 if (TerrType <> fGrass) and (I <> fGrass) then 1743 I := I + TerrSubType * 12; 1751 1744 // trafo to same Special resource group 1752 1745 AddLine(Format(HelpText.Lookup('TRAFO'), 1753 [Phrases.Lookup('TERRAIN', i)]), pkTer, i,1754 hkTer + hkCrossLink, i);1755 if no = fSwamp + 12 then1746 [Phrases.Lookup('TERRAIN', I)]), pkTer, I, 1747 hkTer, I, True); 1748 if No = fSwamp + 12 then 1756 1749 begin 1757 1750 LineFeed; 1758 1751 AddLine(Format(HelpText.Lookup('TRAFO'), 1759 1752 [Phrases.Lookup('TERRAIN', TransTerrain + 24)]), pkTer, 1760 TransTerrain + 24, hkTer + hkCrossLink, TransTerrain + 24);1753 TransTerrain + 24, hkTer, TransTerrain + 24, True); 1761 1754 end 1762 else if i= fGrass then1755 else if I = fGrass then 1763 1756 begin 1764 1757 LineFeed; 1765 1758 AddLine(Format(HelpText.Lookup('TRAFO'), 1766 1759 [Phrases.Lookup('TERRAIN', fGrass + 12)]), pkTer, fGrass + 12, 1767 hkTer + hkCrossLink, fGrass + 12);1760 hkTer, fGrass + 12, True); 1768 1761 end; 1769 1762 end; 1770 1763 NextSection('SPECIAL'); 1771 if no = 3 * 12 then1764 if No = 3 * 12 then 1772 1765 begin 1773 1766 LineFeed; … … 1780 1773 end; 1781 1774 end 1782 else if ( no < 12) and (no <> fGrass) and (no <> fOcean) then1775 else if (No < 12) and (No <> fGrass) and (No <> fOcean) then 1783 1776 begin 1784 1777 LineFeed; 1785 1778 for Special := 1 to 2 do 1786 if ( no <> fArctic) and (no <> fSwamp) or (Special < 2) then1779 if (No <> fArctic) and (No <> fSwamp) or (Special < 2) then 1787 1780 begin 1788 1781 if Special > 1 then 1789 1782 LineFeed; 1790 AddLine(Phrases.Lookup('TERRAIN', no + Special * 12), pkTer,1791 no + Special * 12);1792 i:= FoodRes[Special] - FoodRes[0];1793 if i<> 0 then1783 AddLine(Phrases.Lookup('TERRAIN', No + Special * 12), pkTer, 1784 No + Special * 12); 1785 I := FoodRes[Special] - FoodRes[0]; 1786 if I <> 0 then 1794 1787 MainText[Count - 1] := MainText[Count - 1] + 1795 Format(HelpText.Lookup('SPECIALFOOD'), [ i]);1796 i:= ProdRes[Special] - ProdRes[0];1797 if i<> 0 then1788 Format(HelpText.Lookup('SPECIALFOOD'), [I]); 1789 I := ProdRes[Special] - ProdRes[0]; 1790 if I <> 0 then 1798 1791 MainText[Count - 1] := MainText[Count - 1] + 1799 Format(HelpText.Lookup('SPECIALPROD'), [ i]);1800 i:= TradeRes[Special] - TradeRes[0];1801 if i<> 0 then1792 Format(HelpText.Lookup('SPECIALPROD'), [I]); 1793 I := TradeRes[Special] - TradeRes[0]; 1794 if I <> 0 then 1802 1795 MainText[Count - 1] := MainText[Count - 1] + 1803 Format(HelpText.Lookup('SPECIALTRADE'), [ i]);1796 Format(HelpText.Lookup('SPECIALTRADE'), [I]); 1804 1797 end; 1805 1798 end; 1806 if no = 3 * 12 then1799 if No = 3 * 12 then 1807 1800 begin 1808 1801 LineFeed; 1809 1802 AddTextual(HelpText.Lookup('RARE')); 1810 1803 end; 1811 if ( no < 3 * 12) and (TerrType in [fDesert, fArctic]) then1804 if (No < 3 * 12) and (TerrType in [fDesert, fArctic]) then 1812 1805 begin 1813 1806 NextSection('SEEALSO'); 1814 1807 AddImprovement(woGardens); 1815 CheckSeeAlso := true1808 CheckSeeAlso := True; 1816 1809 end; 1817 1810 end; … … 1819 1812 1820 1813 hkFeature: 1821 if no = 200 then1814 if No = 200 then 1822 1815 begin // complete feature list 1823 1816 Caption := HelpText.Lookup('HELPTITLE_FEATURELIST'); … … 1837 1830 end; 1838 1831 List.Clear; 1839 for i:= 0 to nFeature - 1 do1840 if Feature[ i].Preq <> preNA then1832 for I := 0 to nFeature - 1 do 1833 if Feature[I].Preq <> preNA then 1841 1834 begin 1842 if i< mcFirstNonCap then1843 j:= 01844 else if iin AutoFeature then1845 j:= 21835 if I < mcFirstNonCap then 1836 J := 0 1837 else if I in AutoFeature then 1838 J := 2 1846 1839 else 1847 j:= 1;1848 if j= Special then1849 List.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,1850 hkFeature, i);1840 J := 1; 1841 if J = Special then 1842 List.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I, 1843 hkFeature, I); 1851 1844 end; 1852 1845 List.Sort; … … 1857 1850 else 1858 1851 begin // single feature 1859 Caption := Phrases.Lookup('FEATURES', no);1852 Caption := Phrases.Lookup('FEATURES', No); 1860 1853 LineFeed; 1861 AddLine(Phrases.Lookup('FEATURES', no), pkBigFeature, no);1862 if no < mcFirstNonCap then1854 AddLine(Phrases.Lookup('FEATURES', No), pkBigFeature, No); 1855 if No < mcFirstNonCap then 1863 1856 AddLine(HelpText.Lookup('HELPSPEC_CAP')) 1864 else if no in AutoFeature then1857 else if No in AutoFeature then 1865 1858 AddLine(HelpText.Lookup('HELPSPEC_STANDARD')) 1866 1859 else 1867 1860 AddLine(HelpText.Lookup('HELPSPEC_FEATURE')); 1868 1861 NextSection('EFFECT'); 1869 AddTextual(HelpText.LookupByHandle(hFEATUREHELP, no));1870 if (Feature[ no].Weight <> 0) or (Feature[no].Cost <> 0) then1862 AddTextual(HelpText.LookupByHandle(hFEATUREHELP, No)); 1863 if (Feature[No].Weight <> 0) or (Feature[No].Cost <> 0) then 1871 1864 begin 1872 1865 NextSection('COSTS'); 1873 s := IntToStr(Feature[no].Cost);1874 if Feature[ no].Cost >= 0 then1875 s := '+' + s;1876 AddLine(Format(HelpText.Lookup('COSTBASE'), [ s]));1877 if Feature[ no].Weight > 0 then1866 S := IntToStr(Feature[No].Cost); 1867 if Feature[No].Cost >= 0 then 1868 S := '+' + S; 1869 AddLine(Format(HelpText.Lookup('COSTBASE'), [S])); 1870 if Feature[No].Weight > 0 then 1878 1871 begin 1879 1872 AddLine(Format(HelpText.Lookup('WEIGHT'), 1880 ['+' + IntToStr(Feature[ no].Weight)]));1881 if no = mcDefense then1873 ['+' + IntToStr(Feature[No].Weight)])); 1874 if No = mcDefense then 1882 1875 AddLine(Format(HelpText.Lookup('WEIGHT'), ['+2']), 1883 1876 pkDomain, dGround); 1884 1877 end; 1885 1878 end; 1886 if Feature[ no].Preq <> preNone then1879 if Feature[No].Preq <> preNone then 1887 1880 begin 1888 1881 LineFeed; 1889 if Feature[ no].Preq = preSun then1882 if Feature[No].Preq = preSun then 1890 1883 AddPreqImp(woSun) // sun tsu feature 1891 1884 else 1892 AddPreqAdv(Feature[ no].Preq);1885 AddPreqAdv(Feature[No].Preq); 1893 1886 MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'), 1894 1887 [MainText[Count - 1]]); … … 1901 1894 begin 1902 1895 Caption := HelpText.Lookup('HELPTITLE_MODELLIST'); 1903 for i:= 0 to nSpecialModel - 1 do1904 if i<> 2 then1905 AddModelText( i);1896 for I := 0 to nSpecialModel - 1 do 1897 if I <> 2 then 1898 AddModelText(I); 1906 1899 LineFeed; 1907 1900 AddItem('MODELNOTE'); … … 1910 1903 end; 1911 1904 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);1905 for I := 0 to Length(SeeAlso) - 1 do 1906 if (SeeAlso[I].Kind = Kind) and (SeeAlso[I].No = No) then 1907 case SeeAlso[I].SeeKind of 1908 hkImp: AddImprovement(SeeAlso[I].SeeNo); 1909 hkAdv: AddAdvance(SeeAlso[I].SeeNo); 1910 hkFeature: AddFeature(SeeAlso[I].SeeNo); 1918 1911 end; 1919 1912 if (Headline >= 0) and (Count = Headline + 1) then … … 1926 1919 ScrollBar.SetPos(sbPos); 1927 1920 BackBtn.Visible := HistItems.Count > 1; 1928 TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or ( no <> miscMain);1921 TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or (No <> Integer(miscMain)); 1929 1922 Sel := -1; 1930 1923 end; // with MainText 1931 1924 end; 1932 1925 1933 procedure THelpDlg.ShowNewContent(NewMode, Category, Index: Integer); 1934 begin 1935 if (Category <> Kind) or (Index <> no) or (Category = hkMisc) and 1936 (Index = miscSearchResult) then begin 1926 procedure THelpDlg.ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory; 1927 Index: Integer); 1928 begin 1929 if (Category <> Kind) or (Index <> No) or (Category = hkMisc) and 1930 (Index = Integer(miscSearchResult)) then begin 1937 1931 if HistItems.Count = MaxHist then HistItems.Delete(0); 1938 1932 if HistItems.Count = 0 then … … 1941 1935 end; 1942 1936 Kind := Category; 1943 no := Index;1937 No := Index; 1944 1938 SearchContent := NewSearchContent; 1945 1939 Prepare; … … 1949 1943 1950 1944 procedure THelpDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; 1951 x, y: integer);1945 X, Y: Integer); 1952 1946 var 1953 1947 i0, Sel0: Integer; 1954 1948 begin 1955 y := y- WideFrame;1949 Y := Y - WideFrame; 1956 1950 i0 := ScrollBar.Position; 1957 1951 Sel0 := Sel; 1958 if ( x >= SideFrame) and (x < SideFrame + InnerWidth) and (y>= 0) and1959 ( y < InnerHeight) and (ymod 24 >= 8) then1960 Sel := ydiv 241952 if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and 1953 (Y < InnerHeight) and (Y mod 24 >= 8) then 1954 Sel := Y div 24 1961 1955 else 1962 1956 Sel := -1; 1963 1957 if (Sel + i0 >= MainText.Count) or (Sel >= 0) and 1964 (THelpLineInfo(MainText.Objects[Sel + i0]).Link = 0) then 1958 (THelpLineInfo(MainText.Objects[Sel + i0]).Category = hkNoLink) and 1959 (THelpLineInfo(MainText.Objects[Sel + i0]).Index = 0)then 1965 1960 Sel := -1; 1966 1961 if Sel <> Sel0 then … … 1974 1969 1975 1970 procedure THelpDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 1976 Shift: TShiftState; x, y: integer);1971 Shift: TShiftState; X, Y: Integer); 1977 1972 begin 1978 1973 if Sel >= 0 then 1979 1974 with THelpLineInfo(MainText.Objects[Sel + ScrollBar.Position]) do 1980 if Link shr 8 and $3F= hkInternet then1981 case Link and $FFof1975 if Category = hkInternet then 1976 case Index of 1982 1977 1: OpenDocument(HomeDir + AITemplateFileName); 1983 1978 2: OpenURL(CevoHomepage); … … 1986 1981 else 1987 1982 begin 1988 if (Link >= $8000) and (Link and $3FFF = liInvalid) then 1989 exit; // invalid link; 1990 if Link >= $8000 then 1991 ShowNewContent(FWindowMode, hkText, Link and $3FFF) 1992 else 1993 ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF); 1983 if Index < 0 then Exit; // invalid link; 1984 ShowNewContent(FWindowMode, Category, Index); 1994 1985 end; 1995 1986 end; … … 2003 1994 HistItem.Assign(HistItems.Last); 2004 1995 HistItems.Delete(HistItems.Count - 1); 2005 if (HistItem.Kind = hkMisc) and (HistItem.No = miscSearchResult) and1996 if (HistItem.Kind = hkMisc) and (HistItem.No = Integer(miscSearchResult)) and 2006 1997 (HistItem.SearchContent <> SearchContent) then 2007 1998 begin … … 2010 2001 end; 2011 2002 Kind := HistItem.Kind; 2012 no := HistItem.No;2003 No := HistItem.No; 2013 2004 Prepare(HistItem.Pos); 2014 2005 OffscreenPaint; … … 2022 2013 while HistItems.Count > 1 do HistItems.Delete(HistItems.Count - 1); 2023 2014 Kind := hkMisc; 2024 no := miscMain;2015 No := Integer(miscMain); 2025 2016 Prepare; 2026 2017 OffscreenPaint; … … 2036 2027 function THelpDlg.TextIndex(Item: string): Integer; 2037 2028 begin 2038 Result := HelpText.Get handle(Item);2029 Result := HelpText.GetHandle(Item); 2039 2030 end; 2040 2031 … … 2064 2055 1: 2065 2056 with THelpLineInfo(SearchResult.Objects[0]) do 2066 if Link >= $8000 then 2067 ShowNewContent(FWindowMode, hkText, Link and $3FFF) 2068 else 2069 ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF); 2070 else 2071 begin 2057 ShowNewContent(FWindowMode, Category, Index); 2058 else begin 2072 2059 NewSearchContent := InputDlg.EInput.Text; 2073 ShowNewContent(FWindowMode, hkMisc, miscSearchResult);2060 ShowNewContent(FWindowMode, hkMisc, Integer(miscSearchResult)); 2074 2061 end; 2075 2062 end; … … 2079 2066 procedure THelpDlg.Search(SearchString: string); 2080 2067 var 2081 h, i, PrevHandle, PrevIndex, p, RightMargin: Integer;2082 s: string;2083 mADVHELP, mIMPHELP, mFEATUREHELP: set of 0 ..255;2068 H, I, PrevHandle, PrevIndex, P, RightMargin: Integer; 2069 S: string; 2070 mADVHELP, mIMPHELP, mFEATUREHELP: set of 0..255; 2084 2071 bGOVHELP, bSPECIALMODEL, bJOBHELP: Boolean; 2085 2072 begin … … 2092 2079 bJOBHELP := False; 2093 2080 2094 // search in generic reference2081 // Search in generic reference 2095 2082 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)2083 for I := 0 to 35 + 4 do begin 2084 S := Phrases.Lookup('TERRAIN', I); 2085 if Pos(SearchString, UpperCase(S)) > 0 then 2086 if I < 36 then 2087 SearchResult.AddLine(S + ' ' + HelpText.Lookup('HELPSPEC_TER'), 2088 pkNormal, 0, hkTer, I, True) 2102 2089 else 2103 2090 begin 2104 2091 SearchResult.AddLine(Phrases.Lookup('TERRAIN', 36) + ' ' + 2105 2092 HelpText.Lookup('HELPSPEC_TER'), pkNormal, 0, 2106 hkTer + hkCrossLink, 36);2107 if i> 36 then2093 hkTer, 36, True); 2094 if I > 36 then 2108 2095 SearchResult.AddLine(Phrases.Lookup('IMPROVEMENTS', 2109 imShipComp + i- 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),2110 pkNormal, 0, hkImp + hkCrossLink, imShipComp + i - 37);2096 imShipComp + I - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'), 2097 pkNormal, 0, hkImp, imShipComp + I - 37, True); 2111 2098 Break; 2112 2099 end; 2113 2100 end; 2114 for i := 0 to nJobHelp- 1 do2115 if pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[i]))) > 02101 for I := 0 to Length(JobHelp) - 1 do 2102 if Pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[I]))) > 0 2116 2103 then 2117 2104 begin 2118 2105 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0, 2119 hkMisc + hkCrossLink, miscJobList);2106 hkMisc, Integer(miscJobList), True); 2120 2107 bJOBHELP := True; 2121 2108 Break; 2122 2109 end; 2123 for i:= 0 to nAdv - 1 do2124 begin 2125 s := Phrases.Lookup('ADVANCES', i);2126 if pos(SearchString, UpperCase(s)) > 0 then2110 for I := 0 to nAdv - 1 do 2111 begin 2112 S := Phrases.Lookup('ADVANCES', I); 2113 if Pos(SearchString, UpperCase(S)) > 0 then 2127 2114 begin 2128 if iin FutureTech then2129 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FUTURE')2115 if I in FutureTech then 2116 S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE') 2130 2117 else 2131 s := s+ ' ' + HelpText.Lookup('HELPSPEC_ADV');2132 SearchResult.AddLine( s, pkNormal, 0, hkAdv + hkCrossLink, i);2133 include(mADVHELP, i);2118 S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV'); 2119 SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True); 2120 Include(mADVHELP, I); 2134 2121 end; 2135 2122 end; 2136 for i:= 0 to nSpecialModel - 1 do2137 begin 2138 FindStdModelPicture(SpecialModelPictureCode[ i], h, s);2139 if pos(SearchString, UpperCase(s)) > 0 then2123 for I := 0 to nSpecialModel - 1 do 2124 begin 2125 FindStdModelPicture(SpecialModelPictureCode[I], H, S); 2126 if Pos(SearchString, UpperCase(S)) > 0 then 2140 2127 begin 2141 2128 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 0, 2142 hkModel + hkCrossLink, 0);2129 hkModel, 0, True); 2143 2130 bSPECIALMODEL := True; 2144 2131 Break; 2145 2132 end; 2146 2133 end; 2147 for i:= 0 to nFeature - 1 do2148 begin 2149 s := Phrases.Lookup('FEATURES', i);2150 if Pos(SearchString, UpperCase( s)) > 0 then2134 for I := 0 to nFeature - 1 do 2135 begin 2136 S := Phrases.Lookup('FEATURES', I); 2137 if Pos(SearchString, UpperCase(S)) > 0 then 2151 2138 begin 2152 if i< mcFirstNonCap then2153 s := s+ ' ' + HelpText.Lookup('HELPSPEC_CAP')2154 else if iin AutoFeature then2155 s := s+ ' ' + HelpText.Lookup('HELPSPEC_STANDARD')2139 if I < mcFirstNonCap then 2140 S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP') 2141 else if I in AutoFeature then 2142 S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD') 2156 2143 else 2157 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FEATURE');2158 SearchResult.AddLine( s, pkNormal, 0, hkFeature + hkCrossLink, i);2159 Include(mFEATUREHELP, i);2144 S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE'); 2145 SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True); 2146 Include(mFEATUREHELP, I); 2160 2147 end; 2161 2148 end; 2162 for i:= 0 to nImp - 1 do2163 begin 2164 s := Phrases.Lookup('IMPROVEMENTS', i);2165 if Pos(SearchString, UpperCase( s)) > 0 then2149 for I := 0 to nImp - 1 do 2150 begin 2151 S := Phrases.Lookup('IMPROVEMENTS', I); 2152 if Pos(SearchString, UpperCase(S)) > 0 then 2166 2153 begin 2167 case Imp[ i].Kind of2154 case Imp[I].Kind of 2168 2155 ikWonder: 2169 s := s+ ' ' + HelpText.Lookup('HELPSPEC_WONDER');2156 S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER'); 2170 2157 ikCommon: 2171 s := s+ ' ' + HelpText.Lookup('HELPSPEC_IMP');2158 S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP'); 2172 2159 ikShipPart: 2173 s := s+ ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');2160 S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'); 2174 2161 else 2175 s := s+ ' ' + HelpText.Lookup('HELPSPEC_NAT')2162 S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT') 2176 2163 end; 2177 SearchResult.AddLine( s, pkNormal, 0, hkImp + hkCrossLink, i);2178 Include(mIMPHELP, i);2164 SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True); 2165 Include(mIMPHELP, I); 2179 2166 end 2180 2167 end; 2181 for i:= 0 to nGov - 1 do2182 if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', i))) > 0 then2168 for I := 0 to nGov - 1 do 2169 if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', I))) > 0 then 2183 2170 begin 2184 2171 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0, 2185 hkMisc + hkCrossLink, miscGovList);2172 hkMisc, Integer(miscGovList), True); 2186 2173 bGOVHELP := True; 2187 2174 Break; 2188 2175 end; 2189 2176 2190 // full text search2191 h:= -1;2177 // Full text search 2178 H := -1; 2192 2179 repeat 2193 PrevHandle := h;2194 PrevIndex := i;2195 if not HelpText.Search(SearchString, h, i) then2180 PrevHandle := H; 2181 PrevIndex := I; 2182 if not HelpText.Search(SearchString, H, I) then 2196 2183 Break; 2197 if h= hADVHELP then2184 if H = hADVHELP then 2198 2185 begin 2199 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2200 not( iin mADVHELP) then2186 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2187 not(I in mADVHELP) then 2201 2188 begin 2202 s := Phrases.Lookup('ADVANCES', i);2203 if iin FutureTech then2204 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FUTURE')2189 S := Phrases.Lookup('ADVANCES', I); 2190 if I in FutureTech then 2191 S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE') 2205 2192 else 2206 s := s+ ' ' + HelpText.Lookup('HELPSPEC_ADV');2207 SearchResult.AddLine( s, pkNormal, 0, hkAdv + hkCrossLink, i)2193 S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV'); 2194 SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True); 2208 2195 end; 2209 2196 end 2210 else if h= hIMPHELP then2197 else if H = hIMPHELP then 2211 2198 begin 2212 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2213 not( iin mIMPHELP) then2199 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2200 not(I in mIMPHELP) then 2214 2201 begin 2215 s := Phrases.Lookup('IMPROVEMENTS', i);2216 case Imp[ i].Kind of2202 S := Phrases.Lookup('IMPROVEMENTS', I); 2203 case Imp[I].Kind of 2217 2204 ikWonder: 2218 s := s+ ' ' + HelpText.Lookup('HELPSPEC_WONDER');2205 S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER'); 2219 2206 ikCommon: 2220 s := s+ ' ' + HelpText.Lookup('HELPSPEC_IMP');2207 S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP'); 2221 2208 ikShipPart: 2222 s := s+ ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');2209 S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'); 2223 2210 else 2224 s := s+ ' ' + HelpText.Lookup('HELPSPEC_NAT')2211 S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT') 2225 2212 end; 2226 SearchResult.AddLine( s, pkNormal, 0, hkImp + hkCrossLink, i)2213 SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True); 2227 2214 end; 2228 2215 end 2229 else if h= hFEATUREHELP then2216 else if H = hFEATUREHELP then 2230 2217 begin 2231 if ( i >= 0) and ((i <> PrevIndex) or (h<> PrevHandle)) and2232 not( iin mFEATUREHELP) then2218 if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and 2219 not(I in mFEATUREHELP) then 2233 2220 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')2221 S := Phrases.Lookup('FEATURES', I); 2222 if I < mcFirstNonCap then 2223 S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP') 2224 else if I in AutoFeature then 2225 S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD') 2239 2226 else 2240 s := s+ ' ' + HelpText.Lookup('HELPSPEC_FEATURE');2241 SearchResult.AddLine( s, pkNormal, 0, hkFeature + hkCrossLink, i);2227 S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE'); 2228 SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True); 2242 2229 end; 2243 2230 end 2244 else if h= hGOVHELP then2231 else if H = hGOVHELP then 2245 2232 begin 2246 if ( i >= 0) and (h<> PrevHandle) and not bGOVHELP then2233 if (I >= 0) and (H <> PrevHandle) and not bGOVHELP then 2247 2234 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0, 2248 hkMisc + hkCrossLink, miscGovList)2235 hkMisc, Integer(miscGovList), True); 2249 2236 end 2250 else if h= hSPECIALMODEL then2237 else if H = hSPECIALMODEL then 2251 2238 begin 2252 if ( i >= 0) and (h<> PrevHandle) and not bSPECIALMODEL then2239 if (I >= 0) and (H <> PrevHandle) and not bSPECIALMODEL then 2253 2240 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 2254 0, hkModel + hkCrossLink, 0)2241 0, hkModel, 0, True); 2255 2242 end 2256 else if h= hJOBHELP then2243 else if H = hJOBHELP then 2257 2244 begin 2258 if ( i >= 0) and (h<> PrevHandle) and not bJOBHELP then2245 if (I >= 0) and (H <> PrevHandle) and not bJOBHELP then 2259 2246 SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0, 2260 hkMisc + hkCrossLink, miscJobList)2247 hkMisc, Integer(miscJobList), True); 2261 2248 end 2262 else if { (h<>hMAIN) and } ( h<> PrevHandle) then2249 else if { (h<>hMAIN) and } (H <> PrevHandle) then 2263 2250 begin 2264 s := HelpText.LookupByHandle(h);2265 p := Pos('$', s);2266 if p> 0 then2251 S := HelpText.LookupByHandle(H); 2252 P := Pos('$', S); 2253 if P > 0 then 2267 2254 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);2255 S := Copy(S, P + 1, MaxInt); 2256 P := Pos('\', S); 2257 if P > 0 then 2258 S := Copy(S, 1, P - 1); 2259 SearchResult.AddLine(S, pkNormal, 0, hkText, H, True); 2273 2260 end; 2274 2261 end; 2275 until False;2276 2277 // cut lines to fit to window2278 RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);2279 OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);2280 for i:= 0 to SearchResult.Count - 1 do2281 begin2282 while BiColorTextWidth(OffScreen.Canvas, SearchResult[i]) >2283 RightMargin - 32 do2284 SearchResult[i] := copy(SearchResult[i], 1, length(SearchResult[i]) - 1)2285 end;2286 end;2262 until False; 2263 2264 // Cut lines to fit to window 2265 RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL); 2266 OffScreen.Canvas.Font.Assign(UniFont[ftNormal]); 2267 for I := 0 to SearchResult.Count - 1 do 2268 begin 2269 while BiColorTextWidth(OffScreen.Canvas, SearchResult[I]) > 2270 RightMargin - 32 do 2271 SearchResult[I] := Copy(SearchResult[I], 1, Length(SearchResult[I]) - 1) 2272 end; 2273 end; 2287 2274 2288 2275 end. -
branches/highdpi/LocalPlayer/IsoEngine.pas
r405 r465 5 5 6 6 uses 7 UDpiControls, Protocol, ClientTools, ScreenTools, Tribes, 8 LCLIntf, LCLType, SysUtils, Classes, Graphics, UPixelPointer, UGraphicSet;7 UDpiControls, Protocol, ClientTools, ScreenTools, Tribes, LCLIntf, LCLType, SysUtils, 8 Classes, Graphics, PixelPointer, GraphicSet; 9 9 10 10 const … … 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: TDpiBitmap; … … 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: TDpiBitmap); 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: TDpiBitmap; 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: TDpiBitmap; 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] := TPixelPointer.Create(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; … … 357 357 DitherMask.SetSize(xxt * 2, yyt * 2); 358 358 DitherMask.Canvas.FillRect(0, 0, DitherMask.Width, DitherMask.Height); 359 DpiBit Canvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,359 DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2, 360 360 HGrTerrain.Mask.Canvas, 1 + 7 * (xxt * 2 + 1), 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 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt,375 for Y := -1 to 6 do 376 DpiBitBltCanvas(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 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt, xxt,378 for Y := -2 to 6 do 379 DpiBitBltCanvas(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 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y+ 2) * yyt,382 for Y := -2 to 6 do 383 DpiBitBltCanvas(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 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt, xxt,386 for Y := -2 to 6 do 387 DpiBitBltCanvas(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 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y+ 2) * yyt,389 for Y := -2 to 6 do 390 DpiBitBltCanvas(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 DpiBit Canvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt,406 for X := -2 to 6 do 407 DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, 408 408 xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc); 409 DpiBit Canvas(LandMore.Canvas, xxt * 2, (y+ 2) * yyt, xxt, yyt,409 DpiBitBltCanvas(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 DpiBit Canvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y+ 2) * yyt,411 for X := 0 to 7 do 412 DpiBitBltCanvas(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 DpiBit Canvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt,415 for X := -2 to 6 do 416 DpiBitBltCanvas(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 DpiBit Canvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,426 if (X >= 1) = (Y >= 2) then 427 DpiBitBltCanvas(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 DpiBit Canvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,431 DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 432 432 HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, 433 433 SRCPAINT); 434 DpiBit Canvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,434 DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt, 435 435 HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT); 436 436 end; 437 DpiBit Canvas(OceanPatch.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,437 DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 438 438 DitherMask.Canvas, xxt, yyt, SRCAND); 439 DpiBit Canvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,439 DpiBitBltCanvas(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 DpiBit Canvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,450 if (X < 1) or (Y >= 2) then 451 DpiBitBltCanvas(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 DpiBit Canvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt, yyt,455 DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt, 456 456 HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, 457 457 SRCPAINT); 458 DpiBit Canvas(OceanMore.Canvas, x * (xxt * 2) + xxt, y* yyt, xxt, yyt,458 DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt, 459 459 HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT); 460 460 end; 461 DpiBit Canvas(OceanMore.Canvas, x * (xxt * 2), y* yyt, xxt * 2, yyt,461 DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt, 462 462 DitherMask.Canvas, 0, 0, SRCAND); 463 463 end; 464 464 end; 465 465 466 DpiBit Canvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,466 DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2, 467 467 DitherMask.Canvas, 0, 0, DSTINVERT); { invert dither mask } 468 DpiBit Canvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,468 DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2, 469 469 HGrTerrain.Mask.Canvas, 1, 1 + yyt, SRCPAINT); 470 470 471 for x:= -1 to 6 do472 for y:= -2 to 6 do473 DpiBit Canvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y+ 2) * yyt,471 for X := -1 to 6 do 472 for Y := -2 to 6 do 473 DpiBitBltCanvas(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 DpiBit Canvas(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 DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt, 479 479 xxt * 2, yyt, DitherMask.Canvas, 0, yyt, SRCAND); 480 480 481 DpiBit Canvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9,481 DpiBitBltCanvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9, 482 482 LandMore.Canvas, 0, 0, SRCPAINT); 483 483 484 for x:= 0 to 3 do485 for y:= 0 to 3 do486 DpiBit Canvas(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 DpiBitBltCanvas(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 DpiBit Canvas(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 DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) - xxt, Y * yyt, xxt * 2, 492 492 yyt, DitherMask.Canvas, 0, yyt, SRCAND); 493 493 494 DpiBit Canvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4,494 DpiBitBltCanvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4, 495 495 OceanMore.Canvas, 0, 0, SRCPAINT); 496 496 … … 499 499 FillRect(Rect(0, 0, xxt * 2, yyt)); 500 500 end; 501 DpiBit Canvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt,501 DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, 502 502 HGrTerrain.Mask.Canvas, 1, 1 + yyt); 503 503 504 for x:= 0 to 6 do505 DpiBit Canvas(LandPatch.Canvas, (x+ 2) * (xxt * 2), yyt, xxt * 2, yyt,504 for X := 0 to 6 do 505 DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), yyt, xxt * 2, yyt, 506 506 DitherMask.Canvas, 0, 0, SRCAND); 507 DpiBit Canvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,507 DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas, 508 508 0, 0, DSTINVERT); 509 509 510 for y:= 0 to 6 do511 DpiBit Canvas(LandPatch.Canvas, xxt * 2, (y+ 2) * yyt, xxt * 2, yyt,510 for Y := 0 to 6 do 511 DpiBitBltCanvas(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: TDpiBitmap; 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: TDpiBitmap; 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 DpiBit Canvas(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 DpiBitBltCanvas(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;656 657 DpiBit Canvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);655 Exit; 656 657 DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND); 658 658 if not PureBlack then 659 DpiBit Canvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT);660 end; 661 662 procedure TIsoMap.PaintUnit( x, y: integer; const UnitInfo: TUnitInfo;663 Status: integer);664 var 665 xsh, ysh, xGr, yGr, j, mixShow: integer;659 DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT); 660 end; 661 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 end; { PaintUnit }722 723 procedure TIsoMap.PaintCity( x, y: integer; const CityInfo: TCityInfo;724 accessory: boolean);721 end; 722 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; { PaintCity }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); 1107 DpiBit Canvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2,1107 DpiBitBltCanvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2, 1108 1108 yyt * 2, HGrTerrain.Data.Canvas, 1109 1109 1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1)); … … 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; { PaintTileObjects }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 Line := PixelPointer(FOutput, ScaleToNative(x0), ScaleToNative(y0));1427 for y:= 0 to ScaleToNative(Height) - 1 do begin1428 y_n := (ScaleFromNative( y) + y0 - ym) / yyt;1426 Line := TPixelPointer.Create(FOutput, ScaleToNative(x0), ScaleToNative(y0)); 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; 1687 1687 1688 1688 // frame(FOutput.Canvas,x+1,y+1,x+nx*33+33-2,y+ny*16+32-2,$FFFF,$FFFF); 1689 end; { Paint }1689 end; 1690 1690 1691 1691 procedure TIsoMap.AttackBegin(const ShowMove: TShowMove); -
branches/highdpi/LocalPlayer/KeyBindings.pas
r464 r465 1 unit UKeyBindings; 2 3 {$mode delphi} 1 unit KeyBindings; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, fgl, LCLProc, LCLType, Menus, Registry; 6 Classes, SysUtils, Generics.Collections, Generics.Defaults, LCLProc, LCLType, 7 Menus, Registry; 9 8 10 9 type … … 26 25 { TKeyBindings } 27 26 28 TKeyBindings = class(T FPGObjectList<TKeyBinding>)27 TKeyBindings = class(TObjectList<TKeyBinding>) 29 28 private 30 29 public … … 38 37 procedure ResetToDefault; 39 38 procedure RemoveShortCut(ShortCut: TShortCut); 39 procedure SortAlpha; 40 40 end; 41 41 … … 241 241 Text: string; 242 242 begin 243 Strings.Clear; 244 for I := 0 to Count - 1 do begin 245 Text:= ''; 246 if Items[I].ShortCut <> 0 then 247 Text:= Text + ShortCutToText(Items[I].ShortCut); 248 if Items[I].ShortCut2 <> 0 then begin 249 if Text <> '' then Text := Text + ', '; 250 Text:= Text + ShortCutToText(Items[I].ShortCut2); 243 Strings.BeginUpdate; 244 try 245 Strings.Clear; 246 for I := 0 to Count - 1 do begin 247 Text := ''; 248 if Items[I].ShortCut <> 0 then 249 Text := Text + ShortCutToText(Items[I].ShortCut); 250 if Items[I].ShortCut2 <> 0 then begin 251 if Text <> '' then Text := Text + ', '; 252 Text := Text + ShortCutToText(Items[I].ShortCut2); 253 end; 254 if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')' 255 else Text := Items[I].FullName; 256 Strings.Add(Text); 251 257 end; 252 if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')' 253 else Text := Items[I].FullName; 254 Strings.Add(Text); 258 finally 259 Strings.EndUpdate; 255 260 end; 256 261 end; … … 284 289 if Items[I].ShortCut2 = ShortCut then Items[I].ShortCut2 := 0; 285 290 end; 291 end; 292 293 function CompareAlpha(constref Item1, Item2: TKeyBinding): Integer; 294 begin 295 Result := CompareStr(Item1.FullName, Item2.FullName); 296 end; 297 298 procedure TKeyBindings.SortAlpha; 299 begin 300 Sort(TComparer<TKeyBinding>.Construct(CompareAlpha)); 286 301 end; 287 302 … … 372 387 BMoveLeftUp := AddItem('MoveLeftUp', 'Move unit left-up', 'Num7', 'Home'); 373 388 BMoveLeft := AddItem('MoveLeft', 'Move unit left', 'Num4', 'Left'); 389 SortAlpha; 374 390 end; 375 391 … … 381 397 end. 382 398 399 -
branches/highdpi/LocalPlayer/LocalPlayer.pas
r378 r465 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 10 10 11 11 uses 12 UDpiControls, Term, CityScreen, Draft, MessgEx, Select, CityType, Help, UnitStat, Diagram, 13 NatStat, Wonders, Nego, Enhance, BaseWin, Battle, Rates, TechTree, Forms; 12 UDpiControls, Term, CityScreen, Nego, BaseWin, Forms; 14 13 15 14 var 16 FormsCreated: boolean;15 FormsCreated: Boolean; 17 16 18 procedure Client(Command, Player: integer; var Data);17 procedure Client(Command, Player: Integer; var Data); 19 18 begin 20 19 if not FormsCreated then 21 20 begin 22 FormsCreated := true;21 FormsCreated := True; 23 22 // TODO: Changing application name in runtime will cause change of Linux XML registry file path 24 // DpiApplication.MainForm := MainScreen;23 // Application.MainForm := MainScreen; 25 24 DpiApplication.CreateForm(TMainScreen, MainScreen); 26 DpiApplication.CreateForm(TCityDlg, CityDlg);27 DpiApplication.CreateForm(TModalSelectDlg, ModalSelectDlg);28 DpiApplication.CreateForm(TListDlg, ListDlg);29 DpiApplication.CreateForm(TMessgExDlg, MessgExDlg);30 DpiApplication.CreateForm(TDraftDlg, DraftDlg);31 DpiApplication.CreateForm(TCityTypeDlg, CityTypeDlg);32 DpiApplication.CreateForm(THelpDlg, HelpDlg);33 DpiApplication.CreateForm(TUnitStatDlg, UnitStatDlg);34 DpiApplication.CreateForm(TDiaDlg, DiaDlg);35 DpiApplication.CreateForm(TNatStatDlg, NatStatDlg);36 DpiApplication.CreateForm(TWondersDlg, WondersDlg);37 DpiApplication.CreateForm(TNegoDlg, NegoDlg);38 DpiApplication.CreateForm(TEnhanceDlg, EnhanceDlg);39 DpiApplication.CreateForm(TBattleDlg, BattleDlg);40 // DpiApplication.CreateForm(TAdvisorDlg, AdvisorDlg);41 DpiApplication.CreateForm(TRatesDlg, RatesDlg);42 DpiApplication.CreateForm(TTechTreeDlg, TechTreeDlg);43 25 end; 44 26 MainScreen.Client(Command, Player, Data); 45 27 end; 46 28 47 procedure SetAIName( p: integer; Name: string);29 procedure SetAIName(P: Integer; Name: string); 48 30 begin 49 MainScreen.SetAIName( p, Name);31 MainScreen.SetAIName(P, Name); 50 32 end; 51 33 52 34 initialization 53 35 54 FormsCreated := false;36 FormsCreated := False; 55 37 56 38 end. -
branches/highdpi/LocalPlayer/MessgEx.lfm
r349 r465 6 6 BorderIcons = [] 7 7 BorderStyle = bsNone 8 Caption = ' C-evo'8 Caption = 'Message' 9 9 ClientHeight = 134 10 10 ClientWidth = 418 … … 12 12 DesignTimePPI = 144 13 13 Font.Color = clWindowText 14 Font.Height = - 1314 Font.Height = -20 15 15 Font.Name = 'MS Sans Serif' 16 16 FormStyle = fsStayOnTop … … 20 20 OnPaint = FormPaint 21 21 OnShow = FormShow 22 LCLVersion = '2. 0.12.0'22 LCLVersion = '2.2.2.0' 23 23 Scaled = False 24 24 object Button1: TButtonA … … 61 61 object EInput: TDpiEdit 62 62 Left = 125 63 Height = 2 663 Height = 27 64 64 Top = 64 65 65 Width = 168 -
branches/highdpi/LocalPlayer/MessgEx.pas
r412 r465 5 5 6 6 uses 7 UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils, 8 LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ButtonA,9 ButtonB, StdCtrls, DrawDlg;7 UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils, LCLIntf, LCLType, Messages, 8 SysUtils, Classes, Graphics, Controls, Forms, ButtonA, ButtonB, StdCtrls, 9 DrawDlg, Help; 10 10 11 11 type … … 13 13 mikPureIcon, mikMyArmy, mikEnemyArmy, mikFullControl, mikShip, mikBigIcon, 14 14 mikEnemyShipComplete); 15 16 { TMessgExDlg } 15 17 16 18 TMessgExDlg = class(TBaseMessgDlg) … … 32 34 Kind: TMessageKind; 33 35 IconIndex: Integer; 34 HelpKind: Integer;36 HelpKind: TLinkCategory; 35 37 HelpNo: Integer; 36 38 CenterTo: Integer; 37 39 IconKind: TMessageIconKind; 38 40 OpenSound: string; 39 function ShowModal: integer; override;41 function ShowModal: Integer; override; 40 42 procedure CancelMovie; 41 43 private 42 MovieCancelled: boolean;43 procedure PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);44 MovieCancelled: Boolean; 45 procedure PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer); 44 46 procedure PaintMyArmy; 45 47 procedure PaintEnemyArmy; … … 47 49 end; 48 50 49 var50 MessgExDlg: TMessgExDlg;51 51 52 52 procedure SoundMessageEx(SimpleText, SoundItem: string); 53 procedure TribeMessage( p: integer; SimpleText, SoundItem: string);53 procedure TribeMessage(P: Integer; SimpleText, SoundItem: string); 54 54 function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string) 55 : integer;55 : Integer; 56 56 procedure ContextMessage(SimpleText, SoundItem: string; 57 ContextKind, ContextNo: integer); 57 ContextKind: TLinkCategory; ContextNo: Integer); 58 58 59 59 60 implementation 60 61 61 62 uses 62 ClientTools, BaseWin, Term, Help, UnitStat, Tribes, UPixelPointer,63 IsoEngine,Diagram, Sound;63 ClientTools, BaseWin, Term, UnitStat, Tribes, PixelPointer, 64 Diagram, Sound; 64 65 65 66 {$R *.lfm} … … 78 79 procedure TMessgExDlg.FormShow(Sender: TObject); 79 80 var 80 i: integer;81 I: Integer; 81 82 begin 82 83 if IconKind = mikEnemyArmy then … … 147 148 end; 148 149 149 SplitText( true);150 SplitText(True); 150 151 ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing; 151 152 if GameMode = cMovie then … … 178 179 end; 179 180 end; 180 for i:= 0 to ControlCount - 1 do181 Controls[ i].Top := ClientHeight - (34 + Border);181 for I := 0 to ControlCount - 1 do 182 Controls[I].Top := ClientHeight - (34 + Border); 182 183 if Kind = mkModel then 183 184 EInput.Top := ClientHeight - (76 + Border); 184 185 end; 185 186 186 function TMessgExDlg.ShowModal: integer;187 function TMessgExDlg.ShowModal: Integer; 187 188 var 188 189 Ticks0: TDateTime; 189 190 Ticks: TDateTime; 190 191 begin 192 Caption := Phrases.Lookup('TITLE_MESSAGE'); 191 193 if GameMode = cMovie then 192 194 begin 193 195 if not((GameMode = cMovie) and (MovieSpeed = 4)) then 194 196 begin 195 MovieCancelled := false;197 MovieCancelled := False; 196 198 Show; 197 199 Ticks0 := NowPrecise; … … 203 205 Hide; 204 206 end; 205 result := mrOk;207 Result := mrOk; 206 208 end 207 209 else 208 result := inherited; 210 Result := inherited; 211 //Gtk2Fix; 209 212 end; 210 213 211 214 procedure TMessgExDlg.CancelMovie; 212 215 begin 213 MovieCancelled := true;214 end; 215 216 procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);216 MovieCancelled := True; 217 end; 218 219 procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer); 217 220 const 218 221 xScrewed = 77; … … 220 223 wScrewed = 43; 221 224 hScrewed = 27; 225 type 226 TScrewed = array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of Single; 222 227 var 223 ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: integer;228 ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: Integer; 224 229 BookRect: TRect; 225 x1, xR, yR, share: single;226 Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;230 x1, xR, yR, share: Single; 231 Screwed: TScrewed; 227 232 SrcPtr: TPixelPointer; 228 233 Width: Integer; … … 235 240 yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig; 236 241 // prepare screwed icon 237 FillChar(Screwed, sizeof(Screwed), 0);242 Screwed := Default(TScrewed); 238 243 BigImp.BeginUpdate; 239 SrcPtr := PixelPointer(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));244 SrcPtr := TPixelPointer.Create(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon)); 240 245 for iy := 0 to ScaleToNative(Height) - 1 do begin 241 246 for ix := 0 to ScaleToNative(Width) - 1 do begin … … 277 282 BookRect := SmallBook.BoundsRect; 278 283 end; 279 x := x- BookRect.Width div 2;284 X := X - BookRect.Width div 2; 280 285 281 286 // paint 282 287 UnshareBitmap(LogoBuffer); 283 DpiBit Canvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, x, y);288 DpiBitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, X, Y); 284 289 285 290 if IconIndex >= 0 then … … 294 299 ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), BookRect, clCover, clPage); 295 300 296 DpiBit Canvas(ca, x, y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);301 DpiBitBltCanvas(ca, X, Y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0); 297 302 end; 298 303 … … 303 308 procedure TMessgExDlg.PaintEnemyArmy; 304 309 var 305 emix, ix, iy, x, y, count, UnitsInLine: integer;310 emix, ix, iy, X, Y, count, UnitsInLine: Integer; 306 311 begin 307 312 ix := 0; … … 314 319 for count := 0 to LostArmy[emix] - 1 do 315 320 begin 316 x:= ClientWidth div 2 + ix * 64 - UnitsInLine * 32;317 y:= 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;321 X := ClientWidth div 2 + ix * 64 - UnitsInLine * 32; 322 Y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48; 318 323 with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do 319 324 begin 320 DpiBit Canvas(Canvas, x, y, 64, 48, HGr.Mask.Canvas,325 DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Mask.Canvas, 321 326 pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND); 322 DpiBit Canvas(Canvas, x, y, 64, 48, HGr.Data.Canvas,327 DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Data.Canvas, 323 328 pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT); 324 329 end; 325 330 326 331 // next position 327 inc(ix);332 Inc(ix); 328 333 if ix = LostUnitsPerLine then 329 334 begin // next line 330 335 ix := 0; 331 inc(iy);336 Inc(iy); 332 337 if iy = 6 then 333 exit;338 Exit; 334 339 UnitsInLine := nLostArmy - LostUnitsPerLine * iy; 335 340 if UnitsInLine > LostUnitsPerLine then … … 341 346 procedure TMessgExDlg.FormPaint(Sender: TObject); 342 347 var 343 p1, clSaveTextLight, clSaveTextShade: integer;348 p1, clSaveTextLight, clSaveTextShade: Integer; 344 349 begin 345 350 if (IconKind = mikImp) and (IconIndex = 27) then … … 362 367 p1 := MyRO.Wonder[IconIndex].EffectiveOwner; 363 368 UnshareBitmap(Buffer); 364 DpiBit Canvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,369 DpiBitBltCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange, 365 370 ySizeBig + 2 * GlowRange, Canvas, 366 371 ClientWidth div 2 - (28 + GlowRange), 24 - GlowRange); 367 DpiBit Canvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,372 DpiBitBltCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig, 368 373 BigImp.Canvas, IconIndex mod 7 * xSizeBig, 369 374 (IconIndex + SystemIconLines * 7) div 7 * ySizeBig); … … 373 378 GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig, 374 379 Tribe[p1].Color); 375 DpiBit Canvas(Canvas, ClientWidth div 2 - (28 + GlowRange),380 DpiBitBltCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange), 376 381 24 - GlowRange, xSizeBig + 2 * GlowRange, ySizeBig + 2 * GlowRange, 377 382 Buffer.Canvas, 0, 0); … … 387 392 end; 388 393 mikModel: 389 with Tribe[ me].ModelPicture[IconIndex] do394 with Tribe[Me].ModelPicture[IconIndex] do 390 395 begin 391 396 FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig, 392 397 ySizeBig, 0, 0); 393 DpiBit Canvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,398 DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44, 394 399 HGr.Mask.Canvas, pix mod 10 * 65 + 1, 395 400 pix div 10 * 49 + 1, SRCAND); 396 DpiBit Canvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,401 DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44, 397 402 HGr.Data.Canvas, pix mod 10 * 65 + 1, 398 403 pix div 10 * 49 + 1, SRCPAINT); … … 406 411 Frame(Canvas, ClientWidth div 2 - 32 - 1, 24 - 1, 407 412 ClientWidth div 2 + 32, 24 + 48, $000000, $000000); 408 DpiBit Canvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,413 DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48, 409 414 Tribe[IconIndex].faceHGr.Data.Canvas, 410 415 1 + Tribe[IconIndex].facepix mod 10 * 65, … … 420 425 mikEnemyShipComplete: 421 426 begin 422 DpiBit Canvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,427 DpiBitBltCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas, 423 428 (ClientWidth - 140) div 2, 24); 424 429 ImageOp_BCC(Buffer, Templates.Data, Point(0, 0), StarshipDeparted.BoundsRect, 0, $FFFFFF); 425 DpiBit Canvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,430 DpiBitBltCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120, 426 431 Buffer.Canvas, 0, 0); 427 432 end; … … 451 456 begin 452 457 if Kind = mkOkHelp then 453 HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)458 MainScreen.HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo) 454 459 else if Kind = mkModel then 455 UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)460 MainScreen.UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex) 456 461 else 457 462 ModalResult := mrIgnore; … … 482 487 // because Messg.SoundMessage not capable of movie mode 483 488 begin 484 with M essgExDlg do489 with MainScreen.MessgExDlg do 485 490 begin 486 491 MessgText := SimpleText; … … 491 496 end; 492 497 493 procedure TribeMessage( p: integer; SimpleText, SoundItem: string);494 begin 495 with M essgExDlg do498 procedure TribeMessage(P: Integer; SimpleText, SoundItem: string); 499 begin 500 with MainScreen.MessgExDlg do 496 501 begin 497 502 OpenSound := SoundItem; … … 499 504 Kind := mkOk; 500 505 IconKind := mikTribe; 501 IconIndex := p;506 IconIndex := P; 502 507 ShowModal; 503 508 end; … … 505 510 506 511 function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string) 507 : integer;508 begin 509 with M essgExDlg do512 : Integer; 513 begin 514 with MainScreen.MessgExDlg do 510 515 begin 511 516 MessgText := SimpleText; … … 513 518 Kind := QueryKind; 514 519 ShowModal; 515 result := ModalResult;520 Result := ModalResult; 516 521 end; 517 522 end; 518 523 519 524 procedure ContextMessage(SimpleText, SoundItem: string; 520 ContextKind , ContextNo: integer);521 begin 522 with M essgExDlg do525 ContextKind: TLinkCategory; ContextNo: Integer); 526 begin 527 with MainScreen.MessgExDlg do 523 528 begin 524 529 MessgText := SimpleText; … … 543 548 end; 544 549 545 546 initialization547 548 550 end. -
branches/highdpi/LocalPlayer/NatStat.pas
r361 r465 5 5 6 6 uses 7 UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, 8 9 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, 10 ButtonB, ButtonC, Menus, EOTButton; 7 UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils, 8 Classes, Graphics, Controls, Forms, ButtonB, ButtonC, Menus, EOTButton; 11 9 12 10 type … … 27 25 procedure ToggleBtnClick(Sender: TObject); 28 26 procedure PlayerClick(Sender: TObject); 29 procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);27 procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 30 28 procedure FormDestroy(Sender: TObject); 31 29 procedure ScrollUpBtnClick(Sender: TObject); 32 30 procedure ScrollDownBtnClick(Sender: TObject); 33 31 procedure TellAIBtnClick(Sender: TObject); 34 35 32 public 36 33 procedure CheckAge; 37 procedure ShowNewContent(NewMode: integer; p: integer = -1);34 procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1); 38 35 procedure EcoChange; 39 40 36 protected 41 37 procedure OffscreenPaint; override; 42 43 38 private 44 pView, AgePrepared, LinesDown: integer; 45 SelfReport, CurrentReport: PEnemyReport; 46 ShowContact, ContactEnabled: boolean; 47 Back, Template: TDpiBitmap; 39 pView: Integer; 40 AgePrepared: Integer; 41 LinesDown: Integer; 42 SelfReport: PEnemyReport; 43 CurrentReport: PEnemyReport; 44 ShowContact: Boolean; 45 ContactEnabled: Boolean; 46 Back: TDpiBitmap; 47 Template: TDpiBitmap; 48 48 ReportText: TStringList; 49 49 procedure GenerateReportText; 50 50 end; 51 51 52 var53 NatStatDlg: TNatStatDlg;54 52 55 53 implementation … … 58 56 59 57 uses 60 Messg, Tribes, Directories;58 Term, Messg, Tribes, Directories; 61 59 62 60 const … … 109 107 if MainTexture.Age <> AgePrepared then begin 110 108 AgePrepared := MainTexture.Age; 111 DpiBit Canvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,109 DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight, 112 110 MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2, 113 111 (MainTexture.Height - ClientHeight) div 2); … … 118 116 procedure TNatStatDlg.FormShow(Sender: TObject); 119 117 begin 120 if pView = me then118 if pView = Me then 121 119 begin 122 120 SelfReport.TurnOfCivilReport := MyRO.Turn; 123 121 SelfReport.TurnOfMilReport := MyRO.Turn; 124 move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));122 Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty)); 125 123 SelfReport.Government := MyRO.Government; 126 124 SelfReport.Money := MyRO.Money; 127 CurrentReport := pointer(SelfReport);125 CurrentReport := Pointer(SelfReport); 128 126 end 129 127 else 130 CurrentReport := pointer(MyRO.EnemyReport[pView]);128 CurrentReport := Pointer(MyRO.EnemyReport[pView]); 131 129 if CurrentReport.TurnOfCivilReport >= 0 then 132 130 GenerateReportText; 133 ShowContact := (pView <> me) and (not supervising or (me <> 0));134 ContactEnabled := ShowContact and not supervising and131 ShowContact := (pView <> Me) and (not Supervising or (Me <> 0)); 132 ContactEnabled := ShowContact and not Supervising and 135 133 (1 shl pView and MyRO.Alive <> 0); 136 134 ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and … … 150 148 end; 151 149 152 procedure TNatStatDlg.ShowNewContent(NewMode , p: integer);153 begin 154 if p< 0 then150 procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer); 151 begin 152 if P < 0 then 155 153 if ClientMode >= scContact then 156 pView := DipMem[ me].pContact154 pView := DipMem[Me].pContact 157 155 else 158 156 begin … … 160 158 while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or 161 159 (1 shl pView and MyRO.Alive = 0)) do 162 inc(pView);160 Inc(pView); 163 161 if pView >= nPl then 164 pView := me;162 pView := Me; 165 163 end 166 164 else 167 pView := p;165 pView := P; 168 166 inherited ShowNewContent(NewMode); 169 167 end; … … 178 176 List: ^TChart; 179 177 180 function StatText(no: integer): string;178 function StatText(no: Integer): string; 181 179 var 182 i: integer;180 I: Integer; 183 181 begin 184 182 if (CurrentReport.TurnOfCivilReport >= 0) and 185 (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then183 (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then 186 184 begin 187 i:= List[CurrentReport.TurnOfCivilReport];185 I := List[CurrentReport.TurnOfCivilReport]; 188 186 case no of 189 187 stPop: 190 result := Format(Phrases.Lookup('FRSTATPOP'), [i]);188 Result := Format(Phrases.Lookup('FRSTATPOP'), [I]); 191 189 stTerritory: 192 result := Format(Phrases.Lookup('FRSTATTER'), [i]);190 Result := Format(Phrases.Lookup('FRSTATTER'), [I]);
