Changeset 447 for trunk/Database.pas
- Timestamp:
- May 19, 2022, 10:39:34 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Database.pas
r442 r447 26 26 27 27 nStartUn = 1; 28 StartUn: array [0 .. nStartUn - 1] of integer = (0); // mix of start units28 StartUn: array [0 .. nStartUn - 1] of Integer = (0); // mix of start units 29 29 30 30 CityOwnTile = 13; … … 50 50 Mode: TGameMode; 51 51 GWonder: array [0 .. nWonder - 1] of TWonderInfo; 52 ServerVersion: array [0 .. nPl - 1] of integer;53 ProcessClientData: array [0 .. nPl - 1] of boolean;52 ServerVersion: array [0 .. nPl - 1] of Integer; 53 ProcessClientData: array [0 .. nPl - 1] of Boolean; 54 54 CL: TCmdList; 55 55 {$IFDEF TEXTLOG}CmdInfo: string; … … 58 58 // map data 59 59 RealMap: array [0 .. lxmax * lymax - 1] of Cardinal; 60 Continent: array [0 .. lxmax * lymax - 1] of integer;60 Continent: array [0 .. lxmax * lymax - 1] of Integer; 61 61 { continent id for each tile } 62 62 Occupant: array [0 .. lxmax * lymax - 1] of ShortInt; … … 65 65 ObserveLevel: array [0 .. lxmax * lymax - 1] of Cardinal; 66 66 { Observe Level of player p in bits 2*p and 2*p+1 } 67 UsedByCity: array [0 .. lxmax * lymax - 1] of integer;67 UsedByCity: array [0 .. lxmax * lymax - 1] of Integer; 68 68 { location of exploiting city for 69 69 each tile, =-1 if not exploited } … … 71 71 // player data 72 72 RW: array [0 .. nPl - 1] of TPlayerContext; { player data } 73 Difficulty: array [0 .. nPl - 1] of integer;73 Difficulty: array [0 .. nPl - 1] of Integer; 74 74 GShip: array [0 .. nPl - 1] of TShipInfo; 75 75 ResourceMask: array [0 .. nPl - 1] of Cardinal; 76 Founded: array [0 .. nPl - 1] of integer; { number of cities founded }77 TerritoryCount: array [0 .. nPl] of integer;76 Founded: array [0 .. nPl - 1] of Integer; { number of cities founded } 77 TerritoryCount: array [0 .. nPl] of Integer; 78 78 LastValidStat, Researched, Discovered, // number of tiles discovered 79 GrWallContinent: array [0 .. nPl - 1] of integer;79 GrWallContinent: array [0 .. nPl - 1] of Integer; 80 80 RWemix: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt; 81 81 // [p1,p2,mix] -> index of p2's model mix in p1's enemy model list 82 82 Destroyed: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt; 83 83 // [p1,p2,mix] -> number of p2's units with model mix that p1 has destroyed 84 nTech: array [0 .. nPl - 1] of integer; { number of known techs }84 nTech: array [0 .. nPl - 1] of Integer; { number of known techs } 85 85 // NewContact: array[0..nPl-1,0..nPl-1] of boolean; 86 86 87 87 type 88 TVicinity8Loc = array [0 .. 7] of integer;89 TVicinity21Loc = array [0 .. 27] of integer;90 91 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);92 procedure IntServer(Command, Player, Subject: integer; var Data);93 procedure CompactLists( p: integer);94 procedure ClearTestFlags(ClearFlags: integer);95 procedure SetTestFlags( p, SetFlags: integer);88 TVicinity8Loc = array [0 .. 7] of Integer; 89 TVicinity21Loc = array [0 .. 27] of Integer; 90 91 procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal); 92 procedure IntServer(Command, Player, Subject: Integer; var Data); 93 procedure CompactLists(P: Integer); 94 procedure ClearTestFlags(ClearFlags: Integer); 95 procedure SetTestFlags(P, SetFlags: Integer); 96 96 97 97 // Tech Related Functions 98 function TechBaseCost(nTech, diff: integer): integer;99 function TechCost( p: integer): integer;100 procedure CalculateModel(var m: TModel);101 procedure CheckSpecialModels( p, pre: integer);102 procedure EnableDevModel( p: integer);103 procedure SeeTech( p, ad: integer);104 procedure DiscoverTech( p, ad: integer);105 procedure CheckExpiration(Wonder: integer);98 function TechBaseCost(nTech, diff: Integer): Integer; 99 function TechCost(P: Integer): Integer; 100 procedure CalculateModel(var M: TModel); 101 procedure CheckSpecialModels(P, pre: Integer); 102 procedure EnableDevModel(P: Integer); 103 procedure SeeTech(P, ad: Integer); 104 procedure DiscoverTech(P, ad: Integer); 105 procedure CheckExpiration(Wonder: Integer); 106 106 107 107 // Location Navigation 108 function dLoc(Loc, dx, dy: integer): integer;109 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);110 function Distance(Loc0, Loc1: integer): integer;111 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);112 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);108 function dLoc(Loc, dx, dy: Integer): Integer; 109 procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer); 110 function Distance(Loc0, Loc1: Integer): Integer; 111 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 112 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 113 113 114 114 // Game Initialization 115 115 procedure InitRandomGame; 116 procedure InitMapGame(Human: integer);116 procedure InitMapGame(Human: Integer); 117 117 procedure ReleaseGame; 118 118 119 119 // Map Editor 120 function MapGeneratorAvailable: boolean;120 function MapGeneratorAvailable: Boolean; 121 121 procedure CreateElevation; 122 procedure CreateMap(preview: boolean);122 procedure CreateMap(preview: Boolean); 123 123 procedure InitMapEditor; 124 124 procedure ReleaseMapEditor; 125 procedure EditTile(Loc, NewTile: integer);125 procedure EditTile(Loc, NewTile: Integer); 126 126 127 127 // Map Revealing 128 function GetTileInfo( p, cix, Loc: integer; var Info: TTileInfo): integer;129 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);130 function UnitSpeed( p, mix, Health: integer): integer;131 procedure GetUnitReport( p, uix: integer; var UnitReport: TUnitReport);132 procedure SearchCity(Loc: integer; var p, cix: integer);133 procedure TellAboutModel( p, taOwner, tamix: integer);134 function emixSafe( p, taOwner, tamix: integer): integer;135 function Discover9(Loc, p, Level: integer;136 TellAllied, EnableContact: boolean): boolean;137 function Discover21(Loc, p, AdjacentLevel: integer;138 TellAllied, EnableContact: boolean): boolean;139 procedure DiscoverAll( p, Level: integer);140 procedure DiscoverViewAreas( p: integer);141 function GetUnitStack( p, Loc: integer): integer;142 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);143 procedure RecalcV8ZoC( p, Loc: integer);144 procedure RecalcMapZoC( p: integer);145 procedure RecalcPeaceMap( p: integer);128 function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer; 129 procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer); 130 function UnitSpeed(P, mix, Health: Integer): Integer; 131 procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport); 132 procedure SearchCity(Loc: Integer; var P, cix: Integer); 133 procedure TellAboutModel(P, taOwner, tamix: Integer); 134 function emixSafe(P, taOwner, tamix: Integer): Integer; 135 function Discover9(Loc, P, Level: Integer; 136 TellAllied, EnableContact: Boolean): Boolean; 137 function Discover21(Loc, P, AdjacentLevel: Integer; 138 TellAllied, EnableContact: Boolean): Boolean; 139 procedure DiscoverAll(P, Level: Integer); 140 procedure DiscoverViewAreas(P: Integer); 141 function GetUnitStack(P, Loc: Integer): Integer; 142 procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False); 143 procedure RecalcV8ZoC(P, Loc: Integer); 144 procedure RecalcMapZoC(P: Integer); 145 procedure RecalcPeaceMap(P: Integer); 146 146 147 147 // Territory Calculation 148 procedure CheckBorders(OriginLoc: integer; PlayerLosingCity: integer = -1);149 procedure LogCheckBorders( p, cix: integer; PlayerLosingCity: integer = -1);148 procedure CheckBorders(OriginLoc: Integer; PlayerLosingCity: Integer = -1); 149 procedure LogCheckBorders(P, cix: Integer; PlayerLosingCity: Integer = -1); 150 150 151 151 // Map Processing 152 procedure CreateUnit( p, mix: integer);153 procedure FreeUnit( p, uix: integer);154 procedure PlaceUnit( p, uix: integer);155 procedure RemoveUnit( p, uix: integer; Enemy: integer = -1);156 procedure RemoveUnit_UpdateMap( p, uix: integer);157 procedure RemoveAllUnits( p, Loc: integer; Enemy: integer = -1);158 procedure RemoveDomainUnits( d, p, Loc: integer);159 procedure FoundCity( p, FoundLoc: integer);160 procedure DestroyCity( p, cix: integer; SaveUnits: boolean);161 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);162 procedure CompleteJob( p, Loc, Job: integer);152 procedure CreateUnit(P, mix: Integer); 153 procedure FreeUnit(P, uix: Integer); 154 procedure PlaceUnit(P, uix: Integer); 155 procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1); 156 procedure RemoveUnit_UpdateMap(P, uix: Integer); 157 procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1); 158 procedure RemoveDomainUnits(D, P, Loc: Integer); 159 procedure FoundCity(P, FoundLoc: Integer); 160 procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean); 161 procedure ChangeCityOwner(pOld, cixOld, pNew: Integer); 162 procedure CompleteJob(P, Loc, Job: Integer); 163 163 164 164 // Diplomacy 165 procedure IntroduceEnemy(p1, p2: integer);166 procedure GiveCivilReport( p, pAbout: integer);167 procedure GiveMilReport( p, pAbout: integer);168 procedure ShowPrice(pSender, pTarget, Price: integer);169 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;170 procedure CancelTreaty( p, pWith: integer; DecreaseCredibility: boolean = true);171 function DoSpyMission( p, pCity, cix, Mission: integer): Cardinal;165 procedure IntroduceEnemy(p1, p2: Integer); 166 procedure GiveCivilReport(P, pAbout: Integer); 167 procedure GiveMilReport(P, pAbout: Integer); 168 procedure ShowPrice(pSender, pTarget, Price: Integer); 169 function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean; 170 procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean = True); 171 function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal; 172 172 173 173 … … 180 180 181 181 var 182 UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }183 184 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);182 UnBuilt: array [0 .. nPl - 1] of Integer; { number of units built } 183 184 procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal); 185 185 var 186 186 I: Integer; 187 187 begin 188 188 for I := 0 to Count - 1 do 189 x[I] := x[I] and Mask;190 end; 191 192 procedure CompactLists( p: integer);193 var 194 uix, uix1, cix: integer;195 {$IFOPT O-}V21: integer;189 X[I] := X[I] and Mask; 190 end; 191 192 procedure CompactLists(P: Integer); 193 var 194 uix, uix1, cix: Integer; 195 {$IFOPT O-}V21: Integer; 196 196 Radius: TVicinity21Loc; {$ENDIF} 197 197 begin 198 with RW[ p] do198 with RW[P] do 199 199 begin 200 200 // compact unit list … … 203 203 if Un[uix].Loc < 0 then 204 204 begin 205 dec(nUn);205 Dec(nUn); 206 206 Un[uix] := Un[nUn]; { replace removed unit by last } 207 207 if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then … … 212 212 end 213 213 else 214 inc(uix);214 Inc(uix); 215 215 216 216 // compact city list … … 219 219 if City[cix].Loc < 0 then 220 220 begin 221 dec(nCity);221 Dec(nCity); 222 222 City[cix] := City[nCity]; { replace city by last } 223 223 for uix1 := 0 to nUn - 1 do … … 227 227 end 228 228 else 229 inc(cix);229 Inc(cix); 230 230 231 231 // compact enemy city list … … 234 234 if EnemyCity[cix].Loc < 0 then 235 235 begin 236 dec(nEnemyCity);236 Dec(nEnemyCity); 237 237 EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last } 238 238 end 239 239 else 240 inc(cix);240 Inc(cix); 241 241 242 242 {$IFOPT O-} … … 247 247 for V21 := 1 to 26 do 248 248 if Tiles and (1 shl V21) <> 0 then 249 assert(UsedByCity[Radius[V21]] = Loc);249 Assert(UsedByCity[Radius[V21]] = Loc); 250 250 end; 251 251 {$ENDIF} … … 257 257 ____________________________________________________________________ 258 258 } 259 function TechBaseCost(nTech, diff: integer): integer;260 var 261 c0: single;259 function TechBaseCost(nTech, diff: Integer): Integer; 260 var 261 c0: Single; 262 262 begin 263 263 c0 := TechFormula_M[diff] * (nTech + 4) * 264 264 exp((nTech + 4) / TechFormula_D[diff]); 265 265 if c0 >= $10000000 then 266 result := $10000000266 Result := $10000000 267 267 else 268 result := trunc(c0);269 end; 270 271 function TechCost( p: integer): integer;272 begin 273 with RW[ p] do274 begin 275 result := TechBaseCost(nTech[p], Difficulty[p]);268 Result := trunc(c0); 269 end; 270 271 function TechCost(P: Integer): Integer; 272 begin 273 with RW[P] do 274 begin 275 Result := TechBaseCost(nTech[P], Difficulty[P]); 276 276 if ResearchTech >= 0 then 277 277 if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then 278 result := result shr 1278 Result := Result shr 1 279 279 else if ResearchTech in FutureTech then 280 280 if Government = gFuture then 281 result := result * 2281 Result := Result * 2 282 282 else 283 result := result * 4;284 end; 285 end; 286 287 procedure SetModelFlags(var m: TModel);288 begin 289 m.Flags := 0;290 if ( m.Domain = dGround) and (m.Kind <> mkDiplomat) then291 m.Flags := m.Flags or mdZOC;292 if ( m.Kind = mkDiplomat) or (m.Attack + m.Cap[mcBombs] = 0) then293 m.Flags := m.Flags or mdCivil;294 if ( m.Cap[mcOver] > 0) or (m.Domain = dSea) and (m.Weight >= 6) then295 m.Flags := m.Flags or mdDoubleSupport;296 end; 297 298 procedure CalculateModel(var m: TModel);283 Result := Result * 4; 284 end; 285 end; 286 287 procedure SetModelFlags(var M: TModel); 288 begin 289 M.Flags := 0; 290 if (M.Domain = dGround) and (M.Kind <> mkDiplomat) then 291 M.Flags := M.Flags or mdZOC; 292 if (M.Kind = mkDiplomat) or (M.Attack + M.Cap[mcBombs] = 0) then 293 M.Flags := M.Flags or mdCivil; 294 if (M.Cap[mcOver] > 0) or (M.Domain = dSea) and (M.Weight >= 6) then 295 M.Flags := M.Flags or mdDoubleSupport; 296 end; 297 298 procedure CalculateModel(var M: TModel); 299 299 { calculate attack, defense, cost... of a model by features } 300 300 var 301 i: integer;302 begin 303 with mdo301 I: Integer; 302 begin 303 with M do 304 304 begin 305 305 Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength; … … 312 312 Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines]; 313 313 if Cap[mcNP] = 0 then 314 inc(Speed, 100 * Cap[mcSE]);314 Inc(Speed, 100 * Cap[mcSE]); 315 315 end; 316 316 dAir: … … 318 318 end; 319 319 Cost := 0; 320 for i:= 0 to nFeature - 1 do321 if 1 shl Domain and Feature[ i].Domains <> 0 then322 inc(Cost, Cap[i] * Feature[i].Cost);320 for I := 0 to nFeature - 1 do 321 if 1 shl Domain and Feature[I].Domains <> 0 then 322 Inc(Cost, Cap[I] * Feature[I].Cost); 323 323 Cost := Cost * MCost; 324 324 Weight := 0; 325 for i:= 0 to nFeature - 1 do326 if 1 shl Domain and Feature[ i].Domains <> 0 then327 if (Domain = dGround) and ( i= mcDefense) then328 inc(Weight, Cap[i] * 2)325 for I := 0 to nFeature - 1 do 326 if 1 shl Domain and Feature[I].Domains <> 0 then 327 if (Domain = dGround) and (I = mcDefense) then 328 Inc(Weight, Cap[I] * 2) 329 329 else 330 inc(Weight, Cap[i] * Feature[i].Weight);331 end; 332 SetModelFlags( m);333 end; 334 335 procedure CheckSpecialModels( p, pre: integer);336 var 337 i, mix1: integer;338 HasAlready: boolean;339 begin 340 for i:= 0 to nSpecialModel -330 Inc(Weight, Cap[I] * Feature[I].Weight); 331 end; 332 SetModelFlags(M); 333 end; 334 335 procedure CheckSpecialModels(P, pre: Integer); 336 var 337 I, mix1: Integer; 338 HasAlready: Boolean; 339 begin 340 for I := 0 to nSpecialModel - 341 341 1 do { check whether new special model available } 342 if (SpecialModelPreq[ i] = pre) and (RW[p].nModel < nmmax) then343 begin 344 HasAlready := false;345 for mix1 := 0 to RW[ p].nModel - 1 do346 if (RW[ p].Model[mix1].Kind = SpecialModel[i].Kind) and347 (RW[ p].Model[mix1].Attack = SpecialModel[i].Attack) and348 (RW[ p].Model[mix1].Speed = SpecialModel[i].Speed) then349 HasAlready := true;342 if (SpecialModelPreq[I] = pre) and (RW[P].nModel < nmmax) then 343 begin 344 HasAlready := False; 345 for mix1 := 0 to RW[P].nModel - 1 do 346 if (RW[P].Model[mix1].Kind = SpecialModel[I].Kind) and 347 (RW[P].Model[mix1].Attack = SpecialModel[I].Attack) and 348 (RW[P].Model[mix1].Speed = SpecialModel[I].Speed) then 349 HasAlready := True; 350 350 if not HasAlready then 351 351 begin 352 RW[ p].Model[RW[p].nModel] := SpecialModel[i];353 SetModelFlags(RW[ p].Model[RW[p].nModel]);354 with RW[ p].Model[RW[p].nModel] do352 RW[P].Model[RW[P].nModel] := SpecialModel[I]; 353 SetModelFlags(RW[P].Model[RW[P].nModel]); 354 with RW[P].Model[RW[P].nModel] do 355 355 begin 356 356 Status := 0; … … 359 359 Built := 0; 360 360 Lost := 0; 361 ID := p shl 12 + RW[p].nModel;362 if (Kind = mkSpecial_Boat) and (ServerVersion[ p] < $000EF0) then361 ID := P shl 12 + RW[P].nModel; 362 if (Kind = mkSpecial_Boat) and (ServerVersion[P] < $000EF0) then 363 363 Speed := 350; // old longboat 364 364 end; 365 inc(RW[p].nModel);366 end; 367 end; 368 end; 369 370 procedure EnableDevModel( p: integer);371 begin 372 with RW[ p] do365 Inc(RW[P].nModel); 366 end; 367 end; 368 end; 369 370 procedure EnableDevModel(P: Integer); 371 begin 372 with RW[P] do 373 373 if nModel < nmmax then 374 374 begin … … 381 381 Built := 0; 382 382 Lost := 0; 383 ID := pshl 12 + nModel;384 end; 385 inc(nModel);386 inc(Researched[p]);387 end; 388 end; 389 390 procedure SeeTech( p, ad: integer);391 begin 392 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [ p, ad]); {$ENDIF}393 RW[ p].Tech[ad] := tsSeen;383 ID := P shl 12 + nModel; 384 end; 385 Inc(nModel); 386 Inc(Researched[P]); 387 end; 388 end; 389 390 procedure SeeTech(P, ad: Integer); 391 begin 392 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [P, ad]); {$ENDIF} 393 RW[P].Tech[ad] := tsSeen; 394 394 // inc(nTech[p]); 395 inc(Researched[p]);395 Inc(Researched[P]); 396 396 end; 397 397 398 398 procedure FreeSlaves; 399 399 var 400 p1, uix: integer;400 p1, uix: Integer; 401 401 begin 402 402 for p1 := 0 to nPl - 1 do … … 407 407 end; 408 408 409 procedure DiscoverTech( p, ad: integer);410 411 procedure TellAboutKeyTech( p, Source: integer);409 procedure DiscoverTech(P, ad: Integer); 410 411 procedure TellAboutKeyTech(P, Source: Integer); 412 412 var 413 i, p1: integer;414 begin 415 for i:= 1 to 3 do416 if ad = AgePreq[ i] then413 I, p1: Integer; 414 begin 415 for I := 1 to 3 do 416 if ad = AgePreq[I] then 417 417 for p1 := 0 to nPl - 1 do 418 if (p1 <> p) and ((GAlive or GWatching) and (1 shl p1) <> 0) then419 RW[p1].EnemyReport[ p].Tech[ad] := Source;420 end; 421 422 var 423 i: integer;418 if (p1 <> P) and ((GAlive or GWatching) and (1 shl p1) <> 0) then 419 RW[p1].EnemyReport[P].Tech[ad] := Source; 420 end; 421 422 var 423 I: Integer; 424 424 begin 425 425 if ad in FutureTech then 426 426 begin 427 if RW[ p].Tech[ad] < tsApplicable then428 RW[ p].Tech[ad] := 1427 if RW[P].Tech[ad] < tsApplicable then 428 RW[P].Tech[ad] := 1 429 429 else 430 inc(RW[p].Tech[ad]);430 Inc(RW[P].Tech[ad]); 431 431 if ad <> futResearchTechnology then 432 inc(nTech[p], 2);433 inc(Researched[p], 8);434 exit;435 end; 436 437 if RW[ p].Tech[ad] = tsSeen then438 begin 439 inc(nTech[p]);440 inc(Researched[p]);432 Inc(nTech[P], 2); 433 Inc(Researched[P], 8); 434 Exit; 435 end; 436 437 if RW[P].Tech[ad] = tsSeen then 438 begin 439 Inc(nTech[P]); 440 Inc(Researched[P]); 441 441 end 442 442 else 443 443 begin 444 inc(nTech[p], 2);445 inc(Researched[p], 2);446 end; 447 RW[ p].Tech[ad] := tsResearched;448 TellAboutKeyTech( p, tsResearched);449 CheckSpecialModels( p, ad);444 Inc(nTech[P], 2); 445 Inc(Researched[P], 2); 446 end; 447 RW[P].Tech[ad] := tsResearched; 448 TellAboutKeyTech(P, tsResearched); 449 CheckSpecialModels(P, ad); 450 450 if ad = adScience then 451 ResourceMask[ p] := ResourceMask[p] or fSpecial2;451 ResourceMask[P] := ResourceMask[P] or fSpecial2; 452 452 if ad = adMassProduction then 453 ResourceMask[ p] := ResourceMask[p] or fModern;454 455 for i:= 0 to nWonder - 1 do { check whether wonders expired }456 if (GWonder[ i].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and457 (Imp[ i].Expiration = ad) then458 begin 459 GWonder[ i].EffectiveOwner := -1;460 if i= woPyramids then453 ResourceMask[P] := ResourceMask[P] or fModern; 454 455 for I := 0 to nWonder - 1 do { check whether wonders expired } 456 if (GWonder[I].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and 457 (Imp[I].Expiration = ad) then 458 begin 459 GWonder[I].EffectiveOwner := -1; 460 if I = woPyramids then 461 461 FreeSlaves; 462 462 end; 463 463 end; 464 464 465 procedure CheckExpiration(Wonder: integer);465 procedure CheckExpiration(Wonder: Integer); 466 466 // GWonder[Wonder].EffectiveOwner must be set before! 467 467 var 468 p: integer;468 P: Integer; 469 469 begin 470 470 if (Imp[Wonder].Expiration >= 0) and 471 471 (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) then 472 for p:= 0 to nPl - 1 do // check if already expired473 if (1 shl pand GAlive <> 0) and474 (RW[ p].Tech[Imp[Wonder].Expiration] >= tsApplicable) then472 for P := 0 to nPl - 1 do // check if already expired 473 if (1 shl P and GAlive <> 0) and 474 (RW[P].Tech[Imp[Wonder].Expiration] >= tsApplicable) then 475 475 begin 476 476 GWonder[Wonder].EffectiveOwner := -1; … … 484 484 ____________________________________________________________________ 485 485 } 486 function dLoc(Loc, dx, dy: integer): integer;486 function dLoc(Loc, dx, dy: Integer): Integer; 487 487 { relative location, dx in hor and dy in ver direction from Loc } 488 488 var 489 y0: integer;489 y0: Integer; 490 490 begin 491 491 if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then 492 492 raise Exception.Create('Relative location error'); 493 assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));493 Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0)); 494 494 y0 := Loc div lx; 495 result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);496 if ( result < 0) or (result >= MapSize) then497 result := -1;498 end; 499 500 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);495 Result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy); 496 if (Result < 0) or (Result >= MapSize) then 497 Result := -1; 498 end; 499 500 procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer); 501 501 begin 502 502 dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) - … … 505 505 end; 506 506 507 function Distance(Loc0, Loc1: integer): integer;508 var 509 dx, dy: integer;507 function Distance(Loc0, Loc1: Integer): Integer; 508 var 509 dx, dy: Integer; 510 510 begin 511 511 dxdy(Loc0, Loc1, dx, dy); 512 512 dx := abs(dx); 513 513 dy := abs(dy); 514 result := dx + dy + abs(dx - dy) shr 1;515 end; 516 517 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);518 var 519 x0, y0, lx0: integer;514 Result := dx + dy + abs(dx - dy) shr 1; 515 end; 516 517 procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc); 518 var 519 x0, y0, lx0: Integer; 520 520 begin 521 521 lx0 := lx; // put in register! … … 527 527 VicinityLoc[5] := Loc0 - lx0 * 2; 528 528 VicinityLoc[7] := Loc0 + 1; 529 inc(Loc0, y0);529 Inc(Loc0, y0); 530 530 VicinityLoc[0] := Loc0 + lx0; 531 531 VicinityLoc[2] := Loc0 + lx0 - 1; … … 538 538 if x0 = 0 then 539 539 begin 540 inc(VicinityLoc[3], lx0);540 Inc(VicinityLoc[3], lx0); 541 541 if y0 = 0 then 542 542 begin 543 inc(VicinityLoc[2], lx0);544 inc(VicinityLoc[4], lx0);543 Inc(VicinityLoc[2], lx0); 544 Inc(VicinityLoc[4], lx0); 545 545 end; 546 546 end; … … 548 548 else 549 549 begin 550 dec(VicinityLoc[7], lx0);550 Dec(VicinityLoc[7], lx0); 551 551 if y0 = 1 then 552 552 begin 553 dec(VicinityLoc[0], lx0);554 dec(VicinityLoc[6], lx0);555 end; 556 end; 557 end; 558 559 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);560 var 561 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;562 dst: ^ integer;553 Dec(VicinityLoc[0], lx0); 554 Dec(VicinityLoc[6], lx0); 555 end; 556 end; 557 end; 558 559 procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc); 560 var 561 dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer; 562 dst: ^Integer; 563 563 begin 564 564 y0 := Loc0 div lx; … … 566 566 xCompSwitch := xComp0 - 1 + y0 and 1; 567 567 if xComp0 < 0 then 568 inc(xComp0, lx);568 Inc(xComp0, lx); 569 569 if xCompSwitch < 0 then 570 inc(xCompSwitch, lx);570 Inc(xCompSwitch, lx); 571 571 xCompSwitch := xCompSwitch xor xComp0; 572 572 yComp := lx * (y0 - 3); … … 583 583 else 584 584 dst^ := -1; 585 inc(xComp);585 Inc(xComp); 586 586 if xComp >= lx then 587 dec(xComp, lx);588 inc(dst);587 Dec(xComp, lx); 588 Inc(dst); 589 589 bit := bit shl 1; 590 590 end; 591 inc(yComp, lx);591 Inc(yComp, lx); 592 592 end; 593 593 end; … … 598 598 } 599 599 var 600 primitive: integer;601 StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }600 primitive: Integer; 601 StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates } 602 602 Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation } 603 ElCount: array [Byte] of integer; { count of elevation occurance }603 ElCount: array [Byte] of Integer; { count of elevation occurance } 604 604 605 605 procedure CalculatePrimitive; 606 606 var 607 i, j: integer;607 I, J: Integer; 608 608 begin 609 609 primitive := 1; 610 i:= 2;611 while i * i<= MapSize + 1 do // test whether prime612 begin 613 if (MapSize + 1) mod i= 0 then610 I := 2; 611 while I * I <= MapSize + 1 do // test whether prime 612 begin 613 if (MapSize + 1) mod I = 0 then 614 614 primitive := 0; 615 inc(i);615 Inc(I); 616 616 end; 617 617 618 618 if primitive > 0 then 619 619 repeat 620 inc(primitive);621 i:= 1;622 j:= 0;620 Inc(primitive); 621 I := 1; 622 J := 0; 623 623 repeat 624 inc(j);625 i := i* primitive mod (MapSize + 1);626 until ( i = 1) or (j= MapSize + 1);627 until j= MapSize;628 end; 629 630 function MapGeneratorAvailable: boolean;631 begin 632 result := (primitive > 0) and (lx >= 20) and (ly >= 40);624 Inc(J); 625 I := I * primitive mod (MapSize + 1); 626 until (I = 1) or (J = MapSize + 1); 627 until J = MapSize; 628 end; 629 630 function MapGeneratorAvailable: Boolean; 631 begin 632 Result := (primitive > 0) and (lx >= 20) and (ly >= 40); 633 633 end; 634 634 635 635 procedure CreateElevation; 636 636 const 637 d= 64;637 D = 64; 638 638 Smooth = 0.049; { causes low amplitude of short waves } 639 639 Detail = 0.095; { causes short period of short waves } … … 642 642 643 643 var 644 sa, ca, f1, f2: array [1 .. d] of single;645 imerge, x, y: integer;646 v, maxv: single;647 648 function Value( x, y: integer): single; { elevation formula }644 sa, ca, f1, f2: array [1 .. D] of Single; 645 imerge, X, Y: Integer; 646 V, maxv: Single; 647 648 function Value(X, Y: Integer): Single; { elevation formula } 649 649 var 650 i: integer;651 begin 652 result := 0;653 for i := 1 to ddo654 result := result + sin(f1[i] * ((x * 2 + y and 1) * sa[i] + y* 1.5 *655 ca[ i])) * f2[i];650 I: Integer; 651 begin 652 Result := 0; 653 for I := 1 to D do 654 Result := Result + sin(f1[I] * ((X * 2 + Y and 1) * sa[I] + Y * 1.5 * 655 ca[I])) * f2[I]; 656 656 { x values effectively multiplied with 2 to get 2 horizantal periods 657 657 of the prime waves } … … 659 659 660 660 begin 661 for x := 1 to ddo { prepare formula parameters }662 begin 663 {$IFNDEF SCR} if x= 1 then664 v:= pi / 2 { first wave goes horizontal }665 else {$ENDIF} v:= DelphiRandom * 2 * pi;666 sa[ x] := sin(v) / lx;667 ca[ x] := cos(v) / ly;668 f1[ x] := 2 * pi * exp(Detail * (x- 1));669 f2[ x] := exp(-x* Smooth);661 for X := 1 to D do { prepare formula parameters } 662 begin 663 {$IFNDEF SCR} if X = 1 then 664 V := pi / 2 { first wave goes horizontal } 665 else {$ENDIF} V := DelphiRandom * 2 * pi; 666 sa[X] := sin(V) / lx; 667 ca[X] := cos(V) / ly; 668 f1[X] := 2 * pi * exp(Detail * (X - 1)); 669 f2[X] := exp(-X * Smooth); 670 670 end; 671 671 … … 673 673 FillChar(ElCount, SizeOf(ElCount), 0); 674 674 maxv := 0; 675 for x:= 0 to lx - 1 do676 for y:= 0 to ly - 1 do677 begin 678 v := Value(x, y);679 if x* 2 < imerge then680 v := (x * 2 * v + (imerge - x * 2) * Value(x + lx, y)) / imerge;681 v := v - sqr(sqr(2 * y/ ly - 1)); { soft cut at poles }682 if v> maxv then683 maxv := v;684 685 if v< -4 then686 Elevation[ x + lx * y] := 0687 else if v> 8.75 then688 Elevation[ x + lx * y] := 255675 for X := 0 to lx - 1 do 676 for Y := 0 to ly - 1 do 677 begin 678 V := Value(X, Y); 679 if X * 2 < imerge then 680 V := (X * 2 * V + (imerge - X * 2) * Value(X + lx, Y)) / imerge; 681 V := V - sqr(sqr(2 * Y / ly - 1)); { soft cut at poles } 682 if V > maxv then 683 maxv := V; 684 685 if V < -4 then 686 Elevation[X + lx * Y] := 0 687 else if V > 8.75 then 688 Elevation[X + lx * Y] := 255 689 689 else 690 Elevation[ x + lx * y] := Round((v+ 4) * 20);691 inc(ElCount[Elevation[x + lx * y]]);690 Elevation[X + lx * Y] := Round((V + 4) * 20); 691 Inc(ElCount[Elevation[X + lx * Y]]); 692 692 end; 693 693 end; … … 695 695 procedure FindContinents; 696 696 697 procedure ReplaceCont( a, b, Stop: integer);697 procedure ReplaceCont(A, B, Stop: Integer); 698 698 { replace continent name a by b } 699 699 // make sure always continent[loc]<=loc 700 700 var 701 i: integer;702 begin 703 if a < bthen704 begin 705 i := a;706 a := b;707 b := i708 end; 709 if a > bthen710 for i := ato Stop do711 if Continent[ i] = athen712 Continent[ i] := b;713 end; 714 715 var 716 x, y, Loc, Wrong: integer;717 begin 718 for y:= 1 to ly - 2 do719 for x:= 0 to lx - 1 do720 begin 721 Loc := x + lx * y;701 I: Integer; 702 begin 703 if A < B then 704 begin 705 I := A; 706 A := B; 707 B := I 708 end; 709 if A > B then 710 for I := A to Stop do 711 if Continent[I] = A then 712 Continent[I] := B; 713 end; 714 715 var 716 X, Y, Loc, Wrong: Integer; 717 begin 718 for Y := 1 to ly - 2 do 719 for X := 0 to lx - 1 do 720 begin 721 Loc := X + lx * Y; 722 722 Continent[Loc] := -1; 723 723 if RealMap[Loc] and fTerrain >= fGrass then 724 724 begin 725 if ( y- 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then725 if (Y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then 726 726 Continent[Loc] := Continent[Loc - 2 * lx]; 727 if ( x - 1 + y and 1 >= 0) and (y- 1 >= 1) and728 (RealMap[Loc - 1 + yand 1 - lx] and fTerrain >= fGrass) then729 Continent[Loc] := Continent[Loc - 1 + yand 1 - lx];730 if ( x + y and 1 < lx) and (y- 1 >= 1) and731 (RealMap[Loc + yand 1 - lx] and fTerrain >= fGrass) then732 Continent[Loc] := Continent[Loc + yand 1 - lx];733 if ( x- 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then727 if (X - 1 + Y and 1 >= 0) and (Y - 1 >= 1) and 728 (RealMap[Loc - 1 + Y and 1 - lx] and fTerrain >= fGrass) then 729 Continent[Loc] := Continent[Loc - 1 + Y and 1 - lx]; 730 if (X + Y and 1 < lx) and (Y - 1 >= 1) and 731 (RealMap[Loc + Y and 1 - lx] and fTerrain >= fGrass) then 732 Continent[Loc] := Continent[Loc + Y and 1 - lx]; 733 if (X - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then 734 734 if Continent[Loc] = -1 then 735 735 Continent[Loc] := Continent[Loc - 1] … … 742 742 743 743 { connect continents due to round earth } 744 for y:= 1 to ly - 2 do745 if RealMap[lx * y] and fTerrain >= fGrass then744 for Y := 1 to ly - 2 do 745 if RealMap[lx * Y] and fTerrain >= fGrass then 746 746 begin 747 747 Wrong := -1; 748 if RealMap[lx - 1 + lx * y] and fTerrain >= fGrass then749 Wrong := Continent[lx - 1 + lx * y];750 if ( y and 1 = 0) and (y- 1 >= 1) and751 (RealMap[lx - 1 + lx * ( y- 1)] and fTerrain >= fGrass) then752 Wrong := Continent[lx - 1 + lx * ( y- 1)];753 if ( y and 1 = 0) and (y+ 1 < ly - 1) and754 (RealMap[lx - 1 + lx * ( y+ 1)] and fTerrain >= fGrass) then755 Wrong := Continent[lx - 1 + lx * ( y+ 1)];748 if RealMap[lx - 1 + lx * Y] and fTerrain >= fGrass then 749 Wrong := Continent[lx - 1 + lx * Y]; 750 if (Y and 1 = 0) and (Y - 1 >= 1) and 751 (RealMap[lx - 1 + lx * (Y - 1)] and fTerrain >= fGrass) then 752 Wrong := Continent[lx - 1 + lx * (Y - 1)]; 753 if (Y and 1 = 0) and (Y + 1 < ly - 1) and 754 (RealMap[lx - 1 + lx * (Y + 1)] and fTerrain >= fGrass) then 755 Wrong := Continent[lx - 1 + lx * (Y + 1)]; 756 756 if Wrong >= 0 then 757 ReplaceCont(Wrong, Continent[lx * y], MapSize - 1);757 ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1); 758 758 end; 759 759 end; … … 763 763 // must be done after FindContinents 764 764 var 765 i, j, Cnt, x, y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,766 RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: integer;767 AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of integer;768 RareLoc: array [0 .. 11] of integer;769 Dist: array [0 .. 11, 0 .. 11] of integer;765 I, J, Cnt, X, Y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater, 766 RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: Integer; 767 AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of Integer; 768 RareLoc: array [0 .. 11] of Integer; 769 Dist: array [0 .. 11, 0 .. 11] of Integer; 770 770 Adjacent: TVicinity8Loc; 771 771 begin … … 773 773 repeat 774 774 FillChar(AreaCount, SizeOf(AreaCount), 0); 775 for y:= 1 to ly - 2 do776 begin 777 yBlock := y* 5 div ly;778 if yBlock = ( y+ 1) * 5 div ly then779 for x:= 0 to lx - 1 do780 begin 781 xBlock := x* 8 div lx;782 if xBlock = ( x+ 1) * 8 div lx then775 for Y := 1 to ly - 2 do 776 begin 777 yBlock := Y * 5 div ly; 778 if yBlock = (Y + 1) * 5 div ly then 779 for X := 0 to lx - 1 do 780 begin 781 xBlock := X * 8 div lx; 782 if xBlock = (X + 1) * 8 div lx then 783 783 begin 784 Loc0 := x + lx * y;784 Loc0 := X + lx * Y; 785 785 if RealMap[Loc0] and fTerrain >= fGrass then 786 786 begin … … 792 792 if (Loc1 >= 0) and (Loc1 < MapSize) and 793 793 (RealMap[Loc1] and fTerrain < fGrass) then 794 inc(Cnt); // count adjacent water794 Inc(Cnt); // count adjacent water 795 795 end; 796 796 if Cnt <= RareMaxWater then // inner land 797 797 begin 798 inc(AreaCount[xBlock, yBlock]);798 Inc(AreaCount[xBlock, yBlock]); 799 799 if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then 800 800 RareByArea[xBlock, yBlock] := Loc0; … … 805 805 end; 806 806 totalrare := 0; 807 for x:= 0 to 7 do808 for y:= 0 to 4 do809 if AreaCount[ x, y] > 0 then810 inc(totalrare);811 inc(RareMaxWater);807 for X := 0 to 7 do 808 for Y := 0 to 4 do 809 if AreaCount[X, Y] > 0 then 810 Inc(totalrare); 811 Inc(RareMaxWater); 812 812 until totalrare >= 12; 813 813 … … 815 815 begin // remove rarebyarea resources too close to each other 816 816 FillChar(RareAdjacent, SizeOf(RareAdjacent), 0); 817 for x:= 0 to 7 do818 for y:= 0 to 4 do819 if AreaCount[ x, y] > 0 then820 begin 821 if (AreaCount[( x + 1) mod 8, y] > 0) and822 (Continent[RareByArea[ x, y]] = Continent823 [RareByArea[( x + 1) mod 8, y]]) then817 for X := 0 to 7 do 818 for Y := 0 to 4 do 819 if AreaCount[X, Y] > 0 then 820 begin 821 if (AreaCount[(X + 1) mod 8, Y] > 0) and 822 (Continent[RareByArea[X, Y]] = Continent 823 [RareByArea[(X + 1) mod 8, Y]]) then 824 824 begin 825 inc(RareAdjacent[x, y]);826 inc(RareAdjacent[(x + 1) mod 8, y]);825 Inc(RareAdjacent[X, Y]); 826 Inc(RareAdjacent[(X + 1) mod 8, Y]); 827 827 end; 828 if y< 4 then828 if Y < 4 then 829 829 begin 830 if (AreaCount[ x, y+ 1] > 0) and831 (Continent[RareByArea[ x, y]] = Continent[RareByArea[x, y+ 1]])830 if (AreaCount[X, Y + 1] > 0) and 831 (Continent[RareByArea[X, Y]] = Continent[RareByArea[X, Y + 1]]) 832 832 then 833 833 begin 834 inc(RareAdjacent[x, y]);835 inc(RareAdjacent[x, y+ 1]);834 Inc(RareAdjacent[X, Y]); 835 Inc(RareAdjacent[X, Y + 1]); 836 836 end; 837 if (AreaCount[( x + 1) mod 8, y+ 1] > 0) and838 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 1) mod 8,839 y+ 1]]) then837 if (AreaCount[(X + 1) mod 8, Y + 1] > 0) and 838 (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 1) mod 8, 839 Y + 1]]) then 840 840 begin 841 inc(RareAdjacent[x, y]);842 inc(RareAdjacent[(x + 1) mod 8, y+ 1]);841 Inc(RareAdjacent[X, Y]); 842 Inc(RareAdjacent[(X + 1) mod 8, Y + 1]); 843 843 end; 844 if (AreaCount[( x + 7) mod 8, y+ 1] > 0) and845 (Continent[RareByArea[ x, y]] = Continent[RareByArea[(x+ 7) mod 8,846 y+ 1]]) then844 if (AreaCount[(X + 7) mod 8, Y + 1] > 0) and 845 (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 7) mod 8, 846 Y + 1]]) then 847 847 begin 848 inc(RareAdjacent[x, y]);849 inc(RareAdjacent[(x + 7) mod 8, y+ 1]);848 Inc(RareAdjacent[X, Y]); 849 Inc(RareAdjacent[(X + 7) mod 8, Y + 1]); 850 850 end; 851 851 end; … … 854 854 yworst := 0; 855 855 Cnt := 0; 856 for x:= 0 to 7 do857 for y:= 0 to 4 do858 if AreaCount[ x, y] > 0 then859 begin 860 if (Cnt = 0) or (RareAdjacent[ x, y] > RareAdjacent[xworst, yworst])856 for X := 0 to 7 do 857 for Y := 0 to 4 do 858 if AreaCount[X, Y] > 0 then 859 begin 860 if (Cnt = 0) or (RareAdjacent[X, Y] > RareAdjacent[xworst, yworst]) 861 861 then 862 862 begin 863 xworst := x;864 yworst := y;863 xworst := X; 864 yworst := Y; 865 865 Cnt := 1; 866 866 end 867 else if (RareAdjacent[ x, y] = RareAdjacent[xworst, yworst]) then867 else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then 868 868 begin 869 inc(Cnt);869 Inc(Cnt); 870 870 if DelphiRandom(Cnt) = 0 then 871 871 begin 872 xworst := x;873 yworst := y;872 xworst := X; 873 yworst := Y; 874 874 end; 875 875 end; 876 876 end; 877 877 AreaCount[xworst, yworst] := 0; 878 dec(totalrare);878 Dec(totalrare); 879 879 end; 880 880 881 881 Cnt := 0; 882 for x:= 0 to 7 do883 for y:= 0 to 4 do884 if AreaCount[ x, y] > 0 then885 begin 886 RareLoc[Cnt] := RareByArea[ x, y];887 inc(Cnt);888 end; 889 for i:= 0 to 11 do890 begin 891 RealMap[RareLoc[ i]] := RealMap[RareLoc[i]] and not(fTerrain or fSpecial) or882 for X := 0 to 7 do 883 for Y := 0 to 4 do 884 if AreaCount[X, Y] > 0 then 885 begin 886 RareLoc[Cnt] := RareByArea[X, Y]; 887 Inc(Cnt); 888 end; 889 for I := 0 to 11 do 890 begin 891 RealMap[RareLoc[I]] := RealMap[RareLoc[I]] and not(fTerrain or fSpecial) or 892 892 (fDesert or fDeadLands); 893 893 for dy := -1 to 1 do … … 895 895 if (dx + dy) and 1 = 0 then 896 896 begin 897 Loc1 := dLoc(RareLoc[ i], dx, dy);897 Loc1 := dLoc(RareLoc[I], dx, dy); 898 898 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then 899 899 RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills; 900 900 end; 901 901 end; 902 for i:= 0 to 11 do903 for j:= 0 to 11 do904 Dist[ i, j] := Distance(RareLoc[i], RareLoc[j]);902 for I := 0 to 11 do 903 for J := 0 to 11 do 904 Dist[I, J] := Distance(RareLoc[I], RareLoc[J]); 905 905 906 906 ibest := 0; … … 910 910 begin 911 911 Cnt := 0; 912 for i:= 0 to 11 do913 if RareLoc[ i] >= 0 then914 for j:= 0 to 11 do915 if RareLoc[ j] >= 0 then912 for I := 0 to 11 do 913 if RareLoc[I] >= 0 then 914 for J := 0 to 11 do 915 if RareLoc[J] >= 0 then 916 916 if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then 917 917 begin 918 if Dist[ i, j] >= MinDist then918 if Dist[I, J] >= MinDist then 919 919 begin 920 inc(Cnt);920 Inc(Cnt); 921 921 if DelphiRandom(Cnt) = 0 then 922 922 begin 923 iBest := i;924 jbest := j;923 iBest := I; 924 jbest := J; 925 925 end; 926 926 end; 927 927 end 928 else if (Cnt = 0) or (Dist[ i, j] > Dist[iBest, jbest]) then928 else if (Cnt = 0) or (Dist[I, J] > Dist[iBest, jbest]) then 929 929 begin 930 iBest := i;931 jbest := j;930 iBest := I; 931 jbest := J; 932 932 Cnt := 1; 933 933 end; … … 941 941 end; 942 942 943 function CheckShore(Loc: integer): boolean;944 var 945 Loc1, OldTile, V21: integer;943 function CheckShore(Loc: Integer): Boolean; 944 var 945 Loc1, OldTile, V21: Integer; 946 946 Radius: TVicinity21Loc; 947 947 begin 948 result := false;948 Result := False; 949 949 OldTile := RealMap[Loc]; 950 950 if OldTile and fTerrain < fGrass then … … 961 961 end; 962 962 if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then 963 result := true;964 end; 965 end; 966 967 function ActualSpecialTile(Loc: integer): Cardinal;968 begin 969 result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);970 end; 971 972 procedure CreateMap(preview: boolean);963 Result := True; 964 end; 965 end; 966 967 function ActualSpecialTile(Loc: Integer): Cardinal; 968 begin 969 Result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx); 970 end; 971 972 procedure CreateMap(preview: Boolean); 973 973 const 974 974 ShHiHills = 6; { of land } … … 981 981 hotunification = 50; // min. 25 982 982 983 Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }983 Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution } 984 984 ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35), 985 985 (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3)); 986 986 { Grs Dst Pra Tun - - - For } 987 987 988 function RndLow( y: integer): Cardinal;988 function RndLow(Y: Integer): Cardinal; 989 989 { random lowland appropriate to climate } 990 990 var 991 z0, i: integer;992 p, p0, ZPlus: single;993 begin 994 if ly - 1 - y > ythen995 begin 996 z0 := 6 * ydiv ly;997 ZPlus := 6 * y/ ly - z0;991 z0, I: Integer; 992 P, p0, ZPlus: Single; 993 begin 994 if ly - 1 - Y > Y then 995 begin 996 z0 := 6 * Y div ly; 997 ZPlus := 6 * Y / ly - z0; 998 998 end 999 999 else 1000 1000 begin 1001 z0 := 6 * (ly - 1 - y) div ly;1002 ZPlus := 6 * (ly - 1 - y) / ly - z0;1001 z0 := 6 * (ly - 1 - Y) div ly; 1002 ZPlus := 6 * (ly - 1 - Y) / ly - z0; 1003 1003 end; 1004 1004 p0 := 1; 1005 for i:= 2 to 9 do1006 begin 1007 p := Zone[z0, i] * (1 - ZPlus) + Zone[z0 + 1, i] * ZPlus;1005 for I := 2 to 9 do 1006 begin 1007 P := Zone[z0, I] * (1 - ZPlus) + Zone[z0 + 1, I] * ZPlus; 1008 1008 { weight between zones z0 and z0+1 } 1009 if DelphiRandom * p0 < pthen1010 begin 1011 RndLow := i;1009 if DelphiRandom * p0 < P then 1010 begin 1011 RndLow := I; 1012 1012 Break; 1013 1013 end; 1014 p0 := p0 - p;1015 end; 1016 end; 1017 1018 function RunRiver(Loc0: integer): integer;1014 p0 := p0 - P; 1015 end; 1016 end; 1017 1018 function RunRiver(Loc0: Integer): Integer; 1019 1019 { runs river from start point Loc0; return value: length } 1020 1020 var 1021 Dir, T, Loc, Loc1, Cost: integer;1021 Dir, T, Loc, Loc1, Cost: Integer; 1022 1022 Q: TIPQ; 1023 From: array [0 .. lxmax * lymax - 1] of integer;1024 Time: array [0 .. lxmax * lymax - 1] of integer;1025 OneTileLake: boolean;1023 From: array [0 .. lxmax * lymax - 1] of Integer; 1024 Time: array [0 .. lxmax * lymax - 1] of Integer; 1025 OneTileLake: Boolean; 1026 1026 begin 1027 1027 FillChar(Time, SizeOf(Time), 255); { -1 } … … 1032 1032 if (RealMap[Loc] and fTerrain < fGrass) then 1033 1033 begin 1034 OneTileLake := true;1034 OneTileLake := True; 1035 1035 for Dir := 0 to 3 do 1036 1036 begin 1037 1037 Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1); 1038 1038 if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then 1039 OneTileLake := false;1039 OneTileLake := False; 1040 1040 end; 1041 1041 if not OneTileLake then … … 1062 1062 end; 1063 1063 Loc1 := Loc; 1064 result := 0;1064 Result := 0; 1065 1065 while Loc <> Loc0 do 1066 1066 begin 1067 1067 Loc := From[Loc]; 1068 inc(result);1069 end; 1070 if ( result > 1) and ((result >= MinRivLen) or1068 Inc(Result); 1069 end; 1070 if (Result > 1) and ((Result >= MinRivLen) or 1071 1071 (RealMap[Loc1] and fTerrain >= fGrass)) then 1072 1072 begin … … 1082 1082 end 1083 1083 else 1084 result := 0;1084 Result := 0; 1085 1085 FreeAndNil(Q); 1086 1086 end; 1087 1087 1088 1088 var 1089 x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;1090 CopyFrom: array [0 .. lxmax * lymax - 1] of integer;1089 X, Y, N, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: Integer; 1090 CopyFrom: array [0 .. lxmax * lymax - 1] of Integer; 1091 1091 Adjacent: TVicinity8Loc; 1092 1092 … … 1097 1097 while plus < MapSize * LandMass * ShMountains div 10000 do 1098 1098 begin 1099 dec(bMountains);1100 inc(plus, ElCount[bMountains]);1099 Dec(bMountains); 1100 Inc(plus, ElCount[bMountains]); 1101 1101 end; 1102 1102 Count := plus; … … 1105 1105 while plus < MapSize * LandMass * ShHiHills div 10000 do 1106 1106 begin 1107 dec(bHills);1108 inc(plus, ElCount[bHills]);1109 end; 1110 inc(Count, plus);1107 Dec(bHills); 1108 Inc(plus, ElCount[bHills]); 1109 end; 1110 Inc(Count, plus); 1111 1111 bLand := bHills; 1112 1112 while Count < MapSize * LandMass div 100 do 1113 1113 begin 1114 dec(bLand);1115 inc(Count, ElCount[bLand]);1114 Dec(bLand); 1115 Inc(Count, ElCount[bLand]); 1116 1116 end; 1117 1117 … … 1136 1136 (RealMap[Loc1] and fTerrain < fGrass) or 1137 1137 (RealMap[Loc1] and fTerrain = fArctic) then 1138 inc(Count); // count adjacent water1138 Inc(Count); // count adjacent water 1139 1139 end; 1140 1140 if Count = 8 then … … 1148 1148 plus := MapSize; 1149 1149 Loc0 := DelphiRandom(MapSize); 1150 for n:= 0 to plus - 1 do1150 for N := 0 to plus - 1 do 1151 1151 begin 1152 1152 if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and … … 1165 1165 CopyFrom[Loc0] := Loc0; 1166 1166 1167 for n:= 0 to unification * MapSize div 100 do1168 begin 1169 y:= DelphiRandom(ly);1170 if abs( y- (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then1171 if y< ly shr 1 then1172 y := ly shr 1 - y1167 for N := 0 to unification * MapSize div 100 do 1168 begin 1169 Y := DelphiRandom(ly); 1170 if abs(Y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then 1171 if Y < ly shr 1 then 1172 Y := ly shr 1 - Y 1173 1173 else 1174 y := 3 * ly shr 1 - y;1175 Loc0 := lx * y+ DelphiRandom(lx);1174 Y := 3 * ly shr 1 - Y; 1175 Loc0 := lx * Y + DelphiRandom(lx); 1176 1176 if RealMap[Loc0] and fTerrain = fGrass then 1177 1177 begin … … 1226 1226 if Loc1 >= 0 then 1227 1227 if RealMap[Loc1] and fTerrain < fGrass then 1228 inc(Count, 2);1228 Inc(Count, 2); 1229 1229 end; 1230 1230 end; … … 1242 1242 if Loc1 >= 0 then 1243 1243 if RealMap[Loc1] and fTerrain <> fDesert then 1244 inc(Count);1244 Inc(Count); 1245 1245 end; 1246 1246 if Count >= 4 then … … 1250 1250 for Loc0 := 0 to MapSize - 1 do 1251 1251 CheckShore(Loc0); // change ocean to shore 1252 for x:= 0 to lx - 1 do1253 begin 1254 RealMap[ x+ lx * 0] := fArctic;1255 if RealMap[ x+ lx * 1] >= fGrass then1256 RealMap[ x + lx * 1] := RealMap[x+ lx * 1] and not fTerrain or fTundra;1257 if RealMap[ x+ lx * (ly - 2)] >= fGrass then1258 RealMap[ x + lx * (ly - 2)] := RealMap[x+ lx * (ly - 2)] and1252 for X := 0 to lx - 1 do 1253 begin 1254 RealMap[X + lx * 0] := fArctic; 1255 if RealMap[X + lx * 1] >= fGrass then 1256 RealMap[X + lx * 1] := RealMap[X + lx * 1] and not fTerrain or fTundra; 1257 if RealMap[X + lx * (ly - 2)] >= fGrass then 1258 RealMap[X + lx * (ly - 2)] := RealMap[X + lx * (ly - 2)] and 1259 1259 not fTerrain or fTundra; 1260 RealMap[ x+ lx * (ly - 1)] := fArctic;1260 RealMap[X + lx * (ly - 1)] := fArctic; 1261 1261 end; 1262 1262 … … 1279 1279 CountGood: (cgBest, cgFlat, cgLand); 1280 1280 1281 function IsGoodTile(Loc: integer): boolean;1281 function IsGoodTile(Loc: Integer): Boolean; 1282 1282 var 1283 xLoc, yLoc: integer;1283 xLoc, yLoc: Integer; 1284 1284 begin 1285 1285 xLoc := Loc mod lx; 1286 1286 yLoc := Loc div lx; 1287 1287 if RealMap[Loc] and fDeadLands <> 0 then 1288 result := false1288 Result := False 1289 1289 else 1290 1290 case CountGood of 1291 1291 cgBest: 1292 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1292 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1293 1293 fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc + 1294 1294 (yLoc + 1) shr 1); 1295 1295 cgFlat: 1296 result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,1296 Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra, 1297 1297 fSwamp, fForest]); 1298 1298 cgLand: 1299 result := RealMap[Loc] and fTerrain >= fGrass;1299 Result := RealMap[Loc] and fTerrain >= fGrass; 1300 1300 end; 1301 1301 end; … … 1305 1305 1306 1306 var 1307 p1, p2, nAlive, c, Loc, Loc1, CntGood, CntGoodGrass, MinDist, i, j, n,1307 p1, p2, nAlive, C, Loc, Loc1, CntGood, CntGoodGrass, MinDist, I, J, N, 1308 1308 nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc, 1309 FineDistSQR, nRest: integer;1310 ccount: array [0 .. lxmax * lymax - 1] of word;1311 sc, StartLoc0, sccount: array [1 .. nPl] of integer;1312 TestStartLoc: array [0 .. nPl - 1] of integer;1313 CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of integer;1314 nCityLoc: array [1 .. nPl] of integer;1315 RestLoc: array [0 .. MaxCityLoc - 1] of integer;1316 IrrLoc: array [0 .. 20] of integer;1309 FineDistSQR, nRest: Integer; 1310 ccount: array [0 .. lxmax * lymax - 1] of Word; 1311 sc, StartLoc0, sccount: array [1 .. nPl] of Integer; 1312 TestStartLoc: array [0 .. nPl - 1] of Integer; 1313 CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of Integer; 1314 nCityLoc: array [1 .. nPl] of Integer; 1315 RestLoc: array [0 .. MaxCityLoc - 1] of Integer; 1316 IrrLoc: array [0 .. 20] of Integer; 1317 1317 Radius: TVicinity21Loc; 1318 1318 Adjacent: TVicinity8Loc; 1319 ok: boolean;1319 ok: Boolean; 1320 1320 1321 1321 begin … … 1323 1323 for p1 := 0 to nPl - 1 do 1324 1324 if 1 shl p1 and GAlive <> 0 then 1325 inc(nAlive);1325 Inc(nAlive); 1326 1326 if nAlive = 0 then 1327 exit;1327 Exit; 1328 1328 1329 1329 { count good tiles } … … 1332 1332 if RealMap[Loc] and fTerrain = fGrass then 1333 1333 if ActualSpecialTile(Loc) = 1 then 1334 inc(ccount[Continent[Loc]], 3)1334 Inc(ccount[Continent[Loc]], 3) 1335 1335 else 1336 inc(ccount[Continent[Loc]], 2)1336 Inc(ccount[Continent[Loc]], 2) 1337 1337 else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills] 1338 1338 then 1339 inc(ccount[Continent[Loc]]);1339 Inc(ccount[Continent[Loc]]); 1340 1340 1341 1341 Loc := 0; 1342 1342 while ccount[Loc] > 0 do 1343 inc(Loc);1344 for i:= 1 to nAlive do1345 begin 1346 sc[ i] := Loc;1347 sccount[ i] := 11343 Inc(Loc); 1344 for I := 1 to nAlive do 1345 begin 1346 sc[I] := Loc; 1347 sccount[I] := 1 1348 1348 end; 1349 1349 { init with zero size start continents, then search bigger ones } … … 1356 1356 if p1 < nAlive + 1 then 1357 1357 sc[p1] := sc[p1 - 1]; 1358 dec(p1);1358 Dec(p1); 1359 1359 end; 1360 1360 if p1 < nAlive + 1 then … … 1363 1363 nsc := nAlive; 1364 1364 repeat 1365 c:= 1; // search least crowded continent after smallest1366 for i:= 2 to nsc - 1 do1367 if ccount[sc[ i]] * (2 * sccount[c] + 1) > ccount[sc[c]] *1368 (2 * sccount[ i] + 1) then1369 c := i;1370 if ccount[sc[nsc]] * (2 * sccount[ c] + 1) > ccount[sc[c]] then1365 C := 1; // search least crowded continent after smallest 1366 for I := 2 to nsc - 1 do 1367 if ccount[sc[I]] * (2 * sccount[C] + 1) > ccount[sc[C]] * 1368 (2 * sccount[I] + 1) then 1369 C := I; 1370 if ccount[sc[nsc]] * (2 * sccount[C] + 1) > ccount[sc[C]] then 1371 1371 Break; // even least crowded continent is more crowded than smallest 1372 inc(sccount[c]);1373 dec(nsc);1372 Inc(sccount[C]); 1373 Dec(nsc); 1374 1374 until sccount[nsc] > 1; 1375 1375 … … 1377 1377 CountGood := cgBest; 1378 1378 repeat 1379 dec(MinGood);1379 Dec(MinGood); 1380 1380 if (MinGood = 3) and (CountGood < cgLand) then // too demanding! 1381 1381 begin 1382 inc(CountGood);1382 Inc(CountGood); 1383 1383 MinGood := 6; 1384 1384 end; 1385 1385 FillChar(nCityLoc, SizeOf(nCityLoc), 0); 1386 1386 Loc := DelphiRandom(MapSize); 1387 for i:= 0 to MapSize - 1 do1387 for I := 0 to MapSize - 1 do 1388 1388 begin 1389 1389 if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand)) 1390 1390 and IsGoodTile(Loc) then 1391 1391 begin 1392 c:= nsc;1393 while ( c > 0) and (Continent[Loc] <> sc[c]) do1394 dec(c);1395 if ( c > 0) and (nCityLoc[c] < MaxCityLoc) then1392 C := nsc; 1393 while (C > 0) and (Continent[Loc] <> sc[C]) do 1394 Dec(C); 1395 if (C > 0) and (nCityLoc[C] < MaxCityLoc) then 1396 1396 begin 1397 1397 CntGood := 1; … … 1402 1402 Loc1 := Radius[V21]; 1403 1403 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1404 inc(CntGood);1404 Inc(CntGood); 1405 1405 end; 1406 1406 if CntGood >= MinGood then 1407 1407 begin 1408 CityLoc[ c, nCityLoc[c]] := Loc;1409 inc(nCityLoc[c]);1408 CityLoc[C, nCityLoc[C]] := Loc; 1409 Inc(nCityLoc[C]); 1410 1410 end; 1411 1411 end; … … 1414 1414 end; 1415 1415 1416 ok := true;1417 for c:= 1 to nsc do1418 if nCityLoc[ c] < sccount[c] * (8 - MinGood) div (7 - MinGood) then1419 ok := false;1416 ok := True; 1417 for C := 1 to nsc do 1418 if nCityLoc[C] < sccount[C] * (8 - MinGood) div (7 - MinGood) then 1419 ok := False; 1420 1420 until ok; 1421 1421 1422 1422 FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100); 1423 1423 p1 := 1; 1424 for c:= 1 to nsc do1424 for C := 1 to nsc do 1425 1425 begin // for all start continents 1426 if sccount[ c] = 1 then1427 StartLoc0[p1] := CityLoc[ c, DelphiRandom(nCityLoc[c])]1426 if sccount[C] = 1 then 1427 StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])] 1428 1428 else 1429 1429 begin 1430 1430 BestDist := 0; 1431 n := 1 shl sccount[c] * 32; // number of tries to find good distribution1432 if n> 1 shl 12 then1433 n:= 1 shl 12;1434 while ( n> 0) and (BestDist * BestDist < FineDistSQR) do1431 N := 1 shl sccount[C] * 32; // number of tries to find good distribution 1432 if N > 1 shl 12 then 1433 N := 1 shl 12; 1434 while (N > 0) and (BestDist * BestDist < FineDistSQR) do 1435 1435 begin 1436 1436 MinDist := MaxInt; 1437 nRest := nCityLoc[ c];1438 for i:= 0 to nRest - 1 do1439 RestLoc[ i] := CityLoc[c, i];1440 for i := 0 to sccount[c] - 1 do1437 nRest := nCityLoc[C]; 1438 for I := 0 to nRest - 1 do 1439 RestLoc[I] := CityLoc[C, I]; 1440 for I := 0 to sccount[C] - 1 do 1441 1441 begin 1442 1442 if nRest = 0 then 1443 1443 Break; 1444 j:= DelphiRandom(nRest);1445 TestStartLoc[ i] := RestLoc[j];1446 RestLoc[ j] := RestLoc[nRest - 1];1447 dec(nRest);1448 for j := 0 to i- 1 do1444 J := DelphiRandom(nRest); 1445 TestStartLoc[I] := RestLoc[J]; 1446 RestLoc[J] := RestLoc[nRest - 1]; 1447 Dec(nRest); 1448 for J := 0 to I - 1 do 1449 1449 begin 1450 TestDist := Distance(TestStartLoc[ i], TestStartLoc[j]);1450 TestDist := Distance(TestStartLoc[I], TestStartLoc[J]); 1451 1451 if TestDist < MinDist then 1452 1452 MinDist := TestDist; 1453 1453 end; 1454 if i = sccount[c] - 1 then1454 if I = sccount[C] - 1 then 1455 1455 begin 1456 assert(MinDist > BestDist);1456 Assert(MinDist > BestDist); 1457 1457 BestDist := MinDist; 1458 for j := 0 to sccount[c] - 1 do1459 StartLoc0[p1 + j] := TestStartLoc[j];1458 for J := 0 to sccount[C] - 1 do 1459 StartLoc0[p1 + J] := TestStartLoc[J]; 1460 1460 end 1461 1461 else if BestDist > 0 then 1462 1462 begin 1463 j:= 0;1464 while j< nRest do1463 J := 0; 1464 while J < nRest do 1465 1465 begin // remove all locs from rest which have too little distance to this one 1466 TestDist := Distance(TestStartLoc[ i], RestLoc[j]);1466 TestDist := Distance(TestStartLoc[I], RestLoc[J]); 1467 1467 if TestDist <= BestDist then 1468 1468 begin 1469 RestLoc[ j] := RestLoc[nRest - 1];1470 dec(nRest);1469 RestLoc[J] := RestLoc[nRest - 1]; 1470 Dec(nRest); 1471 1471 end 1472 1472 else 1473 inc(j);1473 Inc(J); 1474 1474 end; 1475 1475 end; 1476 1476 end; 1477 dec(n)1478 end; 1479 end; 1480 p1 := p1 + sccount[ c]1477 Dec(N) 1478 end; 1479 end; 1480 p1 := p1 + sccount[C] 1481 1481 end; 1482 1482 … … 1495 1495 if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then 1496 1496 if RealMap[Loc1] and fTerrain = fGrass then 1497 inc(CntGoodGrass)1497 Inc(CntGoodGrass) 1498 1498 else 1499 inc(CntGood);1499 Inc(CntGood); 1500 1500 end; 1501 1501 for V21 := 1 to 26 do … … 1529 1529 begin 1530 1530 IrrLoc[nIrrLoc] := Loc1; 1531 inc(nIrrLoc);1532 end; 1533 end; 1534 i:= 2;1535 if i> nIrrLoc then1536 i:= nIrrLoc;1537 while i> 0 do1538 begin 1539 j:= DelphiRandom(nIrrLoc);1540 RealMap[IrrLoc[ j]] := RealMap[IrrLoc[j]] or tiIrrigation;1541 IrrLoc[ j] := IrrLoc[nIrrLoc - 1];1542 dec(nIrrLoc);1543 dec(i);1531 Inc(nIrrLoc); 1532 end; 1533 end; 1534 I := 2; 1535 if I > nIrrLoc then 1536 I := nIrrLoc; 1537 while I > 0 do 1538 begin 1539 J := DelphiRandom(nIrrLoc); 1540 RealMap[IrrLoc[J]] := RealMap[IrrLoc[J]] or tiIrrigation; 1541 IrrLoc[J] := IrrLoc[nIrrLoc - 1]; 1542 Dec(nIrrLoc); 1543 Dec(I); 1544 1544 end; 1545 1545 end; … … 1550 1550 begin 1551 1551 repeat 1552 i:= DelphiRandom(nAlive) + 11553 until StartLoc0[ i] >= 0;1554 StartLoc[p1] := StartLoc0[ i];1555 StartLoc0[ i] := -11552 I := DelphiRandom(nAlive) + 1 1553 until StartLoc0[I] >= 0; 1554 StartLoc[p1] := StartLoc0[I]; 1555 StartLoc0[I] := -1 1556 1556 end; 1557 1557 SaveMapCenterLoc := StartLoc[0]; … … 1586 1586 StartLoc2[p1] := Loc1; 1587 1587 BestDist := TestDist; 1588 n:= 1;1588 N := 1; 1589 1589 end 1590 1590 else if TestDist = BestDist then 1591 1591 begin 1592 inc(n);1593 if DelphiRandom( n) = 0 then1592 Inc(N); 1593 if DelphiRandom(N) = 0 then 1594 1594 StartLoc2[p1] := Loc1; 1595 1595 end; … … 1598 1598 end; 1599 1599 1600 procedure PredefinedStartPositions(Human: integer);1600 procedure PredefinedStartPositions(Human: Integer); 1601 1601 // use predefined nation start positions 1602 1602 var 1603 i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;1604 StartLoc0: array [0 .. lxmax * lymax - 1] of integer;1605 ishuman: boolean;1603 I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer; 1604 StartLoc0: array [0 .. lxmax * lymax - 1] of Integer; 1605 ishuman: Boolean; 1606 1606 begin 1607 1607 nAlive := 0; 1608 1608 for p1 := 0 to nPl - 1 do 1609 1609 if 1 shl p1 and GAlive <> 0 then 1610 inc(nAlive);1610 Inc(nAlive); 1611 1611 if nAlive = 0 then 1612 exit;1612 Exit; 1613 1613 1614 1614 for I := 0 to Length(StartLoc0) - 1 do … … 1623 1623 StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0]; 1624 1624 StartLoc0[nPrefStartLoc0] := Loc1; 1625 inc(nPrefStartLoc0);1626 inc(nStartLoc0);1625 Inc(nPrefStartLoc0); 1626 Inc(nStartLoc0); 1627 1627 RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos; 1628 1628 end … … 1630 1630 begin 1631 1631 StartLoc0[nStartLoc0] := Loc1; 1632 inc(nStartLoc0);1632 Inc(nStartLoc0); 1633 1633 RealMap[Loc1] := RealMap[Loc1] and not fStartPos; 1634 1634 end; 1635 assert(nStartLoc0 >= nAlive);1635 Assert(nStartLoc0 >= nAlive); 1636 1636 1637 1637 StartLoc[0] := 0; 1638 for ishuman := true downto false do1638 for ishuman := True downto False do 1639 1639 for p1 := 0 to nPl - 1 do 1640 1640 if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman) 1641 1641 then 1642 1642 begin 1643 dec(nStartLoc0);1643 Dec(nStartLoc0); 1644 1644 imax := nStartLoc0; 1645 1645 if nPrefStartLoc0 > 0 then 1646 1646 begin 1647 dec(nPrefStartLoc0);1647 Dec(nPrefStartLoc0); 1648 1648 imax := nPrefStartLoc0; 1649 1649 end; 1650 i:= DelphiRandom(imax + 1);1651 StartLoc[p1] := StartLoc0[ i];1652 StartLoc2[p1] := StartLoc0[ i];1653 StartLoc0[ i] := StartLoc0[imax];1650 I := DelphiRandom(imax + 1); 1651 StartLoc[p1] := StartLoc0[I]; 1652 StartLoc2[p1] := StartLoc0[I]; 1653 StartLoc0[I] := StartLoc0[imax]; 1654 1654 StartLoc0[imax] := StartLoc0[nStartLoc0]; 1655 1655 end; … … 1659 1659 procedure InitGame; 1660 1660 var 1661 i, p, p1, uix, Loc1: integer;1661 I, P, p1, uix, Loc1: Integer; 1662 1662 begin 1663 1663 {$IFDEF FastContact} … … 1683 1683 GTestFlags := 0; 1684 1684 GInitialized := GAlive or GWatching; 1685 for p:= 0 to nPl - 1 do1686 if 1 shl pand GInitialized <> 0 then1687 with RW[ p] do1688 begin 1689 Researched[ p] := 0;1690 Discovered[ p] := 0;1691 TerritoryCount[ p] := 0;1692 nTech[ p] := 0;1693 if Difficulty[ p] = 0 then1694 ResourceMask[ p] := $FFFFFFFF1685 for P := 0 to nPl - 1 do 1686 if 1 shl P and GInitialized <> 0 then 1687 with RW[P] do 1688 begin 1689 Researched[P] := 0; 1690 Discovered[P] := 0; 1691 TerritoryCount[P] := 0; 1692 nTech[P] := 0; 1693 if Difficulty[P] = 0 then 1694 ResourceMask[P] := $FFFFFFFF 1695 1695 else 1696 ResourceMask[ p] := $FFFFFFFF and not(fSpecial2 or fModern);1697 GrWallContinent[ p] := -1;1696 ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern); 1697 GrWallContinent[P] := -1; 1698 1698 1699 1699 GetMem(Map, 4 * MapSize); … … 1713 1713 if 1 shl p1 and GInitialized <> 0 then 1714 1714 begin 1715 FillChar(RWemix[ p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }1716 FillChar(Destroyed[ p, p1], SizeOf(Destroyed[p, p1]), 0);1715 FillChar(RWemix[P, p1], SizeOf(RWemix[P, p1]), 255); { -1 } 1716 FillChar(Destroyed[P, p1], SizeOf(Destroyed[P, p1]), 0); 1717 1717 end; 1718 1718 Attitude[p1] := atNeutral; … … 1722 1722 Tribute[p1] := 0; 1723 1723 TributePaid[p1] := 0; 1724 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then1724 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 1725 1725 begin // initialize enemy report 1726 1726 GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 * … … 1732 1732 EnemyReport[p1].Attitude := atNeutral; 1733 1733 EnemyReport[p1].Government := gDespotism; 1734 if 1 shl pand GAlive = 0 then1734 if 1 shl P and GAlive = 0 then 1735 1735 Treaty[p1] := trNone // supervisor 1736 1736 end … … 1754 1754 1755 1755 // create initial models and units 1756 for p:= 0 to nPl - 1 do1757 if (1 shl pand GAlive <> 0) then1758 with RW[ p] do1756 for P := 0 to nPl - 1 do 1757 if (1 shl P and GAlive <> 0) then 1758 with RW[P] do 1759 1759 begin 1760 1760 nModel := 0; 1761 for i:= 0 to nSpecialModel - 1 do1762 if SpecialModelPreq[ i] = preNone then1761 for I := 0 to nSpecialModel - 1 do 1762 if SpecialModelPreq[I] = preNone then 1763 1763 begin 1764 Model[nModel] := SpecialModel[ i];1764 Model[nModel] := SpecialModel[I]; 1765 1765 Model[nModel].Status := 0; 1766 1766 Model[nModel].IntroTurn := 0; 1767 1767 Model[nModel].Built := 0; 1768 1768 Model[nModel].Lost := 0; 1769 Model[nModel].ID := pshl 12 + nModel;1769 Model[nModel].ID := P shl 12 + nModel; 1770 1770 SetModelFlags(Model[nModel]); 1771 inc(nModel);1771 Inc(nModel); 1772 1772 end; 1773 1773 nUn := 0; 1774 UnBuilt[ p] := 0;1774 UnBuilt[P] := 0; 1775 1775 for uix := 0 to nStartUn - 1 do 1776 1776 begin 1777 CreateUnit( p, StartUn[uix]);1778 dec(Model[StartUn[uix]].Built);1779 Un[uix].Loc := StartLoc2[ p];1780 PlaceUnit( p, uix);1781 end; 1782 FoundCity( p, StartLoc[p]); // capital1783 Founded[ p] := 1;1777 CreateUnit(P, StartUn[uix]); 1778 Dec(Model[StartUn[uix]].Built); 1779 Un[uix].Loc := StartLoc2[P]; 1780 PlaceUnit(P, uix); 1781 end; 1782 FoundCity(P, StartLoc[P]); // capital 1783 Founded[P] := 1; 1784 1784 with City[0] do 1785 1785 begin 1786 ID := pshl 12;1786 ID := P shl 12; 1787 1787 Flags := chFounded; 1788 1788 end; … … 1798 1798 CalculatePrimitive; 1799 1799 CreateElevation; 1800 CreateMap( false);1800 CreateMap(False); 1801 1801 StartPositions; 1802 1802 InitGame; 1803 1803 end; 1804 1804 1805 procedure InitMapGame(Human: integer);1805 procedure InitMapGame(Human: Integer); 1806 1806 begin 1807 1807 DelphiRandSeed := RND; … … 1813 1813 procedure ReleaseGame; 1814 1814 var 1815 p1, p2: integer;1815 p1, p2: Integer; 1816 1816 begin 1817 1817 for p1 := 0 to nPl - 1 do … … 1835 1835 procedure InitMapEditor; 1836 1836 var 1837 p1: integer;1837 p1: Integer; 1838 1838 begin 1839 1839 CalculatePrimitive; … … 1872 1872 end; 1873 1873 1874 procedure EditTile(Loc, NewTile: integer);1875 var 1876 Loc1, V21: integer;1874 procedure EditTile(Loc, NewTile: Integer); 1875 var 1876 Loc1, V21: Integer; 1877 1877 Radius: TVicinity21Loc; 1878 1878 begin … … 1932 1932 ____________________________________________________________________ 1933 1933 } 1934 function GetTileInfo( p, cix, Loc: integer; var Info: TTileInfo): integer;1934 function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer; 1935 1935 // cix>=0 - known city index of player p -- only core internal! 1936 1936 // cix=-1 - search city, player unknown, only if permission for p 1937 1937 // cix=-2 - don't search city, don't calculate city benefits, just government of player p 1938 1938 var 1939 p0, Tile, special: integer;1939 p0, Tile, special: Integer; 1940 1940 begin 1941 1941 with Info do 1942 1942 begin 1943 p0 := p;1943 p0 := P; 1944 1944 if cix >= 0 then 1945 1945 Tile := RealMap[Loc] 1946 1946 else 1947 1947 begin 1948 Tile := RW[ p].Map[Loc];1948 Tile := RW[P].Map[Loc]; 1949 1949 if Tile and fTerrain = fUNKNOWN then 1950 1950 begin 1951 result := eNoPreq;1952 exit;1951 Result := eNoPreq; 1952 Exit; 1953 1953 end; 1954 1954 end; … … 1956 1956 if (cix = -1) and (UsedByCity[Loc] >= 0) then 1957 1957 begin // search exploiting player and city 1958 SearchCity(UsedByCity[Loc], p, cix);1959 if not(( p= p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and1958 SearchCity(UsedByCity[Loc], P, cix); 1959 if not((P = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and 1960 1960 3 = lObserveSuper)) then 1961 1961 cix := -1 … … 1963 1963 if cix = -1 then 1964 1964 begin 1965 result := eInvalid;1966 exit;1965 Result := eInvalid; 1966 Exit; 1967 1967 end; // no city found here 1968 1968 1969 special := Tile and fSpecial and ResourceMask[ p] shr 5;1969 special := Tile and fSpecial and ResourceMask[P] shr 5; 1970 1970 with Terrain[Tile and fTerrain] do 1971 1971 begin … … 1974 1974 Trade := TradeRes[special]; 1975 1975 if (special > 0) and (Tile and fTerrain <> fGrass) and 1976 (RW[ p].NatBuilt[imSpacePort] > 0) then1976 (RW[P].NatBuilt[imSpacePort] > 0) then 1977 1977 begin // GeoSat effect 1978 1978 Food := 2 * Food - FoodRes[0]; … … 1983 1983 if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or 1984 1984 (Tile and fCity <> 0) then 1985 inc(Food, IrrEff); { irrigation effect }1985 Inc(Food, IrrEff); { irrigation effect } 1986 1986 if Tile and fTerImp = tiMine then 1987 inc(Prod, MineEff); { mining effect }1988 if (Tile and fRiver <> 0) and (RW[ p].Tech[adMapMaking] >= tsApplicable)1987 Inc(Prod, MineEff); { mining effect } 1988 if (Tile and fRiver <> 0) and (RW[P].Tech[adMapMaking] >= tsApplicable) 1989 1989 then 1990 inc(Trade); { river effect }1990 Inc(Trade); { river effect } 1991 1991 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 1992 (RW[ p].Tech[adWheel] >= tsApplicable) then1993 inc(Trade); { road effect }1992 (RW[P].Tech[adWheel] >= tsApplicable) then 1993 Inc(Trade); { road effect } 1994 1994 if (Tile and (fRR or fCity) <> 0) and 1995 (RW[ p].Tech[adRailroad] >= tsApplicable) then1996 inc(Prod, Prod shr 1); { railroad effect }1995 (RW[P].Tech[adRailroad] >= tsApplicable) then 1996 Inc(Prod, Prod shr 1); { railroad effect } 1997 1997 1998 1998 ExplCity := -1; 1999 if (cix >= 0) and ( p= p0) then1999 if (cix >= 0) and (P = p0) then 2000 2000 ExplCity := cix; 2001 2001 if cix >= 0 then … … 2003 2003 begin 2004 2004 if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and 2005 (RW[ p].City[cix].Built[imSupermarket] > 0) then2006 inc(Food, Food shr 1); { farmland effect }2005 (RW[P].City[cix].Built[imSupermarket] > 0) then 2006 Inc(Food, Food shr 1); { farmland effect } 2007 2007 if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and 2008 (RW[ p].City[cix].Built[imHighways] > 0) then2009 inc(Trade, 1); { superhighway effect }2008 (RW[P].City[cix].Built[imHighways] > 0) then 2009 Inc(Trade, 1); { superhighway effect } 2010 2010 end 2011 2011 else 2012 2012 begin 2013 if RW[ p].City[cix].Built[imHarbor] > 0 then2014 inc(Food); { harbour effect }2015 if RW[ p].City[cix].Built[imPlatform] > 0 then2016 inc(Prod); { oil platform effect }2017 if GWonder[woLighthouse].EffectiveOwner = pthen2018 inc(Prod);2013 if RW[P].City[cix].Built[imHarbor] > 0 then 2014 Inc(Food); { harbour effect } 2015 if RW[P].City[cix].Built[imPlatform] > 0 then 2016 Inc(Prod); { oil platform effect } 2017 if GWonder[woLighthouse].EffectiveOwner = P then 2018 Inc(Prod); 2019 2019 end; 2020 2020 end; 2021 2021 2022 2022 { good government influence } 2023 if (RW[ p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)2023 if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0) 2024 2024 then 2025 inc(Trade);2026 if (RW[ p].Government = gCommunism) and (Prod > 1) then2027 inc(Prod);2028 2029 if RW[ p].Government in [gAnarchy, gDespotism] then2025 Inc(Trade); 2026 if (RW[P].Government = gCommunism) and (Prod > 1) then 2027 Inc(Prod); 2028 2029 if RW[P].Government in [gAnarchy, gDespotism] then 2030 2030 begin { bad government influence } 2031 2031 if Food > 3 then … … 2039 2039 if Tile and (fTerrain or fPoll) > fPoll then 2040 2040 begin { pollution - decrease ressources } 2041 dec(Food, Food shr 1);2042 dec(Prod, Prod shr 1);2043 dec(Trade, Trade shr 1);2041 Dec(Food, Food shr 1); 2042 Dec(Prod, Prod shr 1); 2043 Dec(Trade, Trade shr 1); 2044 2044 end; 2045 2045 2046 2046 if Tile and fCity <> 0 then 2047 2047 Trade := 0 2048 else if (cix >= 0) and (RW[ p].City[cix].Built[imCourt] + RW[p].City[cix]2048 else if (cix >= 0) and (RW[P].City[cix].Built[imCourt] + RW[P].City[cix] 2049 2049 .Built[imPalace] = 0) then 2050 if RW[ p].City[cix].Built[imTownHall] = 0 then2050 if RW[P].City[cix].Built[imTownHall] = 0 then 2051 2051 Trade := 0 2052 2052 else if Trade > 3 then 2053 2053 Trade := 3; 2054 2054 end; 2055 result := eOK;2056 end; 2057 2058 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);2055 Result := eOK; 2056 end; 2057 2058 procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer); 2059 2059 { find strongest defender at Loc } 2060 2060 var 2061 2061 Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost, 2062 Domain: integer;2062 Domain: Integer; 2063 2063 PUn: ^TUn; 2064 2064 PModel: ^TModel; … … 2078 2078 if PUn.Loc = Loc then 2079 2079 begin 2080 inc(Cnt);2080 Inc(Cnt); 2081 2081 if PUn.Master < 0 then 2082 2082 begin … … 2085 2085 TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense; 2086 2086 if RealMap[Loc] and fTerImp = tiFort then 2087 inc(TestBonus, 4);2087 Inc(TestBonus, 4); 2088 2088 if PUn.Flags and unFortified <> 0 then 2089 inc(TestBonus, 2);2089 Inc(TestBonus, 2); 2090 2090 if (PModel.Kind = mkSpecial_TownGuard) and 2091 2091 (RealMap[Loc] and fCity <> 0) then 2092 inc(TestBonus, 4);2092 Inc(TestBonus, 4); 2093 2093 end 2094 2094 else 2095 2095 TestBonus := 4; 2096 inc(TestBonus, PUn.exp div ExpCost);2096 Inc(TestBonus, PUn.exp div ExpCost); 2097 2097 TestStrength := PModel.Defense * TestBonus * PUn.Health; 2098 2098 if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or … … 2104 2104 if PModel.Cap[mcStealth] > 0 then 2105 2105 else if PModel.Cap[mcSub] > 0 then 2106 inc(TestDet, 1 shl 28)2106 Inc(TestDet, 1 shl 28) 2107 2107 else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and 2108 2108 not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then 2109 inc(TestDet, 4 shl 28) // fanatic ground units always defend2109 Inc(TestDet, 4 shl 28) // fanatic ground units always defend 2110 2110 else if PModel.Flags and mdZOC <> 0 then 2111 inc(TestDet, 3 shl 28)2111 Inc(TestDet, 3 shl 28) 2112 2112 else 2113 inc(TestDet, 2 shl 28);2113 Inc(TestDet, 2 shl 28); 2114 2114 TestCost := RW[Defender].Model[PUn.mix].Cost; 2115 2115 if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then … … 2126 2126 end; 2127 2127 2128 function UnitSpeed( p, mix, Health: integer): integer;2129 begin 2130 with RW[ p].Model[mix] do2131 begin 2132 result := Speed;2128 function UnitSpeed(P, mix, Health: Integer): Integer; 2129 begin 2130 with RW[P].Model[mix] do 2131 begin 2132 Result := Speed; 2133 2133 if Domain = dSea then 2134 2134 begin 2135 if GWonder[woMagellan].EffectiveOwner = pthen2136 inc(result, 200);2135 if GWonder[woMagellan].EffectiveOwner = P then 2136 Inc(Result, 200); 2137 2137 if Health < 100 then 2138 result := ((result - 250) * Health div 5000) * 50 + 250;2139 end; 2140 end; 2141 end; 2142 2143 procedure GetUnitReport( p, uix: integer; var UnitReport: TUnitReport);2144 var 2145 TerrOwner: integer;2138 Result := ((Result - 250) * Health div 5000) * 50 + 250; 2139 end; 2140 end; 2141 end; 2142 2143 procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport); 2144 var 2145 TerrOwner: Integer; 2146 2146 PModel: ^TModel; 2147 2147 begin … … 2149 2149 UnitReport.ProdSupport := 0; 2150 2150 UnitReport.ReportFlags := 0; 2151 if RW[ p].Government <> gAnarchy then2152 with RW[ p].Un[uix] do2153 begin 2154 PModel := @RW[ p].Model[mix];2151 if RW[P].Government <> gAnarchy then 2152 with RW[P].Un[uix] do 2153 begin 2154 PModel := @RW[P].Model[mix]; 2155 2155 if (PModel.Kind = mkSettler) 2156 2156 { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then 2157 UnitReport.FoodSupport := SettlerFood[RW[ p].Government]2157 UnitReport.FoodSupport := SettlerFood[RW[P].Government] 2158 2158 else if Flags and unConscripts <> 0 then 2159 2159 UnitReport.FoodSupport := 1; 2160 2160 2161 if RW[ p].Government <> gFundamentalism then2161 if RW[P].Government <> gFundamentalism then 2162 2162 begin 2163 2163 if GTestFlags and tfImmImprove = 0 then … … 2174 2174 begin 2175 2175 TerrOwner := RealMap[Loc] shr 27; 2176 case RW[ p].Government of2176 case RW[P].Government of 2177 2177 gRepublic, gFuture: 2178 if (TerrOwner <> p) and (TerrOwner < nPl) and2179 (RW[ p].Treaty[TerrOwner] < trAlliance) then2178 if (TerrOwner <> P) and (TerrOwner < nPl) and 2179 (RW[P].Treaty[TerrOwner] < trAlliance) then 2180 2180 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2181 2181 gDemocracy: 2182 if (TerrOwner >= nPl) or (TerrOwner <> p) and2183 (RW[ p].Treaty[TerrOwner] < trAlliance) then2182 if (TerrOwner >= nPl) or (TerrOwner <> P) and 2183 (RW[P].Treaty[TerrOwner] < trAlliance) then 2184 2184 UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed; 2185 2185 end; … … 2189 2189 end; 2190 2190 2191 procedure SearchCity(Loc: integer; var p, cix: integer);2191 procedure SearchCity(Loc: Integer; var P, cix: Integer); 2192 2192 // set p to supposed owner before call 2193 2193 var 2194 i: integer;2194 I: Integer; 2195 2195 begin 2196 2196 if RealMap[Loc] < nPl shl 27 then 2197 p:= RealMap[Loc] shr 27;2198 for i:= 0 to nPl - 1 do2199 begin 2200 if 1 shl pand GAlive <> 0 then2201 with RW[ p] do2197 P := RealMap[Loc] shr 27; 2198 for I := 0 to nPl - 1 do 2199 begin 2200 if 1 shl P and GAlive <> 0 then 2201 with RW[P] do 2202 2202 begin 2203 2203 cix := nCity - 1; 2204 2204 while (cix >= 0) and (City[cix].Loc <> Loc) do 2205 dec(cix);2205 Dec(cix); 2206 2206 if cix >= 0 then 2207 exit;2208 end; 2209 assert(i< nPl - 1);2210 p := (p+ 1) mod nPl;2211 end; 2212 end; 2213 2214 procedure MakeCityInfo( p, cix: integer; var ci: TCityInfo);2215 begin 2216 assert((p >= 0) and (p< nPl));2217 assert((cix >= 0) and (cix < RW[p].nCity));2218 with RW[ p].City[cix] do2207 Exit; 2208 end; 2209 Assert(I < nPl - 1); 2210 P := (P + 1) mod nPl; 2211 end; 2212 end; 2213 2214 procedure MakeCityInfo(P, cix: Integer; var ci: TCityInfo); 2215 begin 2216 Assert((P >= 0) and (P < nPl)); 2217 Assert((cix >= 0) and (cix < RW[P].nCity)); 2218 with RW[P].City[cix] do 2219 2219 begin 2220 2220 ci.Loc := Loc; 2221 2221 ci.ID := ID; 2222 ci.Owner := p;2222 ci.Owner := P; 2223 2223 ci.Size := Size; 2224 2224 ci.Flags := 0; 2225 2225 if Built[imPalace] > 0 then 2226 inc(ci.Flags, ciCapital);2227 if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[ p]) then2228 inc(ci.Flags, ciWalled);2226 Inc(ci.Flags, ciCapital); 2227 if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[P]) then 2228 Inc(ci.Flags, ciWalled); 2229 2229 if Built[imCoastalFort] > 0 then 2230 inc(ci.Flags, ciCoastalFort);2230 Inc(ci.Flags, ciCoastalFort); 2231 2231 if Built[imMissileBat] > 0 then 2232 inc(ci.Flags, ciMissileBat);2232 Inc(ci.Flags, ciMissileBat); 2233 2233 if Built[imBunker] > 0 then 2234 inc(ci.Flags, ciBunker);2234 Inc(ci.Flags, ciBunker); 2235 2235 if Built[imSpacePort] > 0 then 2236 inc(ci.Flags, ciSpacePort);2237 end; 2238 end; 2239 2240 procedure TellAboutModel( p, taOwner, tamix: integer);2241 var 2242 i: integer;2243 begin 2244 if ( p= taOwner) or (Mode < moPlaying) then2245 exit;2246 i:= 0;2247 while ( i < RW[p].nEnemyModel) and ((RW[p].EnemyModel[i].Owner <> taOwner) or2248 (RW[ p].EnemyModel[i].mix <> tamix)) do2249 inc(i);2250 if i = RW[p].nEnemyModel then2251 IntServer(sIntTellAboutModel + pshl 4, taOwner, tamix, nil^);2252 end; 2253 2254 function emixSafe( p, taOwner, tamix: integer): integer;2255 begin 2256 result := RWemix[p, taOwner, tamix];2257 if result < 0 then2236 Inc(ci.Flags, ciSpacePort); 2237 end; 2238 end; 2239 2240 procedure TellAboutModel(P, taOwner, tamix: Integer); 2241 var 2242 I: Integer; 2243 begin 2244 if (P = taOwner) or (Mode < moPlaying) then 2245 Exit; 2246 I := 0; 2247 while (I < RW[P].nEnemyModel) and ((RW[P].EnemyModel[I].Owner <> taOwner) or 2248 (RW[P].EnemyModel[I].mix <> tamix)) do 2249 Inc(I); 2250 if I = RW[P].nEnemyModel then 2251 IntServer(sIntTellAboutModel + P shl 4, taOwner, tamix, nil^); 2252 end; 2253 2254 function emixSafe(P, taOwner, tamix: Integer): Integer; 2255 begin 2256 Result := RWemix[P, taOwner, tamix]; 2257 if Result < 0 then 2258 2258 begin // sIntTellAboutModel comes too late 2259 assert(Mode = moMovie);2260 result := $FFFF;2261 end; 2262 end; 2263 2264 procedure IntroduceEnemy(p1, p2: integer);2259 Assert(Mode = moMovie); 2260 Result := $FFFF; 2261 end; 2262 end; 2263 2264 procedure IntroduceEnemy(p1, p2: Integer); 2265 2265 begin 2266 2266 RW[p1].Treaty[p2] := trNone; … … 2268 2268 end; 2269 2269 2270 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;2271 euix: integer = -2): boolean;2270 function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean; 2271 euix: Integer = -2): Boolean; 2272 2272 // euix = -2: full discover 2273 2273 // euix = -1: unit and city only, append units in EnemyUn 2274 2274 // euix >= 0: unit and city only, replace EnemyUn[euix] 2275 2275 2276 procedure SetContact(p1, p2: integer);2276 procedure SetContact(p1, p2: Integer); 2277 2277 begin 2278 2278 if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then 2279 exit;2279 Exit; 2280 2280 IntServer(sIntTellAboutNation, p1, p2, nil^); 2281 2281 // NewContact[p1,p2]:=true … … 2283 2283 2284 2284 var 2285 i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,2286 cixFoundCity, MinLevel, Loc1, V8: integer;2285 I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity, 2286 cixFoundCity, MinLevel, Loc1, V8: Integer; 2287 2287 Tile, AddFlags: Cardinal; 2288 2288 Adjacent: TVicinity8Loc; … … 2290 2290 mox: ^TModel; 2291 2291 begin 2292 result := false;2292 Result := False; 2293 2293 with RW[pTell] do 2294 2294 begin … … 2306 2306 AddFlags := AddFlags or fGrWall; 2307 2307 if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and 2308 (pTell = p)) then2308 (pTell = P)) then 2309 2309 begin // set fPeace flag? 2310 2310 TerrOwner := Tile shr 27; … … 2333 2333 unx := @RW[Occupant[Loc]].Un[uix]; 2334 2334 mox := @RW[Occupant[Loc]].Model[unx.mix]; 2335 assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));2335 Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0)); 2336 2336 if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and 2337 2337 (Tile and fTerImp <> tiBase) then … … 2349 2349 begin 2350 2350 uix := nEnemyUn; 2351 inc(nEnemyUn);2352 assert(nEnemyUn < neumax);2351 Inc(nEnemyUn); 2352 Assert(nEnemyUn < neumax); 2353 2353 end; 2354 2354 MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]); 2355 2355 if Cnt > 1 then 2356 2356 EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti; 2357 if (mox.Flags and mdZOC <> 0) and (pTell = p) and2357 if (mox.Flags and mdZOC <> 0) and (pTell = P) and 2358 2358 (Treaty[Occupant[Loc]] < trAlliance) then 2359 2359 begin // set fInEnemyZoC flags of surrounding tiles … … 2374 2374 end; 2375 2375 // Level:=lObserveSuper; // don't discover unit twice 2376 if (pTell = p) and2376 if (pTell = P) and 2377 2377 ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then 2378 result := true;2378 Result := True; 2379 2379 end 2380 2380 else … … 2398 2398 while (cixFoundCity >= 0) and 2399 2399 (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do 2400 dec(cixFoundCity);2401 assert(cixFoundCity >= 0);2402 i:= 0;2403 while ( i < nEnemyCity) and (EnemyCity[i].Loc <> Loc) do2404 inc(i);2405 if i= nEnemyCity then2400 Dec(cixFoundCity); 2401 Assert(cixFoundCity >= 0); 2402 I := 0; 2403 while (I < nEnemyCity) and (EnemyCity[I].Loc <> Loc) do 2404 Inc(I); 2405 if I = nEnemyCity then 2406 2406 begin 2407 inc(nEnemyCity);2408 assert(nEnemyCity < necmax);2409 EnemyCity[ i].Status := 0;2410 EnemyCity[ i].SavedStatus := 0;2411 if pTell = pthen2412 result := true;2407 Inc(nEnemyCity); 2408 Assert(nEnemyCity < necmax); 2409 EnemyCity[I].Status := 0; 2410 EnemyCity[I].SavedStatus := 0; 2411 if pTell = P then 2412 Result := True; 2413 2413 end; 2414 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[ i]);2414 MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]); 2415 2415 end; 2416 2416 end … … 2421 2421 2422 2422 if Map[Loc] and fTerrain = fUNKNOWN then 2423 inc(Discovered[pTell]);2423 Inc(Discovered[pTell]); 2424 2424 if euix >= -1 then 2425 2425 Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or … … 2440 2440 end; 2441 2441 2442 function Discover9(Loc, p, Level: integer;2443 TellAllied, EnableContact: boolean): boolean;2444 var 2445 V9, Loc1, pTell, OldLevel: integer;2442 function Discover9(Loc, P, Level: Integer; 2443 TellAllied, EnableContact: Boolean): Boolean; 2444 var 2445 V9, Loc1, pTell, OldLevel: Integer; 2446 2446 Radius: TVicinity8Loc; 2447 2447 begin 2448 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2449 result := false;2448 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2449 Result := False; 2450 2450 V8_to_Loc(Loc, Radius); 2451 2451 for V9 := 0 to 8 do … … 2459 2459 begin 2460 2460 for pTell := 0 to nPl - 1 do 2461 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2462 (RW[ p].Treaty[pTell] = trAlliance) then2461 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2462 (RW[P].Treaty[pTell] = trAlliance) then 2463 2463 begin 2464 2464 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2465 2465 if Level > OldLevel then 2466 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2467 or result;2466 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2467 or Result; 2468 2468 end; 2469 2469 end 2470 2470 else 2471 2471 begin 2472 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2472 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2473 2473 if Level > OldLevel then 2474 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2475 end; 2476 end; 2477 end; 2478 2479 function Discover21(Loc, p, AdjacentLevel: integer;2480 TellAllied, EnableContact: boolean): boolean;2481 var 2482 V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: integer;2474 Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result; 2475 end; 2476 end; 2477 end; 2478 2479 function Discover21(Loc, P, AdjacentLevel: Integer; 2480 TellAllied, EnableContact: Boolean): Boolean; 2481 var 2482 V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: Integer; 2483 2483 Radius: TVicinity21Loc; 2484 2484 begin 2485 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2486 result := false;2485 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2486 Result := False; 2487 2487 AdjacentFlags := $00267620 shr 1; 2488 2488 V21_to_Loc(Loc, Radius); … … 2499 2499 begin 2500 2500 for pTell := 0 to nPl - 1 do 2501 if (pTell = p) or (1 shl pTell and GAlive <> 0) and2502 (RW[ p].Treaty[pTell] = trAlliance) then2501 if (pTell = P) or (1 shl pTell and GAlive <> 0) and 2502 (RW[P].Treaty[pTell] = trAlliance) then 2503 2503 begin 2504 2504 OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3; 2505 2505 if Level > OldLevel then 2506 result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)2507 or result;2506 Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact) 2507 or Result; 2508 2508 end; 2509 2509 end 2510 2510 else 2511 2511 begin 2512 OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;2512 OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3; 2513 2513 if Level > OldLevel then 2514 result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;2514 Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result; 2515 2515 end; 2516 2516 end; … … 2519 2519 end; 2520 2520 2521 procedure DiscoverAll( p, Level: integer);2521 procedure DiscoverAll(P, Level: Integer); 2522 2522 { player p discovers complete playground (for supervisor) } 2523 2523 var 2524 Loc, OldLevel: integer;2525 begin 2526 assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));2524 Loc, OldLevel: Integer; 2525 begin 2526 Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0)); 2527 2527 for Loc := 0 to MapSize - 1 do 2528 2528 begin 2529 OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;2529 OldLevel := ObserveLevel[Loc] shr (2 * P) and 3; 2530 2530 if Level > OldLevel then 2531 DiscoverTile(Loc, p, p, Level, false);2532 end; 2533 end; 2534 2535 procedure DiscoverViewAreas( p: integer);2536 var 2537 pTell, uix, cix, ecix, Loc, RealOwner: integer;2531 DiscoverTile(Loc, P, P, Level, False); 2532 end; 2533 end; 2534 2535 procedure DiscoverViewAreas(P: Integer); 2536 var 2537 pTell, uix, cix, ecix, Loc, RealOwner: Integer; 2538 2538 PModel: ^TModel; 2539 2539 begin // discover unit and city view areas 2540 2540 for pTell := 0 to nPl - 1 do 2541 if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then2541 if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then 2542 2542 begin 2543 2543 for uix := 0 to RW[pTell].nUn - 1 do … … 2547 2547 PModel := @RW[pTell].Model[mix]; 2548 2548 if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then 2549 Discover21(Loc, p, lObserveSuper, false, true)2549 Discover21(Loc, P, lObserveSuper, False, True) 2550 2550 else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or 2551 2551 (PModel.Domain = dAir) then 2552 Discover21(Loc, p, lObserveAll, false, false)2552 Discover21(Loc, P, lObserveAll, False, False) 2553 2553 else if (RealMap[Loc] and fTerrain = fMountains) or 2554 2554 (RealMap[Loc] and fTerImp = tiFort) or 2555 2555 (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0) 2556 2556 then 2557 Discover21(Loc, p, lObserveUnhidden, false,2557 Discover21(Loc, P, lObserveUnhidden, False, 2558 2558 PModel.Domain = dGround) 2559 2559 else 2560 Discover9(Loc, p, lObserveUnhidden, false,2560 Discover9(Loc, P, lObserveUnhidden, False, 2561 2561 PModel.Domain = dGround); 2562 2562 end; 2563 2563 for cix := 0 to RW[pTell].nCity - 1 do 2564 2564 if RW[pTell].City[cix].Loc >= 0 then 2565 Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);2565 Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True); 2566 2566 for ecix := 0 to RW[pTell].nEnemyCity - 1 do 2567 2567 begin // players know territory, so no use in hiding city owner … … 2582 2582 end; 2583 2583 2584 function GetUnitStack( p, Loc: integer): integer;2585 var 2586 uix: integer;2584 function GetUnitStack(P, Loc: Integer): Integer; 2585 var 2586 uix: Integer; 2587 2587 unx: ^TUn; 2588 2588 begin 2589 result := 0;2589 Result := 0; 2590 2590 if Occupant[Loc] < 0 then 2591 exit;2591 Exit; 2592 2592 for uix := 0 to RW[Occupant[Loc]].nUn - 1 do 2593 2593 begin … … 2595 2595 if unx.Loc = Loc then 2596 2596 begin 2597 MakeUnitInfo(Occupant[Loc], unx^, RW[ p].EnemyUn[RW[p].nEnemyUn + result]);2598 TellAboutModel( p, Occupant[Loc], unx.mix);2599 RW[ p].EnemyUn[RW[p].nEnemyUn + result].emix :=2600 RWemix[ p, Occupant[Loc], unx.mix];2601 inc(result);2602 end; 2603 end; 2604 end; 2605 2606 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);2597 MakeUnitInfo(Occupant[Loc], unx^, RW[P].EnemyUn[RW[P].nEnemyUn + Result]); 2598 TellAboutModel(P, Occupant[Loc], unx.mix); 2599 RW[P].EnemyUn[RW[P].nEnemyUn + Result].emix := 2600 RWemix[P, Occupant[Loc], unx.mix]; 2601 Inc(Result); 2602 end; 2603 end; 2604 end; 2605 2606 procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False); 2607 2607 // update maps and enemy units of all players after unit change 2608 2608 var 2609 p, euix, OldLevel: integer;2609 P, euix, OldLevel: Integer; 2610 2610 AddFlags, ClearFlags: Cardinal; 2611 2611 begin 2612 2612 if (Mode = moLoading_Fast) and not CityChange then 2613 exit;2614 for p:= 0 to nPl - 1 do2615 if 1 shl pand (GAlive or GWatching) <> 0 then2616 begin 2617 OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;2613 Exit; 2614 for P := 0 to nPl - 1 do 2615 if 1 shl P and (GAlive or GWatching) <> 0 then 2616 begin 2617 OldLevel := ObserveLevel[Loc] shr (2 * P) and 3; 2618 2618 if OldLevel > lNoObserve then 2619 2619 begin 2620 if RW[ p].Map[Loc] and (fUnit or fOwned) = fUnit then2620 if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then 2621 2621 begin 2622 2622 // replace unit located here in EnemyUn 2623 2623 // do not just set loc:=-1 because total number would be unlimited 2624 euix := RW[ p].nEnemyUn - 1;2624 euix := RW[P].nEnemyUn - 1; 2625 2625 while euix >= 0 do 2626 2626 begin 2627 if RW[ p].EnemyUn[euix].Loc = Loc then2627 if RW[P].EnemyUn[euix].Loc = Loc then 2628 2628 begin 2629 RW[ p].EnemyUn[euix].Loc := -1;2629 RW[P].EnemyUn[euix].Loc := -1; 2630 2630 Break; 2631 2631 end; 2632 dec(euix);2632 Dec(euix); 2633 2633 end; 2634 RW[ p].Map[Loc] := RW[p].Map[Loc] and not fUnit2634 RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit 2635 2635 end 2636 2636 else 2637 2637 begin // look for empty slot in EnemyUn 2638 euix := RW[ p].nEnemyUn - 1;2639 while (euix >= 0) and (RW[ p].EnemyUn[euix].Loc >= 0) do2640 dec(euix);2638 euix := RW[P].nEnemyUn - 1; 2639 while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do 2640 Dec(euix); 2641 2641 end; 2642 2642 if (Occupant[Loc] < 0) and not CityChange then … … 2645 2645 if RealMap[Loc] and fCity = 0 then 2646 2646 ClearFlags := ClearFlags or fOwned; 2647 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;2647 RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags; 2648 2648 end 2649 else if (Occupant[Loc] <> p) or CityChange then2649 else if (Occupant[Loc] <> P) or CityChange then 2650 2650 begin // city or enemy unit update necessary, call DiscoverTile 2651 ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));2652 DiscoverTile(Loc, p, p, OldLevel, false, euix);2651 ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * P)); 2652 DiscoverTile(Loc, P, P, OldLevel, False, euix); 2653 2653 end 2654 2654 else { if (Occupant[Loc]=p) and not CityChange then } … … 2660 2660 else 2661 2661 ClearFlags := ClearFlags or fOwnZoCUnit; 2662 RW[ p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;2663 end; 2664 end; 2665 end; 2666 end; 2667 2668 procedure RecalcV8ZoC( p, Loc: integer);2662 RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags or AddFlags; 2663 end; 2664 end; 2665 end; 2666 end; 2667 2668 procedure RecalcV8ZoC(P, Loc: Integer); 2669 2669 // recalculate fInEnemyZoC flags around single tile 2670 2670 var 2671 V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;2671 V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer; 2672 2672 Tile1: ^Cardinal; 2673 2673 Adjacent, AdjacentAdjacent: TVicinity8Loc; 2674 2674 begin 2675 2675 if Mode = moLoading_Fast then 2676 exit;2677 ObserveMask := 3 shl (2 * p);2676 Exit; 2677 ObserveMask := 3 shl (2 * P); 2678 2678 V8_to_Loc(Loc, Adjacent); 2679 2679 for V8 := 0 to 7 do … … 2682 2682 if (Loc1 >= 0) and (Loc1 < MapSize) then 2683 2683 begin 2684 Tile1 := @RW[ p].Map[Loc1];2684 Tile1 := @RW[P].Map[Loc1]; 2685 2685 Tile1^ := Tile1^ and not fInEnemyZoC; 2686 2686 V8_to_Loc(Loc1, AdjacentAdjacent); … … 2692 2692 begin 2693 2693 p1 := Occupant[Loc2]; 2694 assert(p1 <> nPl);2695 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2694 Assert(p1 <> nPl); 2695 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2696 2696 begin 2697 2697 Tile1^ := Tile1^ or fInEnemyZoC; … … 2704 2704 end; 2705 2705 2706 procedure RecalcMapZoC( p: integer);2706 procedure RecalcMapZoC(P: Integer); 2707 2707 // recalculate fInEnemyZoC flags for the whole map 2708 2708 var 2709 Loc, Loc1, V8, p1, ObserveMask: integer;2709 Loc, Loc1, V8, p1, ObserveMask: Integer; 2710 2710 Adjacent: TVicinity8Loc; 2711 2711 begin 2712 2712 if Mode = moLoading_Fast then 2713 exit;2714 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));2715 ObserveMask := 3 shl (2 * p);2713 Exit; 2714 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC))); 2715 ObserveMask := 3 shl (2 * P); 2716 2716 for Loc := 0 to MapSize - 1 do 2717 2717 if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then 2718 2718 begin 2719 2719 p1 := Occupant[Loc]; 2720 assert(p1 <> nPl);2721 if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then2720 Assert(p1 <> nPl); 2721 if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then 2722 2722 begin // this non-allied enemy ZoC unit is known to this player -- set flags! 2723 2723 V8_to_Loc(Loc, Adjacent); … … 2726 2726 Loc1 := Adjacent[V8]; 2727 2727 if (Loc1 >= 0) and (Loc1 < MapSize) then 2728 RW[ p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC;2729 end; 2730 end; 2731 end; 2732 end; 2733 2734 procedure RecalcPeaceMap( p: integer);2728 RW[P].Map[Loc1] := RW[P].Map[Loc1] or fInEnemyZoC; 2729 end; 2730 end; 2731 end; 2732 end; 2733 2734 procedure RecalcPeaceMap(P: Integer); 2735 2735 // recalculate fPeace flags for the whole map 2736 2736 var 2737 Loc, p1: integer;2738 PeacePlayer: array [-1 .. nPl - 1] of boolean;2737 Loc, p1: Integer; 2738 PeacePlayer: array [-1 .. nPl - 1] of Boolean; 2739 2739 begin 2740 2740 if Mode <> moPlaying then 2741 exit;2742 MaskD(RW[ p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));2741 Exit; 2742 MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace))); 2743 2743 for p1 := -1 to nPl - 1 do 2744 PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)2745 and (RW[ p].Treaty[p1] in [trPeace, TrFriendlyContact]);2744 PeacePlayer[p1] := (p1 >= 0) and (p1 <> P) and (1 shl p1 and GAlive <> 0) 2745 and (RW[P].Treaty[p1] in [trPeace, TrFriendlyContact]); 2746 2746 for Loc := 0 to MapSize - 1 do 2747 if PeacePlayer[RW[ p].Territory[Loc]] then2748 RW[ p].Map[Loc] := RW[p].Map[Loc] or fPeace;2747 if PeacePlayer[RW[P].Territory[Loc]] then 2748 RW[P].Map[Loc] := RW[P].Map[Loc] or fPeace; 2749 2749 end; 2750 2750 … … 2756 2756 BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal; 2757 2757 2758 procedure ChangeTerritory(Loc, p: integer);2759 var 2760 p1: integer;2761 begin 2762 Assert( p>= 0); // no player's territory indicated by p=nPl2758 procedure ChangeTerritory(Loc, P: Integer); 2759 var 2760 p1: Integer; 2761 begin 2762 Assert(P >= 0); // no player's territory indicated by p=nPl 2763 2763 Dec(TerritoryCount[RealMap[Loc] shr 27]); 2764 Inc(TerritoryCount[ p]);2765 RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal( p) shl 27;2766 if p= $F then2767 p:= -1;2764 Inc(TerritoryCount[P]); 2765 RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(P) shl 27; 2766 if P = $F then 2767 P := -1; 2768 2768 for p1 := 0 to nPl - 1 do 2769 2769 if 1 shl p1 and (GAlive or GWatching) <> 0 then 2770 2770 if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then 2771 2771 begin 2772 RW[p1].Territory[Loc] := p;2773 if ( p < nPl) and (p <> p1) and (1 shl pand GAlive <> 0) and2774 (RW[p1].Treaty[ p] in [trPeace, TrFriendlyContact]) then2772 RW[p1].Territory[Loc] := P; 2773 if (P < nPl) and (P <> p1) and (1 shl P and GAlive <> 0) and 2774 (RW[p1].Treaty[P] in [trPeace, TrFriendlyContact]) then 2775 2775 RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace 2776 2776 else … … 2779 2779 end; 2780 2780 2781 procedure ExpandTerritory(OriginLoc: integer);2782 var 2783 i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;2781 procedure ExpandTerritory(OriginLoc: Integer); 2782 var 2783 I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer; 2784 2784 begin 2785 2785 if OriginLoc = -1 then 2786 2786 raise Exception.Create('Location error'); 2787 i:= 0;2787 I := 0; 2788 2788 dyMax := 0; 2789 2789 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2790 inc(dyMax);2790 Inc(dyMax); 2791 2791 for dy := -dyMax to dyMax do 2792 2792 begin … … 2794 2794 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2795 2795 CountryRadius do 2796 inc(dxMax, 2);2796 Inc(dxMax, 2); 2797 2797 for dx := -dxMax to dxMax do 2798 2798 if (dy + dx) and 1 = 0 then 2799 2799 begin 2800 NewOwner := BorderChanges[ i div 8] shr (imod 8 * 4) and $F;2800 NewOwner := BorderChanges[I div 8] shr (I mod 8 * 4) and $F; 2801 2801 Loc := dLoc(OriginLoc, dx, dy); 2802 2802 if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then 2803 2803 ChangeTerritory(Loc, NewOwner); 2804 inc(i);2805 end; 2806 end; 2807 end; 2808 2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);2804 Inc(I); 2805 end; 2806 end; 2807 end; 2808 2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer); 2810 2810 // OriginLoc: only changes in CountryRadius around this location possible, 2811 2811 // -1 for complete map, -2 for double-check (no more changes allowed) … … 2813 2813 // player's territory, -1 for full border recalculation 2814 2814 var 2815 i, r, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;2815 I, R, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer; 2816 2816 NewOwner: Cardinal; 2817 2817 Adjacent: TVicinity8Loc; 2818 AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;2818 AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean; 2819 2819 Country, FormerCountry, { to who's country a tile belongs } 2820 2820 Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt; … … 2828 2828 StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0; 2829 2829 2830 for r:= 1 to CountryRadius shr 1 do2831 begin 2832 move(StolenDist, FormerDist, MapSize);2830 for R := 1 to CountryRadius shr 1 do 2831 begin 2832 Move(StolenDist, FormerDist, MapSize); 2833 2833 for Loc := 0 to MapSize - 1 do 2834 2834 if (FormerDist[Loc] <= CountryRadius - 2) … … 2862 2862 end; 2863 2863 2864 for r:= 1 to CountryRadius shr 1 do2865 begin 2866 move(Country, FormerCountry, MapSize);2867 move(Dist, FormerDist, MapSize);2864 for R := 1 to CountryRadius shr 1 do 2865 begin 2866 Move(Country, FormerCountry, MapSize); 2867 Move(Dist, FormerDist, MapSize); 2868 2868 for Loc := 0 to MapSize - 1 do 2869 2869 if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above! … … 2871 2871 (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then 2872 2872 begin 2873 assert(FormerCountry[Loc] >= 0);2873 Assert(FormerCountry[Loc] >= 0); 2874 2874 V8_to_Loc(Loc, Adjacent); 2875 2875 for V8 := 0 to 7 do … … 2886 2886 end; 2887 2887 2888 FillChar(AtPeace, SizeOf(AtPeace), false);2888 FillChar(AtPeace, SizeOf(AtPeace), False); 2889 2889 for p1 := 0 to nPl - 1 do 2890 2890 if 1 shl p1 and GAlive <> 0 then … … 2892 2892 if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and 2893 2893 (RW[p1].Treaty[p2] >= trPeace) then 2894 AtPeace[p1, p2] := true;2894 AtPeace[p1, p2] := True; 2895 2895 2896 2896 if OriginLoc >= 0 then 2897 2897 begin // update area only 2898 i:= 0;2898 I := 0; 2899 2899 FillChar(BorderChanges, SizeOf(BorderChanges), 0); 2900 2900 dyMax := 0; 2901 2901 while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do 2902 inc(dyMax);2902 Inc(dyMax); 2903 2903 for dy := -dyMax to dyMax do 2904 2904 begin … … 2906 2906 while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <= 2907 2907 CountryRadius do 2908 inc(dxMax, 2);2908 Inc(dxMax, 2); 2909 2909 for dx := -dxMax to dxMax do 2910 2910 if (dy + dx) and 1 = 0 then … … 2922 2922 else 2923 2923 ChangeTerritory(Loc, NewOwner); 2924 BorderChanges[ i shr 3] := BorderChanges[ishr 3] or2925 ((NewOwner shl (( iand 7) * 4)) and $ffffffff);2924 BorderChanges[I shr 3] := BorderChanges[I shr 3] or 2925 ((NewOwner shl ((I and 7) * 4)) and $ffffffff); 2926 2926 end; 2927 inc(i);2927 Inc(I); 2928 2928 end; 2929 2929 end; … … 2938 2938 then 2939 2939 begin 2940 assert(OriginLoc <> -2); // test if border saving works2940 Assert(OriginLoc <> -2); // test if border saving works 2941 2941 ChangeTerritory(Loc, NewOwner); 2942 2942 end; … … 2947 2947 end; 2948 2948 2949 procedure LogCheckBorders( p, cix, PlayerLosingCity: integer);2950 begin 2951 CheckBorders(RW[ p].City[cix].Loc, PlayerLosingCity);2952 IntServer(sIntExpandTerritory, p, cix, BorderChanges);2949 procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer); 2950 begin 2951 CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity); 2952 IntServer(sIntExpandTerritory, P, cix, BorderChanges); 2953 2953 end; 2954 2954 … … 2958 2958 } 2959 2959 2960 procedure CreateUnit( p, mix: integer);2961 begin 2962 with RW[ p] do2960 procedure CreateUnit(P, mix: Integer); 2961 begin 2962 with RW[P] do 2963 2963 begin 2964 2964 Un[nUn].mix := mix; 2965 2965 with Un[nUn] do 2966 2966 begin 2967 ID := UnBuilt[ p];2968 inc(UnBuilt[p]);2967 ID := UnBuilt[P]; 2968 Inc(UnBuilt[P]); 2969 2969 Status := 0; 2970 2970 SavedStatus := 0; 2971 inc(Model[mix].Built);2971 Inc(Model[mix].Built); 2972 2972 Home := -1; 2973 2973 Health := 100; … … 2985 2985 Master := -1; 2986 2986 end; 2987 inc(nUn);2987 Inc(nUn); 2988 2988 end 2989 2989 end; 2990 2990 2991 procedure FreeUnit( p, uix: integer);2991 procedure FreeUnit(P, uix: Integer); 2992 2992 // loc or master should be set after call 2993 2993 // implementation is critical for loading performance, change carefully 2994 2994 var 2995 Loc0, uix1: integer;2996 Occ, ZoC: boolean;2997 begin 2998 with RW[ p].Un[uix] do2995 Loc0, uix1: Integer; 2996 Occ, ZoC: Boolean; 2997 begin 2998 with RW[P].Un[uix] do 2999 2999 begin 3000 3000 Job := jNone; … … 3004 3004 if Occupant[Loc0] >= 0 then 3005 3005 begin 3006 assert(Occupant[Loc0] = p);3007 Occ := false;3008 ZoC := false;3009 for uix1 := 0 to RW[ p].nUn - 1 do3010 with RW[ p].Un[uix1] do3006 Assert(Occupant[Loc0] = P); 3007 Occ := False; 3008 ZoC := False; 3009 for uix1 := 0 to RW[P].nUn - 1 do 3010 with RW[P].Un[uix1] do 3011 3011 if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then 3012 3012 begin 3013 Occ := true;3014 if RW[ p].Model[mix].Flags and mdZOC <> 0 then3013 Occ := True; 3014 if RW[P].Model[mix].Flags and mdZOC <> 0 then 3015 3015 begin 3016 ZoC := true;3016 ZoC := True; 3017 3017 Break; 3018 3018 end; … … 3025 3025 end; 3026 3026 3027 procedure PlaceUnit( p, uix: integer);3028 begin 3029 with RW[ p].Un[uix] do3030 begin 3031 Occupant[Loc] := p;3032 if RW[ p].Model[mix].Flags and mdZOC <> 0 then3027 procedure PlaceUnit(P, uix: Integer); 3028 begin 3029 with RW[P].Un[uix] do 3030 begin 3031 Occupant[Loc] := P; 3032 if RW[P].Model[mix].Flags and mdZOC <> 0 then 3033 3033 ZoCMap[Loc] := 1; 3034 3034 end; 3035 3035 end; 3036 3036 3037 procedure CountLost( p, mix, Enemy: integer);3038 begin 3039 Inc(RW[ p].Model[mix].Lost);3040 TellAboutModel(Enemy, p, mix);3041 Inc(Destroyed[Enemy, p, mix]);3042 end; 3043 3044 procedure RemoveUnit( p, uix: integer; Enemy: integer = -1);3037 procedure CountLost(P, mix, Enemy: Integer); 3038 begin 3039 Inc(RW[P].Model[mix].Lost); 3040 TellAboutModel(Enemy, P, mix); 3041 Inc(Destroyed[Enemy, P, mix]); 3042 end; 3043 3044 procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1); 3045 3045 // use enemy only from inside sMoveUnit if attack 3046 3046 var 3047 uix1: integer;3048 begin 3049 with RW[ p].Un[uix] do3050 begin 3051 assert((Loc >= 0) or (RW[p].Model[mix].Kind = mkDiplomat));3047 uix1: Integer; 3048 begin 3049 with RW[P].Un[uix] do 3050 begin 3051 Assert((Loc >= 0) or (RW[P].Model[mix].Kind = mkDiplomat)); 3052 3052 // already freed when spy mission 3053 3053 if Loc >= 0 then 3054 FreeUnit( p, uix);3054 FreeUnit(P, uix); 3055 3055 if Master >= 0 then 3056 if RW[ p].Model[mix].Domain = dAir then3057 dec(RW[p].Un[Master].AirLoad)3056 if RW[P].Model[mix].Domain = dAir then 3057 Dec(RW[P].Un[Master].AirLoad) 3058 3058 else 3059 dec(RW[p].Un[Master].TroopLoad);3059 Dec(RW[P].Un[Master].TroopLoad); 3060 3060 if (TroopLoad > 0) or (AirLoad > 0) then 3061 for uix1 := 0 to RW[ p].nUn - 1 do3062 if (RW[ p].Un[uix1].Loc >= 0) and (RW[p].Un[uix1].Master = uix) then3061 for uix1 := 0 to RW[P].nUn - 1 do 3062 if (RW[P].Un[uix1].Loc >= 0) and (RW[P].Un[uix1].Master = uix) then 3063 3063 { unit mastered by removed unit -- remove too } 3064 3064 begin 3065 RW[ p].Un[uix1].Loc := -1;3065 RW[P].Un[uix1].Loc := -1; 3066 3066 if Enemy >= 0 then 3067 CountLost( p, RW[p].Un[uix1].mix, Enemy);3067 CountLost(P, RW[P].Un[uix1].mix, Enemy); 3068 3068 end; 3069 3069 Loc := -1; 3070 3070 if Enemy >= 0 then 3071 CountLost( p, mix, Enemy);3072 end; 3073 end; 3074 3075 procedure RemoveUnit_UpdateMap( p, uix: integer);3071 CountLost(P, mix, Enemy); 3072 end; 3073 end; 3074 3075 procedure RemoveUnit_UpdateMap(P, uix: Integer); 3076 3076 var 3077 3077 Loc0: Integer; 3078 3078 begin 3079 Loc0 := RW[ p].Un[uix].Loc;3080 RemoveUnit( p, uix);3079 Loc0 := RW[P].Un[uix].Loc; 3080 RemoveUnit(P, uix); 3081 3081 if Mode > moLoading_Fast then 3082 3082 UpdateUnitMap(Loc0); 3083 3083 end; 3084 3084 3085 procedure RemoveAllUnits( p, Loc: integer; Enemy: integer = -1);3086 var 3087 uix: integer;3088 begin 3089 for uix := 0 to RW[ p].nUn - 1 do3090 if RW[ p].Un[uix].Loc = Loc then3085 procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1); 3086 var 3087 uix: Integer; 3088 begin 3089 for uix := 0 to RW[P].nUn - 1 do 3090 if RW[P].Un[uix].Loc = Loc then 3091 3091 begin 3092 3092 if Enemy >= 0 then 3093 CountLost( p, RW[p].Un[uix].mix, Enemy);3094 RW[ p].Un[uix].Loc := -1;3093 CountLost(P, RW[P].Un[uix].mix, Enemy); 3094 RW[P].Un[uix].Loc := -1; 3095 3095 end; 3096 3096 Occupant[Loc] := -1; … … 3098 3098 end; 3099 3099 3100 procedure RemoveDomainUnits( d, p, Loc: integer);3101 var 3102 uix: integer;3103 begin 3104 for uix := 0 to RW[ p].nUn - 1 do3105 if (RW[ p].Model[RW[p].Un[uix].mix].Domain = d) and (RW[p].Un[uix].Loc = Loc)3100 procedure RemoveDomainUnits(D, P, Loc: Integer); 3101 var 3102 uix: Integer; 3103 begin 3104 for uix := 0 to RW[P].nUn - 1 do 3105 if (RW[P].Model[RW[P].Un[uix].mix].Domain = D) and (RW[P].Un[uix].Loc = Loc) 3106 3106 then 3107 RemoveUnit( p, uix);3108 end; 3109 3110 procedure FoundCity( p, FoundLoc: integer);3111 var 3112 p1, cix1, V21, dx, dy: integer;3113 begin 3114 if RW[ p].nCity = ncmax then3115 exit;3116 inc(RW[p].nCity);3117 with RW[ p].City[RW[p].nCity - 1] do3107 RemoveUnit(P, uix); 3108 end; 3109 3110 procedure FoundCity(P, FoundLoc: Integer); 3111 var 3112 p1, cix1, V21, dx, dy: Integer; 3113 begin 3114 if RW[P].nCity = ncmax then 3115 Exit; 3116 Inc(RW[P].nCity); 3117 with RW[P].City[RW[P].nCity - 1] do 3118 3118 begin 3119 3119 Size := 2; … … 3131 3131 if UsedByCity[FoundLoc] >= 0 then 3132 3132 begin { central tile is exploited - toggle in exploiting city } 3133 p1 := p;3133 p1 := P; 3134 3134 SearchCity(UsedByCity[FoundLoc], p1, cix1); 3135 3135 dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy); … … 3142 3142 (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity; 3143 3143 3144 ChangeTerritory(Loc, p);3145 end; 3146 end; 3147 3148 procedure StealCity( p, cix: integer; SaveUnits: boolean);3149 var 3150 i, j, uix1, cix1, nearest: integer;3151 begin 3152 for i:= 0 to nWonder - 1 do3153 if RW[ p].City[cix].Built[i] = 1 then3154 begin 3155 GWonder[ i].EffectiveOwner := -1;3156 if i= woPyramids then3144 ChangeTerritory(Loc, P); 3145 end; 3146 end; 3147 3148 procedure StealCity(P, cix: Integer; SaveUnits: Boolean); 3149 var 3150 I, J, uix1, cix1, nearest: Integer; 3151 begin 3152 for I := 0 to nWonder - 1 do 3153 if RW[P].City[cix].Built[I] = 1 then 3154 begin 3155 GWonder[I].EffectiveOwner := -1; 3156 if I = woPyramids then 3157 3157 FreeSlaves; 3158 if i= woEiffel then // deactivate expired wonders3159 for j:= 0 to nWonder - 1 do3160 if GWonder[ j].EffectiveOwner = pthen3161 CheckExpiration( j);3162 end; 3163 for i:= nWonder to nImp - 1 do3164 if (Imp[ i].Kind <> ikCommon) and (RW[p].City[cix].Built[i] > 0) then3158 if I = woEiffel then // deactivate expired wonders 3159 for J := 0 to nWonder - 1 do 3160 if GWonder[J].EffectiveOwner = P then 3161 CheckExpiration(J); 3162 end; 3163 for I := nWonder to nImp - 1 do 3164 if (Imp[I].Kind <> ikCommon) and (RW[P].City[cix].Built[I] > 0) then 3165 3165 begin { destroy national projects } 3166 RW[ p].NatBuilt[i] := 0;3167 if i= imGrWall then3168 GrWallContinent[ p] := -1;3169 end; 3170 3171 for uix1 := 0 to RW[ p].nUn - 1 do3172 with RW[ p].Un[uix1] do3166 RW[P].NatBuilt[I] := 0; 3167 if I = imGrWall then 3168 GrWallContinent[P] := -1; 3169 end; 3170 3171 for uix1 := 0 to RW[P].nUn - 1 do 3172 with RW[P].Un[uix1] do 3173 3173 if (Loc >= 0) and (Home = cix) then 3174 3174 if SaveUnits then 3175 3175 begin // support units by nearest other city 3176 3176 nearest := -1; 3177 for cix1 := 0 to RW[ p].nCity - 1 do3178 if (cix1 <> cix) and (RW[ p].City[cix1].Loc >= 0) and3179 ((nearest < 0) or (Distance(RW[ p].City[cix1].Loc, Loc) <3180 Distance(RW[ p].City[nearest].Loc, Loc))) then3177 for cix1 := 0 to RW[P].nCity - 1 do 3178 if (cix1 <> cix) and (RW[P].City[cix1].Loc >= 0) and 3179 ((nearest < 0) or (Distance(RW[P].City[cix1].Loc, Loc) < 3180 Distance(RW[P].City[nearest].Loc, Loc))) then 3181 3181 nearest := cix1; 3182 3182 Home := nearest; 3183 3183 end 3184 3184 else 3185 RemoveUnit( p, uix1); // destroy supported units3186 end; 3187 3188 procedure DestroyCity( p, cix: integer; SaveUnits: boolean);3189 var 3190 i, V21: integer;3185 RemoveUnit(P, uix1); // destroy supported units 3186 end; 3187 3188 procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean); 3189 var 3190 I, V21: Integer; 3191 3191 Radius: TVicinity21Loc; 3192 3192 begin 3193 StealCity( p, cix, SaveUnits);3194 with RW[ p].City[cix] do begin3195 for i:= 0 to nWonder - 1 do3196 if Built[ i] > 0 then3197 GWonder[ i].CityID := WonderDestroyed;3193 StealCity(P, cix, SaveUnits); 3194 with RW[P].City[cix] do begin 3195 for I := 0 to nWonder - 1 do 3196 if Built[I] > 0 then 3197 GWonder[I].CityID := WonderDestroyed; 3198 3198 V21_to_Loc(Loc, Radius); 3199 3199 for V21 := 1 to 26 do … … 3201 3201 UsedByCity[Radius[V21]] := -1; 3202 3202 RealMap[Loc] := RealMap[Loc] and not fCity; 3203 Loc := -1 3204 end; 3205 end; 3206 3207 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);3208 var 3209 i, j, cix1, Loc1, V21: integer;3203 Loc := -1; 3204 end; 3205 end; 3206 3207 procedure ChangeCityOwner(pOld, cixOld, pNew: Integer); 3208 var 3209 I, J, cix1, Loc1, V21: Integer; 3210 3210 Radius: TVicinity21Loc; 3211 3211 begin 3212 inc(RW[pNew].nCity);3212 Inc(RW[pNew].nCity); 3213 3213 RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld]; 3214 StealCity(pOld, cixOld, false);3214 StealCity(pOld, cixOld, False); 3215 3215 RW[pOld].City[cixOld].Loc := -1; 3216 3216 with RW[pNew].City[(RW[pNew].nCity - 1)] do … … 3231 3231 begin 3232 3232 Loc1 := Radius[V21]; 3233 assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));3233 Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc)); 3234 3234 if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and 3235 3235 (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then … … 3243 3243 Built[imTownHall] := 0; 3244 3244 Built[imCourt] := 0; 3245 for i:= nWonder to nImp - 1 do3246 if Imp[ i].Kind <> ikCommon then3247 Built[ i] := 0; { destroy national projects }3248 for i:= 0 to nWonder - 1 do3249 if Built[ i] = 1 then3245 for I := nWonder to nImp - 1 do 3246 if Imp[I].Kind <> ikCommon then 3247 Built[I] := 0; { destroy national projects } 3248 for I := 0 to nWonder - 1 do 3249 if Built[I] = 1 then 3250 3250 begin // new wonder owner! 3251 GWonder[ i].EffectiveOwner := pNew;3252 if i= woEiffel then // reactivate expired wonders3253 begin 3254 for j:= 0 to nWonder - 1 do3255 if Imp[ j].Expiration >= 0 then3251 GWonder[I].EffectiveOwner := pNew; 3252 if I = woEiffel then // reactivate expired wonders 3253 begin 3254 for J := 0 to nWonder - 1 do 3255 if Imp[J].Expiration >= 0 then 3256 3256 for cix1 := 0 to (RW[pNew].nCity - 1) do 3257 if RW[pNew].City[cix1].Built[ j] = 1 then3258 GWonder[ j].EffectiveOwner := pNew;3257 if RW[pNew].City[cix1].Built[J] = 1 then 3258 GWonder[J].EffectiveOwner := pNew; 3259 3259 end 3260 3260 else 3261 CheckExpiration( i);3262 case iof3261 CheckExpiration(I); 3262 case I of 3263 3263 woLighthouse: 3264 3264 CheckSpecialModels(pNew, preLighthouse); … … 3274 3274 cix1 := RW[pNew].nEnemyCity - 1; 3275 3275 while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do 3276 dec(cix1);3277 assert(cix1 >= 0);3276 Dec(cix1); 3277 Assert(cix1 >= 0); 3278 3278 RW[pNew].EnemyCity[cix1].Loc := -1; 3279 3279 … … 3282 3282 end; 3283 3283 3284 procedure CompleteJob( p, Loc, Job: integer);3285 var 3286 ChangedTerrain, p1: integer;3287 begin 3288 assert(Job <> jCity);3284 procedure CompleteJob(P, Loc, Job: Integer); 3285 var 3286 ChangedTerrain, p1: Integer; 3287 begin 3288 Assert(Job <> jCity); 3289 3289 ChangedTerrain := -1; 3290 3290 case Job of … … 3328 3328 if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then 3329 3329 begin 3330 RemoveDomainUnits(dSea, p, Loc);3330 RemoveDomainUnits(dSea, P, Loc); 3331 3331 RealMap[Loc] := RealMap[Loc] and not fCanal; 3332 3332 end; … … 3340 3340 begin 3341 3341 if RealMap[Loc] and fTerImp = tiBase then 3342 RemoveDomainUnits(dAir, p, Loc);3342 RemoveDomainUnits(dAir, P, Loc); 3343 3343 RealMap[Loc] := RealMap[Loc] and not fTerImp 3344 3344 end 3345 3345 else if RealMap[Loc] and fCanal <> 0 then 3346 3346 begin 3347 RemoveDomainUnits(dSea, p, Loc);3347 RemoveDomainUnits(dSea, P, Loc); 3348 3348 RealMap[Loc] := RealMap[Loc] and not fCanal 3349 3349 end … … 3381 3381 ____________________________________________________________________ 3382 3382 } 3383 procedure GiveCivilReport( p, pAbout: integer);3384 begin 3385 with RW[ p].EnemyReport[pAbout]^ do3383 procedure GiveCivilReport(P, pAbout: Integer); 3384 begin 3385 with RW[P].EnemyReport[pAbout]^ do 3386 3386 begin 3387 3387 // general info 3388 3388 TurnOfCivilReport := LastValidStat[pAbout]; 3389 move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));3389 Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty)); 3390 3390 Government := RW[pAbout].Government; 3391 3391 Money := RW[pAbout].Money; … … 3396 3396 if ResearchDone > 100 then 3397 3397 ResearchDone := 100; 3398 move(RW[pAbout].Tech, Tech, nAdv);3399 end; 3400 end; 3401 3402 procedure GiveMilReport( p, pAbout: integer);3403 var 3404 uix, mix: integer;3405 begin 3406 with RW[ p].EnemyReport[pAbout]^ do3398 Move(RW[pAbout].Tech, Tech, nAdv); 3399 end; 3400 end; 3401 3402 procedure GiveMilReport(P, pAbout: Integer); 3403 var 3404 uix, mix: Integer; 3405 begin 3406 with RW[P].EnemyReport[pAbout]^ do 3407 3407 begin 3408 3408 TurnOfMilReport := LastValidStat[pAbout]; … … 3410 3410 for mix := 0 to RW[pAbout].nModel - 1 do 3411 3411 begin 3412 TellAboutModel( p, pAbout, mix);3412 TellAboutModel(P, pAbout, mix); 3413 3413 UnCount[mix] := 0 3414 3414 end; 3415 3415 for uix := 0 to RW[pAbout].nUn - 1 do 3416 3416 if RW[pAbout].Un[uix].Loc >= 0 then 3417 inc(UnCount[RW[pAbout].Un[uix].mix]);3418 end; 3419 end; 3420 3421 procedure ShowPrice(pSender, pTarget, Price: integer);3417 Inc(UnCount[RW[pAbout].Un[uix].mix]); 3418 end; 3419 end; 3420 3421 procedure ShowPrice(pSender, pTarget, Price: Integer); 3422 3422 begin 3423 3423 case Price and opMask of … … 3434 3434 end; 3435 3435 3436 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;3437 var 3438 i: integer;3436 function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean; 3437 var 3438 I: Integer; 3439 3439 rSender, rTarget: ^TEnemyReport; 3440 3440 begin // copy third nation civil report 3441 result := false;3441 Result := False; 3442 3442 if RW[pTarget].Treaty[pAbout] = trNoContact then 3443 3443 IntroduceEnemy(pTarget, pAbout); 3444 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3445 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3444 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3445 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3446 3446 if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then 3447 3447 begin // only if newer than current information … … 3452 3452 rTarget.ResearchTech := rSender.ResearchTech; 3453 3453 rTarget.ResearchDone := rSender.ResearchDone; 3454 result := true;3455 end; 3456 for i:= 0 to nAdv - 1 do3457 if rTarget.Tech[ i] < rSender.Tech[i] then3458 begin 3459 rTarget.Tech[ i] := rSender.Tech[i];3460 result := true;3461 end; 3462 end; 3463 3464 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;3465 var 3466 mix: integer;3454 Result := True; 3455 end; 3456 for I := 0 to nAdv - 1 do 3457 if rTarget.Tech[I] < rSender.Tech[I] then 3458 begin 3459 rTarget.Tech[I] := rSender.Tech[I]; 3460 Result := True; 3461 end; 3462 end; 3463 3464 function CopyMilReport(pSender, pTarget, pAbout: Integer): Boolean; 3465 var 3466 mix: Integer; 3467 3467 rSender, rTarget: ^TEnemyReport; 3468 3468 begin // copy third nation military report 3469 result := false;3469 Result := False; 3470 3470 if RW[pTarget].Treaty[pAbout] = trNoContact then 3471 3471 IntroduceEnemy(pTarget, pAbout); 3472 rSender := pointer(RW[pSender].EnemyReport[pAbout]);3473 rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);3472 rSender := Pointer(RW[pSender].EnemyReport[pAbout]); 3473 rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]); 3474 3474 if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then 3475 3475 begin // only if newer than current information 3476 3476 rTarget.TurnOfMilReport := rSender.TurnOfMilReport; 3477 3477 rTarget.nModelCounted := rSender.nModelCounted; 3478 move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);3478 Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted); 3479 3479 for mix := 0 to rTarget.nModelCounted - 1 do 3480 3480 TellAboutModel(pTarget, pAbout, mix); 3481 result := true;3482 end; 3483 end; 3484 3485 procedure CopyModel(pSender, pTarget, mix: integer);3486 var 3487 i: integer;3481 Result := True; 3482 end; 3483 end; 3484 3485 procedure CopyModel(pSender, pTarget, mix: Integer); 3486 var 3487 I: Integer; 3488 3488 miSender, miTarget: TModelInfo; 3489 ok: boolean;3489 ok: Boolean; 3490 3490 begin 3491 3491 // only if target doesn't already have a model like this 3492 3492 ok := RW[pTarget].nModel < nmmax; 3493 3493 MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender); 3494 for i:= 0 to RW[pTarget].nModel - 1 do3495 begin 3496 MakeModelInfo(pTarget, i, RW[pTarget].Model[i], miTarget);3494 for I := 0 to RW[pTarget].nModel - 1 do 3495 begin 3496 MakeModelInfo(pTarget, I, RW[pTarget].Model[I], miTarget); 3497 3497 if IsSameModel(miSender, miTarget) then 3498 ok := false;3498 ok := False; 3499 3499 end; 3500 3500 if ok then … … 3511 3511 Lost := 0; 3512 3512 end; 3513 inc(RW[pTarget].nModel);3514 inc(Researched[pTarget]);3513 Inc(RW[pTarget].nModel); 3514 Inc(Researched[pTarget]); 3515 3515 TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1); 3516 3516 end; 3517 3517 end; 3518 3518 3519 procedure CopyMap(pSender, pTarget: integer);3520 var 3521 Loc, i, cix: integer;3519 procedure CopyMap(pSender, pTarget: Integer); 3520 var 3521 Loc, I, cix: Integer; 3522 3522 Tile: Cardinal; 3523 3523 begin … … 3529 3529 if Tile and fCity <> 0 then 3530 3530 begin 3531 i:= 0;3532 while ( i< RW[pTarget].nEnemyCity) and3533 (RW[pTarget].EnemyCity[ i].Loc <> Loc) do3534 inc(i);3535 if i= RW[pTarget].nEnemyCity then3536 begin 3537 inc(RW[pTarget].nEnemyCity);3538 assert(RW[pTarget].nEnemyCity < necmax);3539 RW[pTarget].EnemyCity[ i].Status := 0;3540 RW[pTarget].EnemyCity[ i].SavedStatus := 0;3531 I := 0; 3532 while (I < RW[pTarget].nEnemyCity) and 3533 (RW[pTarget].EnemyCity[I].Loc <> Loc) do 3534 Inc(I); 3535 if I = RW[pTarget].nEnemyCity then 3536 begin 3537 Inc(RW[pTarget].nEnemyCity); 3538 Assert(RW[pTarget].nEnemyCity < necmax); 3539 RW[pTarget].EnemyCity[I].Status := 0; 3540 RW[pTarget].EnemyCity[I].SavedStatus := 0; 3541 3541 end; 3542 3542 if Tile and fOwned <> 0 then … … 3544 3544 cix := RW[pSender].nCity - 1; 3545 3545 while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do 3546 dec(cix);3547 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[ i]);3546 Dec(cix); 3547 MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]); 3548 3548 end 3549 3549 else // city not owned by sender -- copy old info … … 3551 3551 cix := RW[pSender].nEnemyCity - 1; 3552 3552 while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do 3553 dec(cix);3554 RW[pTarget].EnemyCity[ i] := RW[pSender].EnemyCity[cix];3553 Dec(cix); 3554 RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix]; 3555 3555 end; 3556 3556 end … … 3566 3566 3567 3567 if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then 3568 inc(Discovered[pTarget]);3568 Inc(Discovered[pTarget]); 3569 3569 RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC 3570 3570 // always preserve this flag! … … 3582 3582 end; 3583 3583 3584 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;3585 var 3586 pSubject, i, n, NewTreaty: integer;3587 begin 3588 result := true;3584 function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean; 3585 var 3586 pSubject, I, N, NewTreaty: Integer; 3587 begin 3588 Result := True; 3589 3589 case Price and opMask of 3590 3590 opCivilReport: // + turn + concerned player shl 16 … … 3592 3592 pSubject := Price shr 16 and $F; 3593 3593 if pTarget = pSubject then 3594 result := false3594 Result := False 3595 3595 else if pSender = pSubject then 3596 3596 begin … … 3599 3599 end 3600 3600 else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then 3601 result := false3601 Result := False 3602 3602 else if execute then 3603 3603 CopyCivilReport(pSender, pTarget, pSubject); … … 3607 3607 pSubject := Price shr 16 and $F; 3608 3608 if pTarget = pSubject then 3609 result := false3609 Result := False 3610 3610 else if pSender = pSubject then 3611 3611 begin … … 3614 3614 end 3615 3615 else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then 3616 result := false3616 Result := False 3617 3617 else if execute then 3618 3618 CopyMilReport(pSender, pTarget, pSubject); … … 3629 3629 begin // agreed treaty end 3630 3630 if execute then 3631 CancelTreaty(pSender, pTarget, false);3631 CancelTreaty(pSender, pTarget, False); 3632 3632 end 3633 3633 else … … 3640 3640 NewTreaty := trPeace; 3641 3641 if NewTreaty < 0 then 3642 result := false3642 Result := False 3643 3643 else if execute then 3644 3644 begin 3645 assert(NewTreaty > RW[pSender].Treaty[pTarget]);3645 Assert(NewTreaty > RW[pSender].Treaty[pTarget]); 3646 3646 RW[pSender].Treaty[pTarget] := NewTreaty; 3647 3647 RW[pTarget].Treaty[pSender] := NewTreaty; … … 3672 3672 opShipParts: // + number + part type shl 16 3673 3673 begin 3674 n:= Price and $FFFF; // number3675 i:= Price shr 16 and $F; // type3676 if ( i < nShipPart) and (GShip[pSender].Parts[i] >= n) then3674 N := Price and $FFFF; // number 3675 I := Price shr 16 and $F; // type 3676 if (I < nShipPart) and (GShip[pSender].Parts[I] >= N) then 3677 3677 begin 3678 3678 if execute then 3679 3679 begin 3680 dec(GShip[pSender].Parts[i], n);3681 RW[pSender].Ship[pSender].Parts[ i] := GShip[pSender].Parts[i];3682 RW[pTarget].Ship[pSender].Parts[ i] := GShip[pSender].Parts[i];3680 Dec(GShip[pSender].Parts[I], N); 3681 RW[pSender].Ship[pSender].Parts[I] := GShip[pSender].Parts[I]; 3682 RW[pTarget].Ship[pSender].Parts[I] := GShip[pSender].Parts[I]; 3683 3683 if RW[pTarget].NatBuilt[imSpacePort] > 0 then 3684 3684 begin // space ship control requires space port 3685 inc(GShip[pTarget].Parts[i], n);3686 RW[pSender].Ship[pTarget].Parts[ i] := GShip[pTarget].Parts[i];3687 RW[pTarget].Ship[pTarget].Parts[ i] := GShip[pTarget].Parts[i];3685 Inc(GShip[pTarget].Parts[I], N); 3686 RW[pSender].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I]; 3687 RW[pTarget].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I]; 3688 3688 end; 3689 3689 end; 3690 3690 end 3691 3691 else 3692 result := false;3692 Result := False; 3693 3693 end; 3694 3694 opMoney: // + value … … 3698 3698 if execute then 3699 3699 begin 3700 dec(RW[pSender].Money, Price - opMoney);3701 inc(RW[pTarget].Money, Price - opMoney);3700 Dec(RW[pSender].Money, Price - opMoney); 3701 Inc(RW[pTarget].Money, Price - opMoney); 3702 3702 end; 3703 3703 end 3704 3704 else 3705 result := false;3705 Result := False; 3706 3706 opTribute: // + value 3707 3707 if execute then … … 3718 3718 end 3719 3719 else 3720 result := false;3720 Result := False; 3721 3721 opAllTech: 3722 3722 if execute then 3723 for i:= 0 to nAdv - 1 do3724 if (RW[pSender].Tech[ i] >= tsApplicable) and3725 (RW[pTarget].Tech[ i] = tsNA) then3723 for I := 0 to nAdv - 1 do 3724 if (RW[pSender].Tech[I] >= tsApplicable) and 3725 (RW[pTarget].Tech[I] = tsNA) then 3726 3726 begin 3727 SeeTech(pTarget, i);3728 RW[pSender].EnemyReport[pTarget].Tech[ i] := tsSeen;3729 RW[pTarget].EnemyReport[pSender].Tech[ i] := tsApplicable;3727 SeeTech(pTarget, I); 3728 RW[pSender].EnemyReport[pTarget].Tech[I] := tsSeen; 3729 RW[pTarget].EnemyReport[pSender].Tech[I] := tsApplicable; 3730 3730 end; 3731 3731 opModel: // + model index … … 3736 3736 end 3737 3737 else 3738 result := false;3738 Result := False; 3739 3739 opAllModel: 3740 3740 if execute then 3741 for i:= 0 to RW[pSender].nModel - 1 do3742 begin 3743 TellAboutModel(pTarget, pSender, i);3744 CopyModel(pSender, pTarget, i);3741 for I := 0 to RW[pSender].nModel - 1 do 3742 begin 3743 TellAboutModel(pTarget, pSender, I); 3744 CopyModel(pSender, pTarget, I); 3745 3745 end; 3746 3746 { opCity: // + city ID 3747 3747 begin 3748 result:=false3748 Result:=False 3749 3749 end; } 3750 3750 end; 3751 3751 end; 3752 3752 3753 procedure CancelTreaty( p, pWith: integer; DecreaseCredibility: boolean);3753 procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean); 3754 3754 // side effect: PeaceEnded := bitarray of players with which peace treaty was canceled 3755 3755 var 3756 p1, OldTreaty: integer;3757 begin 3758 OldTreaty := RW[ p].Treaty[pWith];3756 p1, OldTreaty: Integer; 3757 begin 3758 OldTreaty := RW[P].Treaty[pWith]; 3759 3759 PeaceEnded := 0; 3760 3760 if OldTreaty >= trPeace then 3761 RW[ p].LastCancelTreaty[pWith] := GTurn;3761 RW[P].LastCancelTreaty[pWith] := GTurn; 3762 3762 if DecreaseCredibility then 3763 3763 begin … … 3765 3765 trPeace: 3766 3766 begin 3767 RW[ p].Credibility := RW[p].Credibility shr 1;3768 if RW[ p].MaxCredibility > 0 then3769 dec(RW[p].MaxCredibility, 10);3770 if RW[ p].Credibility > RW[p].MaxCredibility then3771 RW[ p].Credibility := RW[p].MaxCredibility;3767 RW[P].Credibility := RW[P].Credibility shr 1; 3768 if RW[P].MaxCredibility > 0 then 3769 Dec(RW[P].MaxCredibility, 10); 3770 if RW[P].Credibility > RW[P].MaxCredibility then 3771 RW[P].Credibility := RW[P].MaxCredibility; 3772 3772 end; 3773 3773 trAlliance: 3774 RW[ p].Credibility := RW[p].Credibility * 3 div 4;3775 end; 3776 RW[pWith].EnemyReport[ p].Credibility := RW[p].Credibility;3774 RW[P].Credibility := RW[P].Credibility * 3 div 4; 3775 end; 3776 RW[pWith].EnemyReport[P].Credibility := RW[P].Credibility; 3777 3777 end; 3778 3778 … … 3780 3780 begin 3781 3781 for p1 := 0 to nPl - 1 do 3782 if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and3783 (RW[pWith].Treaty[p1] = trAlliance) and (RW[ p].Treaty[p1] >= trPeace)3782 if (p1 = pWith) or DecreaseCredibility and (p1 <> P) and 3783 (RW[pWith].Treaty[p1] = trAlliance) and (RW[P].Treaty[p1] >= trPeace) 3784 3784 then 3785 3785 begin 3786 RW[ p].Treaty[p1] := trNone;3787 RW[p1].Treaty[ p] := trNone;3788 RW[ p].EvaStart[p1] := -PeaceEvaTurns - 1;3789 RW[p1].EvaStart[ p] := -PeaceEvaTurns - 1;3790 inc(PeaceEnded, 1 shl p1);3786 RW[P].Treaty[p1] := trNone; 3787 RW[p1].Treaty[P] := trNone; 3788 RW[P].EvaStart[p1] := -PeaceEvaTurns - 1; 3789 RW[p1].EvaStart[P] := -PeaceEvaTurns - 1; 3790 Inc(PeaceEnded, 1 shl p1); 3791 3791 end; 3792 3792 CheckBorders(-1); 3793 3793 if (Mode > moLoading_Fast) and (PeaceEnded > 0) then 3794 RecalcMapZoC( p);3794 RecalcMapZoC(P); 3795 3795 end 3796 3796 else 3797 3797 begin 3798 RW[ p].Treaty[pWith] := OldTreaty - 1;3799 RW[pWith].Treaty[ p] := OldTreaty - 1;3798 RW[P].Treaty[pWith] := OldTreaty - 1; 3799 RW[pWith].Treaty[P] := OldTreaty - 1; 3800 3800 if OldTreaty = TrFriendlyContact then 3801 3801 begin // necessary for loading 3802 GiveCivilReport( p, pWith);3803 GiveCivilReport(pWith, p);3802 GiveCivilReport(P, pWith); 3803 GiveCivilReport(pWith, P); 3804 3804 end 3805 3805 else if OldTreaty = trAlliance then 3806 3806 begin // necessary for loading 3807 GiveMilReport( p, pWith);3808 GiveMilReport(pWith, p);3807 GiveMilReport(P, pWith); 3808 GiveMilReport(pWith, P); 3809 3809 end; 3810 3810 if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then 3811 3811 begin 3812 RecalcMapZoC( p);3812 RecalcMapZoC(P); 3813 3813 RecalcMapZoC(pWith); 3814 3814 end; … … 3816 3816 if OldTreaty in [trPeace, trAlliance] then 3817 3817 begin 3818 RecalcPeaceMap( p);3818 RecalcPeaceMap(P); 3819 3819 RecalcPeaceMap(pWith); 3820 3820 end; 3821 3821 end; 3822 3822 3823 function DoSpyMission( p, pCity, cix, Mission: integer): Cardinal;3824 var 3825 p1: integer;3826 begin 3827 result := 0;3823 function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal; 3824 var 3825 p1: Integer; 3826 begin 3827 Result := 0; 3828 3828 case Mission of 3829 3829 smSabotageProd: … … 3832 3832 smStealMap: 3833 3833 begin 3834 CopyMap(pCity, p);3835 RecalcPeaceMap( p);3834 CopyMap(pCity, P); 3835 RecalcPeaceMap(P); 3836 3836 end; 3837 3837 smStealCivilReport: 3838 3838 begin 3839 if RW[ p].Treaty[pCity] = trNoContact then3840 IntroduceEnemy( p, pCity);3841 GiveCivilReport( p, pCity);3839 if RW[P].Treaty[pCity] = trNoContact then 3840 IntroduceEnemy(P, pCity); 3841 GiveCivilReport(P, pCity); 3842 3842 end; 3843 3843 smStealMilReport: 3844 3844 begin 3845 if RW[ p].Treaty[pCity] = trNoContact then3846 IntroduceEnemy( p, pCity);3847 GiveMilReport( p, pCity);3845 if RW[P].Treaty[pCity] = trNoContact then 3846 IntroduceEnemy(P, pCity); 3847 GiveMilReport(P, pCity); 3848 3848 end; 3849 3849 smStealForeignReports: 3850 3850 begin 3851 3851 for p1 := 0 to nPl - 1 do 3852 if (p1 <> p) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)3852 if (p1 <> P) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil) 3853 3853 then 3854 3854 begin 3855 3855 if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then 3856 if CopyCivilReport(pCity, p, p1) then3857 result := result or (1 shl (2 * p1));3856 if CopyCivilReport(pCity, P, p1) then 3857 Result := Result or (1 shl (2 * p1)); 3858 3858 if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then 3859 if CopyMilReport(pCity, p, p1) then3860 result := result or (2 shl (2 * p1));3859 if CopyMilReport(pCity, P, p1) then 3860 Result := Result or (2 shl (2 * p1)); 3861 3861 end; 3862 3862 end; … … 3868 3868 ____________________________________________________________________ 3869 3869 } 3870 procedure ClearTestFlags(ClearFlags: integer);3871 var 3872 p1: integer;3870 procedure ClearTestFlags(ClearFlags: Integer); 3871 var 3872 p1: Integer; 3873 3873 begin 3874 3874 GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or … … 3879 3879 end; 3880 3880 3881 procedure SetTestFlags( p, SetFlags: integer);3882 var 3883 i, p1, p2, MoreFlags: integer;3881 procedure SetTestFlags(P, SetFlags: Integer); 3882 var 3883 I, p1, p2, MoreFlags: Integer; 3884 3884 begin 3885 3885 MoreFlags := SetFlags and not GTestFlags; … … 3905 3905 if 1 shl p1 and GAlive <> 0 then 3906 3906 begin 3907 for i:= 0 to nAdv - 1 do // give all techs to player p13908 if not( i in FutureTech) and (RW[p1].Tech[i] < tsApplicable) then3907 for I := 0 to nAdv - 1 do // give all techs to player p1 3908 if not(I in FutureTech) and (RW[p1].Tech[I] < tsApplicable) then 3909 3909 begin 3910 RW[p1].Tech[ i] := tsCheat;3911 CheckSpecialModels(p1, i);3910 RW[p1].Tech[I] := tsCheat; 3911 CheckSpecialModels(p1, I); 3912 3912 end; 3913 3913 for p2 := 0 to nPl - 1 do 3914 3914 if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then 3915 for i:= 1 to 3 do3916 if RW[p2].EnemyReport[p1].Tech[AgePreq[ i]] < tsApplicable then3917 RW[p2].EnemyReport[p1].Tech[AgePreq[ i]] := tsCheat;3915 for I := 1 to 3 do 3916 if RW[p2].EnemyReport[p1].Tech[AgePreq[I]] < tsApplicable then 3917 RW[p2].EnemyReport[p1].Tech[AgePreq[I]] := tsCheat; 3918 3918 end; 3919 3919 end; … … 3921 3921 if MoreFlags and tfUncover <> 0 then 3922 3922 begin 3923 DiscoverAll( p, lObserveSuper);3923 DiscoverAll(P, lObserveSuper); 3924 3924 for p1 := 0 to nPl - 1 do 3925 3925 if 1 shl p1 and GAlive <> 0 then 3926 3926 begin 3927 3927 ResourceMask[p1] := $FFFFFFFF; 3928 if p1 <> pthen3929 begin 3930 GiveCivilReport( p, p1);3931 GiveMilReport( p, p1);3928 if p1 <> P then 3929 begin 3930 GiveCivilReport(P, p1); 3931 GiveMilReport(P, p1); 3932 3932 end; 3933 3933 end; … … 3939 3939 ____________________________________________________________________ 3940 3940 } 3941 procedure IntServer(Command, Player, Subject: integer; var Data);3942 var 3943 i, p1: integer;3941 procedure IntServer(Command, Player, Subject: Integer; var Data); 3942 var 3943 I, p1: Integer; 3944 3944 begin 3945 3945 if Mode = moPlaying then … … 3951 3951 begin 3952 3952 {$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutNation P%d+P%d', [Player, Subject]); {$ENDIF} 3953 assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and3953 Assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and 3954 3954 (Subject < nPl)); 3955 3955 IntroduceEnemy(Player, Subject); … … 3959 3959 begin 3960 3960 {$IFDEF TEXTLOG}CmdInfo := Format('IntHaveContact P%d+P%d', [Player, Subject]); {$ENDIF} 3961 assert(RW[Player].Treaty[Subject] > trNoContact);3961 Assert(RW[Player].Treaty[Subject] > trNoContact); 3962 3962 RW[Player].EnemyReport[Subject].TurnOfContact := GTurn; 3963 3963 RW[Subject].EnemyReport[Player].TurnOfContact := GTurn; … … 3981 3981 p1 := (Command - sIntTellAboutModel) shr 4; // told player 3982 3982 {$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutModel P%d about P%d Mod%d', [p1, Player, Subject]); {$ENDIF} 3983 assert((Player >= 0) and (Player < nPl));3984 assert((Subject >= 0) and (Subject < RW[Player].nModel));3983 Assert((Player >= 0) and (Player < nPl)); 3984 Assert((Subject >= 0) and (Subject < RW[Player].nModel)); 3985 3985 MakeModelInfo(Player, Subject, RW[Player].Model[Subject], 3986 3986 RW[p1].EnemyModel[RW[p1].nEnemyModel]); 3987 3987 RWemix[p1, Player, Subject] := RW[p1].nEnemyModel; 3988 inc(RW[p1].nEnemyModel);3989 assert(RW[p1].nEnemyModel < nemmax);3988 Inc(RW[p1].nEnemyModel); 3989 Assert(RW[p1].nEnemyModel < nemmax); 3990 3990 end; 3991 3991 3992 3992 sIntDiscoverZOC: 3993 3993 begin 3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, integer(Data)]); {$ENDIF}3995 Discover9( integer(Data), Player, lObserveUnhidden, true, false);3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, Integer(Data)]); {$ENDIF} 3995 Discover9(Integer(Data), Player, lObserveUnhidden, True, False); 3996 3996 end; 3997 3997 … … 4000 4000 begin 4001 4001 {$IFDEF TEXTLOG}CmdInfo := Format('IntExpandTerritory P%d Loc%d', [Player, RW[Player].City[Subject].Loc]); {$ENDIF} 4002 move(Data, BorderChanges, SizeOf(BorderChanges));4002 Move(Data, BorderChanges, SizeOf(BorderChanges)); 4003 4003 ExpandTerritory(RW[Player].City[Subject].Loc); 4004 4004 end; … … 4007 4007 with RW[Player].City[Subject] do 4008 4008 begin 4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, integer(Data)]); {$ENDIF}4010 dec(RW[Player].Money, integer(Data));4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, Integer(Data)]); {$ENDIF} 4010 Dec(RW[Player].Money, Integer(Data)); 4011 4011 if (GWonder[woMich].EffectiveOwner = Player) and (Project and cpImp <> 0) 4012 4012 then 4013 inc(Prod, integer(Data) div 2)4013 Inc(Prod, Integer(Data) div 2) 4014 4014 else 4015 inc(Prod, integer(Data) div 4);4015 Inc(Prod, Integer(Data) div 4); 4016 4016 if Project0 and not cpAuto <> Project and not cpAuto then 4017 4017 Project0 := Project; … … 4022 4022 begin 4023 4023 {$IFDEF TEXTLOG}CmdInfo := Format('IntPayPrices P%d+P%d', [Player, Subject]); {$ENDIF} 4024 for i:= 0 to TOffer(Data).nDeliver - 1 do4025 PayPrice(Player, Subject, TOffer(Data).Price[ i], true);4026 for i:= 0 to TOffer(Data).nCost - 1 do4024 for I := 0 to TOffer(Data).nDeliver - 1 do 4025 PayPrice(Player, Subject, TOffer(Data).Price[I], True); 4026 for I := 0 to TOffer(Data).nCost - 1 do 4027 4027 PayPrice(Subject, Player, TOffer(Data).Price[TOffer(Data).nDeliver 4028 + i], true);4029 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do4030 if TOffer(Data).Price[ i] = opTreaty + trAlliance then4028 + I], True); 4029 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 4030 if TOffer(Data).Price[I] = opTreaty + trAlliance then 4031 4031 begin // add view area of allied player 4032 4032 DiscoverViewAreas(Player); … … 4045 4045 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetModelStatus P%d', [Player]); 4046 4046 {$ENDIF} 4047 RW[Player].Model[Subject].Status := integer(Data);4047 RW[Player].Model[Subject].Status := Integer(Data); 4048 4048 end; 4049 4049 … … 4053 4053 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetUnitStatus P%d', [Player]); 4054 4054 {$ENDIF} 4055 RW[Player].Un[Subject].Status := integer(Data);4055 RW[Player].Un[Subject].Status := Integer(Data); 4056 4056 end; 4057 4057 … … 4061 4061 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetCityStatus P%d', [Player]); 4062 4062 {$ENDIF} 4063 RW[Player].City[Subject].Status := integer(Data);4063 RW[Player].City[Subject].Status := Integer(Data); 4064 4064 end; 4065 4065 … … 4069 4069 {$IFDEF TEXTLOG}CmdInfo := Format('IntSetECityStatus P%d', [Player]); 4070 4070 {$ENDIF} 4071 RW[Player].EnemyCity[Subject].Status := integer(Data);4071 RW[Player].EnemyCity[Subject].Status := Integer(Data); 4072 4072 end; 4073 4073 end;
Note:
See TracChangeset
for help on using the changeset viewer.