Changeset 465 for branches/highdpi/GameServer.pas
- Timestamp:
- Nov 30, 2023, 10:16:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/GameServer.pas
r405 r465 7 7 8 8 uses 9 Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,10 Graphics, UBrain, Global;9 Protocol, Database, dynlibs, Platform, dateutils, LazFileUtils, Graphics, 10 Brain, Global; 11 11 12 12 const … … 49 49 // PARAMETERS 50 50 PlayersBrain: TBrains; { brain of the players view } 51 Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty;51 Difficulty: array [0 .. nPl - 1] of Integer absolute Database.Difficulty; 52 52 { difficulty } 53 53 … … 70 70 71 71 procedure StartNewGame(const Path, FileName, Map: string; 72 Newlx, Newly, NewLandMass, NewMaxTurn: integer);73 function LoadGame(const Path, FileName: string; Turn: integer;74 MovieMode: boolean): boolean;75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);76 procedure DirectHelp(Command: integer);72 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 73 function LoadGame(const Path, FileName: string; Turn: Integer; 74 MovieMode: Boolean): Boolean; 75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer); 76 procedure DirectHelp(Command: Integer); 77 77 78 78 procedure ChangeClient; 79 79 procedure NextPlayer; 80 function PreviewMap(lm: integer): pointer;80 function PreviewMap(lm: Integer): Pointer; 81 81 82 82 … … 112 112 MapField: ^Cardinal; // predefined map 113 113 LastOffer: TOffer; 114 CCData: array [0 .. 14] of integer;114 CCData: array [0 .. 14] of Integer; 115 115 bix: TBrains; { brain of the players } 116 116 DevModelTurn: array [0 .. nPl - 1] of Integer; { turn of last call to sResetModel } 117 117 OriginalDataVersion: array [0 .. nPl - 1] of Integer; 118 118 SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal; 119 SavedData: array [0 .. nPl - 1] of pointer;119 SavedData: array [0 .. nPl - 1] of Pointer; 120 120 LogFileName: string; 121 121 SavePath: string; { name of file for saving the current game } … … 135 135 PreviewRND = 41601260; { randseed for preview map } 136 136 137 function Server(Command, Player, Subject: integer; var Data): integer;137 function Server(Command, Player, Subject: Integer; var Data): Integer; 138 138 stdcall; forward; 139 139 140 procedure CallPlayer(Command, p: integer; var Data);140 procedure CallPlayer(Command, P: Integer; var Data); 141 141 begin 142 if ((Mode <> moMovie) or ( p= 0)) then142 if ((Mode <> moMovie) or (P = 0)) then 143 143 begin 144 144 {$IFOPT O-} 145 HandoverStack[nHandoverStack] := p;145 HandoverStack[nHandoverStack] := P; 146 146 HandoverStack[nHandoverStack + 1] := Command; 147 inc(nHandoverStack, 2);148 bix[ p].Client(Command, p, Data);149 dec(nHandoverStack, 2);147 Inc(nHandoverStack, 2); 148 bix[P].Client(Command, P, Data); 149 Dec(nHandoverStack, 2); 150 150 {$ELSE} 151 151 try 152 bix[ p].Client(Command, p, Data);152 bix[P].Client(Command, P, Data); 153 153 except 154 Notify(ntException + bix[ p]);154 Notify(ntException + bix[P]); 155 155 end; 156 156 {$ENDIF} 157 end 157 end; 158 158 end; 159 159 … … 167 167 end; 168 168 169 procedure CallClient(bix, Command: integer; var Data);169 procedure CallClient(bix, Command: Integer; var Data); 170 170 begin 171 171 if ((Mode <> moMovie) or (bix = Brains.IndexOf(GameServer.bix[0]))) then … … 174 174 HandoverStack[nHandoverStack] := bix; 175 175 HandoverStack[nHandoverStack + 1] := Command; 176 inc(nHandoverStack, 2);176 Inc(nHandoverStack, 2); 177 177 Brains[bix].Client(Command, -1, Data); 178 dec(nHandoverStack, 2);178 Dec(nHandoverStack, 2); 179 179 {$ELSE} 180 180 try … … 189 189 procedure Init(NotifyFunction: TNotifyFunction); 190 190 var 191 f: TSearchRec;191 F: TSearchRec; 192 192 BasePath: string; 193 193 NewBrain: TBrain; … … 195 195 begin 196 196 Notify := NotifyFunction; 197 PreviewElevation := false;197 PreviewElevation := False; 198 198 PlayersBrain := TBrains.Create(False); 199 199 PlayersBrain.Count := nPl; … … 246 246 end; 247 247 248 if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then248 if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, F) = 0 then 249 249 repeat 250 BasePath := GetAiDir + DirectorySeparator + f.Name;251 if ( f.Name <> '.') and (f.Name <> '..') and DirectoryExists(BasePath) then begin250 BasePath := GetAiDir + DirectorySeparator + F.Name; 251 if (F.Name <> '.') and (F.Name <> '..') and DirectoryExists(BasePath) then begin 252 252 NewBrain := Brains.AddNew; 253 253 NewBrain.Kind := btAI; … … 258 258 end else Brains.Delete(Brains.Count - 1); 259 259 end; 260 until FindNext( f) <> 0;260 until FindNext(F) <> 0; 261 261 FindClose(F); 262 262 … … 281 281 end; 282 282 283 function PreviewMap(lm: integer): pointer;283 function PreviewMap(lm: Integer): Pointer; 284 284 begin 285 285 lx := lxmax; … … 291 291 begin 292 292 CreateElevation; 293 PreviewElevation := true;293 PreviewElevation := True; 294 294 end; 295 CreateMap( true);295 CreateMap(True); 296 296 Result := @RealMap; 297 297 end; 298 298 299 procedure ChangeClientWhenDone(Command, Player: integer; var Data;300 DataSize: integer);299 procedure ChangeClientWhenDone(Command, Player: Integer; var Data; 300 DataSize: Integer); 301 301 begin 302 302 CCCommand := Command; 303 303 CCPlayer := Player; 304 304 if DataSize > 0 then 305 move(Data, CCData, DataSize);305 Move(Data, CCData, DataSize); 306 306 Notify(ntChangeClient); 307 307 end; 308 308 309 procedure PutMessage(Level: integer; Text: string);309 procedure PutMessage(Level: Integer; Text: string); 310 310 begin 311 bix[0].Client(cDebugMessage, Level, pchar(Text)^);311 bix[0].Client(cDebugMessage, Level, PChar(Text)^); 312 312 end; 313 313 … … 336 336 // hand over control to other client (as specified by CC...) 337 337 var 338 p: integer;338 P: Integer; 339 339 T: TDateTime; 340 340 begin … … 346 346 [CCPlayer, bix[CCPlayer].Name])); 347 347 if CCCommand = cTurn then 348 for p:= 0 to nPl - 1 do349 if ( p <> CCPlayer) and (1 shl pand GWatching <> 0) then350 CallPlayer(cShowTurnChange, p, CCPlayer);351 352 p:= CCPlayer;348 for P := 0 to nPl - 1 do 349 if (P <> CCPlayer) and (1 shl P and GWatching <> 0) then 350 CallPlayer(cShowTurnChange, P, CCPlayer); 351 352 P := CCPlayer; 353 353 CCPlayer := -1; 354 CallPlayer(CCCommand, p, CCData);355 if (Mode = moPlaying) and (bix[ p].Flags and aiThreaded = 0) and354 CallPlayer(CCCommand, P, CCData); 355 if (Mode = moPlaying) and (bix[P].Flags and aiThreaded = 0) and 356 356 (CCPlayer < 0) then 357 357 begin 358 Notify(ntDeactivationMissing, p);358 Notify(ntDeactivationMissing, P); 359 359 ForceClientDeactivation; 360 360 end; 361 361 end; 362 362 363 procedure Inform( p: integer);363 procedure Inform(P: Integer); 364 364 var 365 i, p1: integer;365 I, p1: Integer; 366 366 begin 367 RW[ p].Turn := GTurn;368 if (GTurn = MaxTurn) and ( p = pTurn) and (p= 0) then369 RW[ p].Happened := RW[p].Happened or phTimeUp;370 if (GWinner > 0) and ( p = pTurn) and (p= 0) then371 RW[ p].Happened := RW[p].Happened or phShipComplete;372 RW[ p].Alive := GAlive;373 move(GWonder, RW[p].Wonder, SizeOf(GWonder));374 move(GShip, RW[p].Ship, SizeOf(GShip));367 RW[P].Turn := GTurn; 368 if (GTurn = MaxTurn) and (P = pTurn) and (P = 0) then 369 RW[P].Happened := RW[P].Happened or phTimeUp; 370 if (GWinner > 0) and (P = pTurn) and (P = 0) then 371 RW[P].Happened := RW[P].Happened or phShipComplete; 372 RW[P].Alive := GAlive; 373 Move(GWonder, RW[P].Wonder, SizeOf(GWonder)); 374 Move(GShip, RW[P].Ship, SizeOf(GShip)); 375 375 for p1 := 0 to nPl - 1 do 376 if (p1 <> p) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then377 RW[ p].EnemyReport[p1].Credibility := RW[p1].Credibility;376 if (p1 <> P) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then 377 RW[P].EnemyReport[p1].Credibility := RW[p1].Credibility; 378 378 for p1 := 0 to nPl - 1 do 379 if (p1 <> p) and (1 shl p1 and GAlive <> 0) then379 if (p1 <> P) and (1 shl p1 and GAlive <> 0) then 380 380 begin 381 if (GTestFlags and tfUncover <> 0) or (Difficulty[ p] = 0) or382 (RW[ p].Treaty[p1] >= trFriendlyContact) then383 GiveCivilReport( p, p1);384 if (GTestFlags and tfUncover <> 0) or (Difficulty[ p] = 0) or385 (RW[ p].Treaty[p1] = trAlliance) then386 GiveMilReport( p, p1)381 if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or 382 (RW[P].Treaty[p1] >= trFriendlyContact) then 383 GiveCivilReport(P, p1); 384 if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or 385 (RW[P].Treaty[p1] = trAlliance) then 386 GiveMilReport(P, p1) 387 387 end; 388 for i := 0 to RW[p].nEnemyModel - 1 do389 with RW[ p].EnemyModel[i] do390 Lost := Destroyed[ p, Owner, mix];388 for I := 0 to RW[P].nEnemyModel - 1 do 389 with RW[P].EnemyModel[I] do 390 Lost := Destroyed[P, Owner, mix]; 391 391 end; 392 392 393 393 procedure LogChanges; 394 394 var 395 p, ix: integer;395 P, ix: Integer; 396 396 begin 397 for p:= 0 to nPl - 1 do398 if (1 shl p and GWatching <> 0) and ProcessClientData[p] then397 for P := 0 to nPl - 1 do 398 if (1 shl P and GWatching <> 0) and ProcessClientData[P] then 399 399 begin 400 400 // log unit status changes 401 for ix := 0 to RW[ p].nUn - 1 do402 with RW[ p].Un[ix] do401 for ix := 0 to RW[P].nUn - 1 do 402 with RW[P].Un[ix] do 403 403 if (Loc >= 0) and (SavedStatus <> Status) then 404 404 begin 405 CL.Put(sIntSetUnitStatus, p, ix, @Status);405 CL.Put(sIntSetUnitStatus, P, ix, @Status); 406 406 SavedStatus := Status; 407 407 end; 408 408 // log city status changes 409 for ix := 0 to RW[ p].nCity - 1 do410 with RW[ p].City[ix] do409 for ix := 0 to RW[P].nCity - 1 do 410 with RW[P].City[ix] do 411 411 if (Loc >= 0) and (SavedStatus <> Status) then 412 412 begin 413 CL.Put(sIntSetCityStatus, p, ix, @Status);413 CL.Put(sIntSetCityStatus, P, ix, @Status); 414 414 SavedStatus := Status; 415 415 end; 416 416 // log model status changes 417 for ix := 0 to RW[ p].nModel - 1 do418 with RW[ p].Model[ix] do417 for ix := 0 to RW[P].nModel - 1 do 418 with RW[P].Model[ix] do 419 419 if SavedStatus <> Status then 420 420 begin 421 CL.Put(sIntSetModelStatus, p, ix, @Status);421 CL.Put(sIntSetModelStatus, P, ix, @Status); 422 422 SavedStatus := Status; 423 423 end; 424 424 // log enemy city status changes 425 for ix := 0 to RW[ p].nEnemyCity - 1 do426 with RW[ p].EnemyCity[ix] do425 for ix := 0 to RW[P].nEnemyCity - 1 do 426 with RW[P].EnemyCity[ix] do 427 427 if (Loc >= 0) and (SavedStatus <> Status) then 428 428 begin 429 CL.Put(sIntSetECityStatus, p, ix, @Status);429 CL.Put(sIntSetECityStatus, P, ix, @Status); 430 430 SavedStatus := Status; 431 431 end; 432 432 // log data changes 433 if bix[ p].DataSize > 0 then434 begin 435 CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data,436 bix[ p].DataSize);437 Move(RW[ p].Data^, SavedData[p]^, bix[p].DataSize * 4);433 if bix[P].DataSize > 0 then 434 begin 435 CL.PutDataChanges(sIntDataChange, P, SavedData[P], RW[P].Data, 436 bix[P].DataSize); 437 Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4); 438 438 end; 439 439 end; … … 442 442 procedure NoLogChanges; 443 443 var 444 p, ix: integer;444 P, ix: Integer; 445 445 begin 446 for p:= 0 to nPl - 1 do447 if (1 shl p and GWatching <> 0) and ProcessClientData[p] then446 for P := 0 to nPl - 1 do 447 if (1 shl P and GWatching <> 0) and ProcessClientData[P] then 448 448 begin 449 for ix := 0 to RW[ p].nUn - 1 do450 with RW[ p].Un[ix] do449 for ix := 0 to RW[P].nUn - 1 do 450 with RW[P].Un[ix] do 451 451 SavedStatus := Status; 452 for ix := 0 to RW[ p].nCity - 1 do453 with RW[ p].City[ix] do452 for ix := 0 to RW[P].nCity - 1 do 453 with RW[P].City[ix] do 454 454 SavedStatus := Status; 455 for ix := 0 to RW[ p].nModel - 1 do456 with RW[ p].Model[ix] do455 for ix := 0 to RW[P].nModel - 1 do 456 with RW[P].Model[ix] do 457 457 SavedStatus := Status; 458 for ix := 0 to RW[ p].nEnemyCity - 1 do459 with RW[ p].EnemyCity[ix] do458 for ix := 0 to RW[P].nEnemyCity - 1 do 459 with RW[P].EnemyCity[ix] do 460 460 SavedStatus := Status; 461 if bix[ p].DataSize > 0 then462 Move(RW[ p].Data^, SavedData[p]^, bix[p].DataSize * 4);461 if bix[P].DataSize > 0 then 462 Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4); 463 463 end; 464 464 end; 465 465 466 function HasChanges( p: integer): boolean;466 function HasChanges(P: Integer): Boolean; 467 467 type 468 468 TDWordList = array [0 .. INFIN] of Cardinal; 469 469 PDWortList = ^TDWordList; 470 470 var 471 ix: integer;471 ix: Integer; 472 472 begin 473 473 Result := False; 474 for ix := 0 to RW[ p].nUn - 1 do475 with RW[ p].Un[ix] do474 for ix := 0 to RW[P].nUn - 1 do 475 with RW[P].Un[ix] do 476 476 if (Loc >= 0) and (SavedStatus <> Status) then 477 477 Result := True; 478 for ix := 0 to RW[ p].nCity - 1 do479 with RW[ p].City[ix] do478 for ix := 0 to RW[P].nCity - 1 do 479 with RW[P].City[ix] do 480 480 if (Loc >= 0) and (SavedStatus <> Status) then 481 481 Result := True; 482 for ix := 0 to RW[ p].nModel - 1 do483 with RW[ p].Model[ix] do482 for ix := 0 to RW[P].nModel - 1 do 483 with RW[P].Model[ix] do 484 484 if SavedStatus <> Status then 485 485 Result := True; 486 for ix := 0 to RW[ p].nEnemyCity - 1 do487 with RW[ p].EnemyCity[ix] do486 for ix := 0 to RW[P].nEnemyCity - 1 do 487 with RW[P].EnemyCity[ix] do 488 488 if (Loc >= 0) and (SavedStatus <> Status) then 489 489 Result := True; 490 if RW[ p].Data <> nil then491 for ix := 0 to bix[ p].DataSize - 1 do492 if PDWortList(SavedData[ p])[ix] <> PDWortList(RW[p].Data)[ix] then490 if RW[P].Data <> nil then 491 for ix := 0 to bix[P].DataSize - 1 do 492 if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then 493 493 Result := True; 494 494 end; … … 498 498 InitModuleData: TInitModuleData; 499 499 begin 500 assert(bix.Kind <> btSuperVirtual);500 Assert(bix.Kind <> btSuperVirtual); 501 501 with bix do begin 502 502 if Initialized then 503 exit;503 Exit; 504 504 if Kind = btAI then 505 505 begin { get client function } … … 509 509 else 510 510 begin 511 hm := LoadLibrary( pchar(DLLName));511 hm := LoadLibrary(PChar(DLLName)); 512 512 if hm = 0 then 513 513 begin … … 525 525 if @Client <> nil then 526 526 begin 527 Initialized := true;527 Initialized := True; 528 528 InitModuleData.Server := @Server; 529 529 InitModuleData.DataVersion := 0; … … 542 542 procedure SaveMap(FileName: string); 543 543 var 544 i: integer;544 I: Integer; 545 545 MapFile: TFileStream; 546 s: string[255];546 S: string[255]; 547 547 begin 548 548 MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName, … … 550 550 try 551 551 MapFile.Position := 0; 552 s:= 'cEvoMap'#0;553 MapFile. write(s[1], 8); { file id }554 i:= 0;555 MapFile. write(i, 4); { format id }556 MapFile. write(MaxTurn, 4);557 MapFile. write(lx, 4);558 MapFile. write(ly, 4);559 MapFile. write(RealMap, MapSize * 4);552 S := 'cEvoMap'#0; 553 MapFile.Write(S[1], 8); { file id } 554 I := 0; 555 MapFile.Write(I, 4); { format id } 556 MapFile.Write(MaxTurn, 4); 557 MapFile.Write(lx, 4); 558 MapFile.Write(ly, 4); 559 MapFile.Write(RealMap, MapSize * 4); 560 560 finally 561 561 FreeAndNil(MapFile); … … 563 563 end; 564 564 565 function LoadMap(FileName: string): boolean;565 function LoadMap(FileName: string): Boolean; 566 566 var 567 i, Loc1: integer;567 I, Loc1: Integer; 568 568 MapFile: TFileStream; 569 s: string[255];569 S: string[255]; 570 570 begin 571 result := false;571 Result := False; 572 572 MapFile := nil; 573 573 try 574 574 MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive); 575 575 MapFile.Position := 0; 576 MapFile. read(s[1], 8); { file id }577 MapFile. read(i, 4); { format id }578 if i= 0 then576 MapFile.Read(S[1], 8); { file id } 577 MapFile.Read(I, 4); { format id } 578 if I = 0 then 579 579 begin 580 MapFile. read(i, 4); // MaxTurn581 MapFile. read(lx, 4);582 MapFile. read(ly, 4);580 MapFile.Read(I, 4); // MaxTurn 581 MapFile.Read(lx, 4); 582 MapFile.Read(ly, 4); 583 583 ly := ly and not 1; 584 584 if lx > lxmax then … … 587 587 ly := lymax; 588 588 MapSize := lx * ly; 589 MapFile. read(RealMap, MapSize * 4);589 MapFile.Read(RealMap, MapSize * 4); 590 590 for Loc1 := 0 to MapSize - 1 do 591 591 begin … … 600 600 or fDesert; 601 601 end; 602 result := true;602 Result := True; 603 603 end; 604 604 FreeAndNil(MapFile); … … 609 609 end; 610 610 611 procedure SaveGame(FileName: string; auto: boolean);611 procedure SaveGame(FileName: string; Auto: Boolean); 612 612 var 613 x, y, i, zero, Tile, nLocal: integer;613 X, Y, I, zero, Tile, nLocal: Integer; 614 614 LogFile: TFileStream; 615 s: string[255];615 S: string[255]; 616 616 SaveMap: array [0 .. lxmax * lymax - 1] of Byte; 617 617 begin 618 618 nLocal := 0; 619 for i:= 0 to nPl - 1 do620 if Assigned(bix[ i]) and (bix[i].Kind = btTerm) then621 inc(nLocal);619 for I := 0 to nPl - 1 do 620 if Assigned(bix[I]) and (bix[I].Kind = btTerm) then 621 Inc(nLocal); 622 622 if Difficulty[0] = 0 then 623 623 nLocal := 0; 624 624 if nLocal <= 1 then 625 for y:= 0 to ly - 1 do626 for x:= 0 to lx - 1 do627 begin 628 Tile := RW[0].Map[( x + SaveMapCenterLoc + lx shr 1) mod lx + lx * y];629 SaveMap[ x + lx * y] := Tile and fTerrain + Tile and625 for Y := 0 to ly - 1 do 626 for X := 0 to lx - 1 do 627 begin 628 Tile := RW[0].Map[(X + SaveMapCenterLoc + lx shr 1) mod lx + lx * Y]; 629 SaveMap[X + lx * Y] := Tile and fTerrain + Tile and 630 630 (fCity or fUnit or fOwned) shr 16; 631 631 end; 632 632 633 if auto and AutoSaveExists then // append to existing file633 if Auto and AutoSaveExists then // append to existing file 634 634 LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or 635 635 fmShareExclusive) … … 640 640 zero := 0; 641 641 LogFile.Position := 0; 642 s:= 'cEvoBook';643 LogFile. write(s[1], 8); { file id }644 i:= CevoVersion;645 LogFile. write(i, 4); { c-evo version }646 LogFile. write(ExeInfo.Time, 4);647 LogFile. write(lx, 4);648 LogFile. write(ly, 4);649 LogFile. write(LandMass, 4);642 S := 'cEvoBook'; 643 LogFile.Write(S[1], 8); { file id } 644 I := CevoVersion; 645 LogFile.Write(I, 4); { c-evo version } 646 LogFile.Write(ExeInfo.Time, 4); 647 LogFile.Write(lx, 4); 648 LogFile.Write(ly, 4); 649 LogFile.Write(LandMass, 4); 650 650 if LandMass = 0 then 651 LogFile. write(MapField^, MapSize * 4);652 653 LogFile. write(MaxTurn, 4);654 LogFile. write(RND, 4);655 LogFile. write(GTurn, 4);651 LogFile.Write(MapField^, MapSize * 4); 652 653 LogFile.Write(MaxTurn, 4); 654 LogFile.Write(RND, 4); 655 LogFile.Write(GTurn, 4); 656 656 if nLocal > 1 then // multiplayer game -- no quick view 657 657 begin 658 i:= $80;659 LogFile. write(i, 4);658 I := $80; 659 LogFile.Write(I, 4); 660 660 end 661 661 else 662 LogFile. write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);663 for i:= 0 to nPl - 1 do664 if not Assigned(bix[ i]) then665 LogFile. write(zero, 4)662 LogFile.Write(SaveMap, ((MapSize - 1) div 4 + 1) * 4); 663 for I := 0 to nPl - 1 do 664 if not Assigned(bix[I]) then 665 LogFile.Write(zero, 4) 666 666 else 667 667 begin 668 if PlayersBrain[ i].Kind in [btRandom, btAI] then669 s := bix[i].FileName670 else 671 s := PlayersBrain[i].FileName;672 move(zero, s[Length(s) + 1], 4);673 LogFile. write(s, (Length(s) div 4 + 1) * 4);674 LogFile. write(OriginalDataVersion[i], 4);675 s:= ''; { behavior }676 move(zero, s[Length(s) + 1], 4);677 LogFile. write(s, (Length(s) div 4 + 1) * 4);678 LogFile. write(Difficulty[i], 4);668 if PlayersBrain[I].Kind in [btRandom, btAI] then 669 S := bix[I].FileName 670 else 671 S := PlayersBrain[I].FileName; 672 Move(zero, S[Length(S) + 1], 4); 673 LogFile.Write(S, (Length(S) div 4 + 1) * 4); 674 LogFile.Write(OriginalDataVersion[I], 4); 675 S := ''; { behavior } 676 Move(zero, S[Length(S) + 1], 4); 677 LogFile.Write(S, (Length(S) div 4 + 1) * 4); 678 LogFile.Write(Difficulty[I], 4); 679 679 end; 680 680 681 if auto and AutoSaveExists then681 if Auto and AutoSaveExists then 682 682 CL.AppendToFile(LogFile, AutoSaveState) 683 683 else 684 684 CL.SaveToFile(LogFile); 685 685 FreeAndNil(LogFile); 686 if auto then686 if Auto then 687 687 begin 688 688 AutoSaveState := CL.State; 689 AutoSaveExists := true;689 AutoSaveExists := True; 690 690 end 691 691 end; … … 693 693 procedure StartGame; 694 694 var 695 i, p, p1, Human, nAlive, bixUni: integer;695 I, P, p1, Human, nAlive, bixUni: Integer; 696 696 Game: TNewGameData; 697 697 // GameEx: TNewGameExData; … … 722 722 723 723 BrainUsed := []; 724 for p:= 0 to nPl - 1 do725 if Assigned(bix[ p]) and ((Mode <> moMovie) or (p= 0)) then724 for P := 0 to nPl - 1 do 725 if Assigned(bix[P]) and ((Mode <> moMovie) or (P = 0)) then 726 726 begin { initiate selected control module } 727 AIInfo[ p] := bix[p].Name + #0;728 InitBrain(bix[ p]);727 AIInfo[P] := bix[P].Name + #0; 728 InitBrain(bix[P]); 729 729 if Mode = moPlaying then 730 730 begin // new game, this data version is original 731 OriginalDataVersion[ p] := bix[p].DataVersion;732 ProcessClientData[ p] := true;731 OriginalDataVersion[P] := bix[P].DataVersion; 732 ProcessClientData[P] := True; 733 733 end 734 734 else // loading game, compare with data version read from file 735 ProcessClientData[ p] := ProcessClientData[p] and736 (OriginalDataVersion[ p] = bix[p].DataVersion);737 if @bix[ p].Client = nil then // client function not found735 ProcessClientData[P] := ProcessClientData[P] and 736 (OriginalDataVersion[P] = bix[P].DataVersion); 737 if @bix[P].Client = nil then // client function not found 738 738 if bix[0].Kind = btNoTerm then 739 bix[ p] := nil739 bix[P] := nil 740 740 else 741 741 begin 742 bix[ p] := BrainTerm;743 OriginalDataVersion[ p] := -1;744 ProcessClientData[ p] := false;742 bix[P] := BrainTerm; 743 OriginalDataVersion[P] := -1; 744 ProcessClientData[P] := False; 745 745 end; 746 if Assigned(bix[ p]) then747 include(BrainUsed, Brains.IndexOf(bix[p]));746 if Assigned(bix[P]) then 747 Include(BrainUsed, Brains.IndexOf(bix[P])); 748 748 end; 749 749 … … 760 760 begin 761 761 if Mode <> moMovie then 762 inc(GWatching, 1 shl p1);762 Inc(GWatching, 1 shl p1); 763 763 if bix[p1].Kind = btAI then 764 inc(GAI, 1 shl p1);764 Inc(GAI, 1 shl p1); 765 765 if Difficulty[p1] > 0 then 766 766 begin 767 inc(GAlive, 1 shl p1);768 inc(nAlive);767 Inc(GAlive, 1 shl p1); 768 Inc(nAlive); 769 769 end; 770 770 ServerVersion[p1] := bix[p1].ServerVersion; … … 779 779 780 780 GTurn := 0; 781 for i:= 0 to nWonder - 1 do782 with GWonder[ i] do781 for I := 0 to nWonder - 1 do 782 with GWonder[I] do 783 783 begin 784 784 CityID := -1; … … 787 787 FillChar(GShip, SizeOf(GShip), 0); 788 788 789 for p:= 0 to nPl - 1 do790 if 1 shl pand (GAlive or GWatching) <> 0 then791 with RW[ p] do789 for P := 0 to nPl - 1 do 790 if 1 shl P and (GAlive or GWatching) <> 0 then 791 with RW[P] do 792 792 begin 793 793 Government := gDespotism; … … 799 799 AnarchyStart := -AnarchyTurns - 1; 800 800 Happened := 0; 801 LastValidStat[ p] := -1;802 Worked[ p] := 0;803 Founded[ p] := 0;804 DevModelTurn[ p] := -1;801 LastValidStat[P] := -1; 802 Worked[P] := 0; 803 Founded[P] := 0; 804 DevModelTurn[P] := -1; 805 805 OracleIncome := 0; 806 806 807 if bix[ p].DataSize > 0 then807 if bix[P].DataSize > 0 then 808 808 begin 809 GetMem(SavedData[ p], bix[p].DataSize * 4);810 GetMem(Data, bix[ p].DataSize * 4);811 FillChar(SavedData[ p]^, bix[p].DataSize * 4, 0);812 FillChar(Data^, bix[ p].DataSize * 4, 0);809 GetMem(SavedData[P], bix[P].DataSize * 4); 810 GetMem(Data, bix[P].DataSize * 4); 811 FillChar(SavedData[P]^, bix[P].DataSize * 4, 0); 812 FillChar(Data^, bix[P].DataSize * 4, 0); 813 813 end 814 814 else 815 815 begin 816 816 Data := nil; 817 SavedData[ p] := nil817 SavedData[P] := nil; 818 818 end; 819 819 nBattleHistory := 0; … … 825 825 end 826 826 else } BorderHelper := nil; 827 for i:= 0 to nStat - 1 do828 GetMem(Stat[ i, p], 4 * (MaxTurn + 1));829 if bix[ p].Flags and fDotNet <> 0 then827 for I := 0 to nStat - 1 do 828 GetMem(Stat[I, P], 4 * (MaxTurn + 1)); 829 if bix[P].Flags and fDotNet <> 0 then 830 830 begin 831 GetMem(RW[ p].DefaultDebugMap, MapSize * 4);832 FillChar(RW[ p].DefaultDebugMap^, MapSize * 4, 0);833 DebugMap[ p] := RW[p].DefaultDebugMap;831 GetMem(RW[P].DefaultDebugMap, MapSize * 4); 832 FillChar(RW[P].DefaultDebugMap^, MapSize * 4, 0); 833 DebugMap[P] := RW[P].DefaultDebugMap; 834 834 end 835 835 else 836 RW[ p].DefaultDebugMap := nil;837 838 { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); {}836 RW[P].DefaultDebugMap := nil; 837 838 { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); } 839 839 end; 840 840 … … 842 842 begin // random map 843 843 InitRandomGame; 844 PreviewElevation := false;844 PreviewElevation := False; 845 845 MapField := nil; 846 846 end … … 850 850 LoadMap(MapFileName); // new game -- load map from file 851 851 GetMem(MapField, MapSize * 4); 852 move(RealMap, MapField^, MapSize * 4);852 Move(RealMap, MapField^, MapSize * 4); 853 853 Human := 0; 854 854 for p1 := 0 to nPl - 1 do 855 855 if Assigned(bix[p1]) and (bix[p1].Kind = btTerm) then 856 inc(Human, 1 shl p1);856 Inc(Human, 1 shl p1); 857 857 InitMapGame(Human); 858 858 end; 859 859 CityProcessing.InitGame; 860 860 UnitProcessing.InitGame; 861 for p:= 0 to nPl - 1 do862 if 1 shl pand (GAlive or GWatching) <> 0 then863 Inform( p);861 for P := 0 to nPl - 1 do 862 if 1 shl P and (GAlive or GWatching) <> 0 then 863 Inform(P); 864 864 865 865 pTurn := -1; … … 870 870 Game.LandMass := LandMass; 871 871 Game.MaxTurn := MaxTurn; 872 move(Difficulty, Game.Difficulty, SizeOf(Difficulty));872 Move(Difficulty, Game.Difficulty, SizeOf(Difficulty)); 873 873 // GameEx.lx:=lx; GameEx.ly:=ly; GameEx.LandMass:=LandMass; 874 874 // GameEx.MaxTurn:=MaxTurn; GameEx.RND:=RND; 875 875 // move(Difficulty,GameEx.Difficulty,SizeOf(Difficulty)); 876 876 AICredits := ''; 877 for i:= 0 to Brains.Count - 1 do877 for I := 0 to Brains.Count - 1 do 878 878 with Brains[I] do begin 879 879 if Initialized then 880 if iin BrainUsed then880 if I in BrainUsed then 881 881 begin 882 882 if Kind = btAI then 883 883 Notify(ntInitPlayers); 884 for p:= 0 to nPl - 1 do884 for P := 0 to nPl - 1 do 885 885 begin 886 if Brains.IndexOf(bix[ p]) = ithen887 Game.RO[ p] := @RW[p]886 if Brains.IndexOf(bix[P]) = I then 887 Game.RO[P] := @RW[P] 888 888 else 889 Game.RO[ p] := nil;890 if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[ p]) then891 Game.SuperVisorRO[ p] := @RW[p]889 Game.RO[P] := nil; 890 if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[P]) then 891 Game.SuperVisorRO[P] := @RW[P] 892 892 else 893 Game.SuperVisorRO[ p] := nil;893 Game.SuperVisorRO[P] := nil; 894 894 end; 895 895 if Flags and fDotNet > 0 then 896 896 begin 897 897 Path := DLLName; 898 move(Path[1], Game.AssemblyPath, Length(Path));898 Move(Path[1], Game.AssemblyPath, Length(Path)); 899 899 Game.AssemblyPath[Length(Path)] := #0; 900 900 end … … 903 903 case Mode of 904 904 moLoading, moLoading_Fast: 905 CallClient( i, cLoadGame, Game);905 CallClient(I, cLoadGame, Game); 906 906 moMovie: 907 CallClient( i, cMovie, Game);907 CallClient(I, cMovie, Game); 908 908 moPlaying: 909 CallClient( i, cNewGame, Game);909 CallClient(I, cNewGame, Game); 910 910 end; 911 911 if (Kind = btAI) and (Credits <> '') then … … 917 917 else 918 918 begin { module no longer used -- unload } 919 CallClient( i, cReleaseModule, nil^);919 CallClient(I, cReleaseModule, nil^); 920 920 if Kind = btAI then 921 921 begin … … 924 924 Client := nil; 925 925 end; 926 Initialized := false;926 Initialized := False; 927 927 end; 928 928 end; … … 952 952 CheckBorders(-1); 953 953 {$IFOPT O-}InvalidTreatyMap := 0; {$ENDIF} 954 AutoSaveExists := false;954 AutoSaveExists := False; 955 955 pDipActive := -1; 956 956 pTurn := 0; … … 958 958 if Mode >= moMovie then 959 959 Notify(ntEndInfo); 960 end; { StartGame }960 end; 961 961 962 962 procedure EndGame; 963 963 var 964 i, p1: integer;964 I, p1: Integer; 965 965 begin 966 966 if LandMass = 0 then … … 969 969 if Assigned(bix[p1]) then 970 970 begin 971 for i:= 0 to nStat - 1 do972 FreeMem(Stat[ i, p1]);971 for I := 0 to nStat - 1 do 972 FreeMem(Stat[I, p1]); 973 973 if RW[p1].BattleHistory <> nil then 974 974 FreeMem(RW[p1].BattleHistory); … … 985 985 end; 986 986 987 procedure GenerateStat( p: integer);987 procedure GenerateStat(P: Integer); 988 988 var 989 cix, uix: integer;989 cix, uix: Integer; 990 990 begin 991 if Difficulty[ p] > 0 then992 with RW[ p] do991 if Difficulty[P] > 0 then 992 with RW[P] do 993 993 begin 994 Stat[stPop, p, GTurn] := 0;994 Stat[stPop, P, GTurn] := 0; 995 995 for cix := 0 to nCity - 1 do 996 996 if City[cix].Loc >= 0 then 997 inc(Stat[stPop, p, GTurn], City[cix].Size);998 Stat[stScience, p, GTurn] := Researched[p] * 50;999 if (RW[ p].ResearchTech >= 0) and (RW[p].ResearchTech <> adMilitary) then1000 inc(Stat[stScience, p, GTurn], Research * 100 div TechBaseCost(nTech[p],1001 Difficulty[ p]));1002 Stat[stMil, p, GTurn] := 0;997 Inc(Stat[stPop, P, GTurn], City[cix].Size); 998 Stat[stScience, P, GTurn] := Researched[P] * 50; 999 if (RW[P].ResearchTech >= 0) and (RW[P].ResearchTech <> adMilitary) then 1000 Inc(Stat[stScience, P, GTurn], Research * 100 div TechBaseCost(nTech[P], 1001 Difficulty[P])); 1002 Stat[stMil, P, GTurn] := 0; 1003 1003 for uix := 0 to nUn - 1 do 1004 1004 if Un[uix].Loc >= 0 then … … 1006 1006 begin 1007 1007 if (Kind <= mkEnemyDeveloped) and (Un[uix].mix <> 1) then 1008 inc(Stat[stMil, p, GTurn], Weight * MStrength *1008 Inc(Stat[stMil, P, GTurn], Weight * MStrength * 1009 1009 Un[uix].Health div 100) 1010 1010 else if Domain = dGround then 1011 inc(Stat[stMil, p, GTurn], (Attack + 2 * Defense) *1011 Inc(Stat[stMil, P, GTurn], (Attack + 2 * Defense) * 1012 1012 Un[uix].Health div 100) 1013 1013 else 1014 inc(Stat[stMil, p, GTurn], (Attack + Defense) *1014 Inc(Stat[stMil, P, GTurn], (Attack + Defense) * 1015 1015 Un[uix].Health div 100); 1016 1016 case Kind of 1017 1017 mkSlaves: 1018 inc(Stat[stPop, p, GTurn]);1018 Inc(Stat[stPop, P, GTurn]); 1019 1019 mkSettler: 1020 inc(Stat[stPop, p, GTurn], 2);1020 Inc(Stat[stPop, P, GTurn], 2); 1021 1021 end; 1022 1022 end; 1023 Stat[stMil, p, GTurn] := Stat[stMil, p, GTurn] div 16;1024 Stat[stExplore, p, GTurn] := Discovered[p];1025 Stat[stTerritory, p, GTurn] := TerritoryCount[p];1026 Stat[stWork, p, GTurn] := Worked[p];1027 LastValidStat[ p] := GTurn;1023 Stat[stMil, P, GTurn] := Stat[stMil, P, GTurn] div 16; 1024 Stat[stExplore, P, GTurn] := Discovered[P]; 1025 Stat[stTerritory, P, GTurn] := TerritoryCount[P]; 1026 Stat[stWork, P, GTurn] := Worked[P]; 1027 LastValidStat[P] := GTurn; 1028 1028 end; 1029 1029 end; … … 1031 1031 procedure LogCityTileChanges; 1032 1032 var 1033 cix: integer;1033 cix: Integer; 1034 1034 begin 1035 1035 for cix := 0 to RW[pTurn].nCity - 1 do … … 1052 1052 procedure NoLogCityTileChanges; 1053 1053 var 1054 cix: integer;1054 cix: Integer; 1055 1055 begin 1056 1056 for cix := 0 to RW[pTurn].nCity - 1 do … … 1063 1063 end; 1064 1064 1065 function HasCityTileChanges: boolean;1065 function HasCityTileChanges: Boolean; 1066 1066 var 1067 cix: integer;1067 cix: Integer; 1068 1068 begin 1069 result := false;1069 Result := False; 1070 1070 for cix := 0 to RW[pTurn].nCity - 1 do 1071 1071 with RW[pTurn].City[cix] do … … 1074 1074 // if SavedResourceWeights[cix]<>ResourceWeights then result:=true; 1075 1075 if SavedTiles[cix] <> Tiles then 1076 result := true;1076 Result := True; 1077 1077 end; 1078 1078 end; … … 1080 1080 procedure BeforeTurn0; 1081 1081 var 1082 p1, uix: integer;1082 p1, uix: Integer; 1083 1083 begin 1084 1084 for uix := 0 to RW[pTurn].nUn - 1 do { init movement points for first turn } … … 1101 1101 end; 1102 1102 1103 function LoadGame(const Path, FileName: string; Turn: integer;1104 MovieMode: boolean): boolean;1103 function LoadGame(const Path, FileName: string; Turn: Integer; 1104 MovieMode: Boolean): Boolean; 1105 1105 var 1106 1106 J: TBrain; 1107 i, ix, d, p1, Command, Subject: integer;1107 I, ix, D, p1, Command, Subject: Integer; 1108 1108 K: Integer; 1109 {$IFDEF TEXTLOG}LoadPos0: integer; {$ENDIF}1110 Data: pointer;1109 {$IFDEF TEXTLOG}LoadPos0: Integer; {$ENDIF} 1110 Data: Pointer; 1111 1111 LogFile: TFileStream; 1112 1112 FormerCLState: TCmdListState; 1113 s: string[255];1113 S: string[255]; 1114 1114 SaveMap: array [0 .. lxmax * lymax - 1] of Byte; 1115 Started, StatRequest: boolean;1115 Started, StatRequest: Boolean; 1116 1116 begin 1117 1117 SavePath := Path; … … 1121 1121 fmShareExclusive); 1122 1122 LogFile.Position := 0; 1123 LogFile.Read( s[1], 8); { file id }1124 LogFile.Read( i, 4); { c-evo version }1123 LogFile.Read(S[1], 8); { file id } 1124 LogFile.Read(I, 4); { c-evo version } 1125 1125 LogFile.Read(J, 4); { exe time } 1126 1126 1127 if ( i >= FirstBookCompatibleVersion) and (i<= CevoVersion) then1127 if (I >= FirstBookCompatibleVersion) and (I <= CevoVersion) then 1128 1128 begin 1129 result := true;1129 Result := True; 1130 1130 LogFile.Read(lx, 4); 1131 1131 LogFile.Read(ly, 4); … … 1139 1139 LogFile.Read(SaveMap, 4); 1140 1140 if SaveMap[0] <> $80 then 1141 LogFile. read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);1141 LogFile.Read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4); 1142 1142 for p1 := 0 to nPl - 1 do 1143 1143 begin 1144 LogFile.Read( s[0], 4);1145 if s[0] = #0 then1144 LogFile.Read(S[0], 4); 1145 if S[0] = #0 then 1146 1146 PlayersBrain[p1] := nil 1147 1147 else 1148 1148 begin 1149 LogFile.Read( s[4], Byte(s[0]) div 4 * 4);1149 LogFile.Read(S[4], Byte(S[0]) div 4 * 4); 1150 1150 LogFile.Read(OriginalDataVersion[p1], 4); 1151 LogFile.Read( d, 4); { behavior }1151 LogFile.Read(D, 4); { behavior } 1152 1152 LogFile.Read(Difficulty[p1], 4); 1153 1153 J := Brains.Last; 1154 while Assigned(J) and (AnsiCompareFileName(J.FileName, s) <> 0) do begin1154 while Assigned(J) and (AnsiCompareFileName(J.FileName, S) <> 0) do begin 1155 1155 K := Brains.IndexOf(J) - 1; 1156 1156 if K >= 0 then J := Brains[K] … … 1159 1159 if not Assigned(J) then 1160 1160 begin // ai not found -- replace by local player 1161 ProcessClientData[p1] := false;1162 NotifyMessage := s;1161 ProcessClientData[p1] := False; 1162 NotifyMessage := S; 1163 1163 Notify(ntAIError); 1164 1164 J := BrainTerm; 1165 1165 end 1166 1166 else 1167 ProcessClientData[p1] := true;1168 if j.Kind = btNoTerm then1169 j:= BrainSuperVirtual;1167 ProcessClientData[p1] := True; 1168 if J.Kind = btNoTerm then 1169 J := BrainSuperVirtual; 1170 1170 // crashed tournament -- load as supervisor 1171 PlayersBrain[p1] := j;1171 PlayersBrain[p1] := J; 1172 1172 end; 1173 1173 end; 1174 1174 end 1175 1175 else 1176 Result := false;1176 Result := False; 1177 1177 1178 1178 if Result then begin … … 1181 1181 end; 1182 1182 FreeAndNil(LogFile); 1183 if not result then1183 if not Result then 1184 1184 Exit; 1185 1185 … … 1195 1195 {$IFDEF TEXTLOG}AssignFile(TextLog, SavePath + LogFileName + '.txt'); 1196 1196 Rewrite(TextLog); {$ENDIF} 1197 LoadOK := true;1197 LoadOK := True; 1198 1198 StartGame; 1199 1199 if MovieMode then … … 1205 1205 Notify(ntLoadBegin); 1206 1206 1207 started := false;1208 StatRequest := false;1209 MovieStopped := false;1207 started := False; 1208 StatRequest := False; 1209 MovieStopped := False; 1210 1210 {$IFDEF LOADPERF}QueryPerformanceCounter(time_total0); 1211 1211 time_a := 0; … … 1222 1222 begin 1223 1223 GenerateStat(pTurn); 1224 StatRequest := false;1224 StatRequest := False; 1225 1225 end; 1226 1226 // complete all internal commands following an sTurn before generating statistics … … 1237 1237 CallPlayer(cMovieTurn, 0, nil^); 1238 1238 end; 1239 StatRequest := true;1240 started := true;1239 StatRequest := True; 1240 started := True; 1241 1241 end 1242 1242 else if (Command = sTurn) and (pTurn = 0) and (GTurn = LoadTurn) then 1243 1243 begin 1244 assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn1244 Assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn 1245 1245 CL.State := FormerCLState; 1246 1246 CL.Cut; … … 1278 1278 EndGame; 1279 1279 Notify(ntStartGo); 1280 result := false;1281 exit;1280 Result := False; 1281 Exit; 1282 1282 end; 1283 1283 1284 1284 if StatRequest then 1285 1285 GenerateStat(pTurn); 1286 assert(started);1286 Assert(started); 1287 1287 {$IFDEF TEXTLOG}CloseFile(TextLog); {$ENDIF} 1288 1288 {$IFDEF LOADPERF}QueryPerformanceCounter(time_total); { time in s is: (time_total-time_total0)/PerfFreq }{$ENDIF} … … 1324 1324 Inform(pTurn); 1325 1325 ChangeClientWhenDone(cResume, 0, nil^, 0); 1326 end; // LoadGame1326 end; 1327 1327 1328 1328 procedure InsertTerritoryUpdateCommands; 1329 1329 var 1330 p1, Command, Subject: integer;1331 Data: pointer;1330 p1, Command, Subject: Integer; 1331 Data: Pointer; 1332 1332 FormerCLState: TCmdListState; 1333 1333 begin … … 1351 1351 1352 1352 procedure StartNewGame(const Path, FileName, Map: string; 1353 Newlx, Newly, NewLandMass, NewMaxTurn: integer);1353 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 1354 1354 var 1355 1355 I: Integer; … … 1395 1395 end; 1396 1396 1397 procedure DirectHelp(Command: integer);1397 procedure DirectHelp(Command: Integer); 1398 1398 begin 1399 1399 InitBrain(BrainTerm); … … 1402 1402 end; 1403 1403 1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer); 1405 1405 var 1406 p1, Loc1: integer;1406 p1, Loc1: Integer; 1407 1407 Game: TNewGameData; 1408 1408 begin … … 1446 1446 end; 1447 1447 1448 procedure DestroySpacePort_TellPlayers( p, pCapturer: integer);1448 procedure DestroySpacePort_TellPlayers(P, pCapturer: Integer); 1449 1449 var 1450 cix, i, p1: integer;1450 cix, I, p1: Integer; 1451 1451 ShowShipChange: TShowShipChange; 1452 1452 begin 1453 1453 // stop ship part production 1454 for cix := 0 to RW[ p].nCity - 1 do1455 with RW[ p].City[cix] do1454 for cix := 0 to RW[P].nCity - 1 do 1455 with RW[P].City[cix] do 1456 1456 if (Loc >= 0) and (Project and cpImp <> 0) and 1457 1457 ((Project and cpIndex = woMIR) or 1458 1458 (Imp[Project and cpIndex].Kind = ikShipPart)) then 1459 1459 begin 1460 inc(RW[p].Money, Prod0);1460 Inc(RW[P].Money, Prod0); 1461 1461 Prod := 0; 1462 1462 Prod0 := 0; … … 1466 1466 1467 1467 // destroy ship 1468 with GShip[ p] do1468 with GShip[P] do 1469 1469 if Parts[0] + Parts[1] + Parts[2] > 0 then 1470 1470 begin 1471 for i:= 0 to nShipPart - 1 do1472 begin 1473 ShowShipChange.Ship1Change[ i] := -Parts[i];1471 for I := 0 to nShipPart - 1 do 1472 begin 1473 ShowShipChange.Ship1Change[I] := -Parts[I]; 1474 1474 if pCapturer >= 0 then 1475 1475 begin 1476 ShowShipChange.Ship2Change[ i] := Parts[i];1477 inc(GShip[pCapturer].Parts[i], Parts[i]);1476 ShowShipChange.Ship2Change[I] := Parts[I]; 1477 Inc(GShip[pCapturer].Parts[I], Parts[I]); 1478 1478 end; 1479 Parts[ i] := 0;1479 Parts[I] := 0; 1480 1480 end; 1481 1481 if Mode >= moMovie then … … 1485 1485 else 1486 1486 ShowShipChange.Reason := scrDestruction; 1487 ShowShipChange.Ship1Owner := p;1487 ShowShipChange.Ship1Owner := P; 1488 1488 ShowShipChange.Ship2Owner := pCapturer; 1489 1489 for p1 := 0 to nPl - 1 do 1490 1490 if 1 shl p1 and (GAlive or GWatching) <> 0 then 1491 1491 begin 1492 move(GShip, RW[p1].Ship, SizeOf(GShip));1492 Move(GShip, RW[p1].Ship, SizeOf(GShip)); 1493 1493 if 1 shl p1 and GWatching <> 0 then 1494 1494 CallPlayer(cShowShipChange, p1, ShowShipChange); … … 1498 1498 end; 1499 1499 1500 procedure DestroyCity_TellPlayers( p, cix: integer; SaveUnits: boolean);1500 procedure DestroyCity_TellPlayers(P, cix: Integer; SaveUnits: Boolean); 1501 1501 begin 1502 if RW[ p].City[cix].built[imSpacePort] > 0 then1503 DestroySpacePort_TellPlayers( p, -1);1504 DestroyCity( p, cix, SaveUnits);1502 if RW[P].City[cix].built[imSpacePort] > 0 then 1503 DestroySpacePort_TellPlayers(P, -1); 1504 DestroyCity(P, cix, SaveUnits); 1505 1505 end; 1506 1506 1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: integer);1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: Integer); 1508 1508 begin 1509 1509 if RW[pOld].City[cixOld].built[imSpacePort] > 0 then … … 1515 1515 end; 1516 1516 1517 procedure CheckWin( p: integer);1517 procedure CheckWin(P: Integer); 1518 1518 var 1519 i: integer;1520 ShipComplete: boolean;1519 I: Integer; 1520 ShipComplete: Boolean; 1521 1521 begin 1522 ShipComplete := true;1523 for i:= 0 to nShipPart - 1 do1524 if GShip[ p].Parts[i] < ShipNeed[i] then1525 ShipComplete := false;1522 ShipComplete := True; 1523 for I := 0 to nShipPart - 1 do 1524 if GShip[P].Parts[I] < ShipNeed[I] then 1525 ShipComplete := False; 1526 1526 if ShipComplete then 1527 GWinner := GWinner or 1 shl p; // game won!1527 GWinner := GWinner or 1 shl P; // game won! 1528 1528 end; 1529 1529 1530 1530 procedure BeforeTurn; 1531 1531 var 1532 i, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,1533 SiegedTiles, nUpdateLoc: integer;1534 UpdateLoc: array [0 .. numax - 1] of integer;1532 I, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc, 1533 SiegedTiles, nUpdateLoc: Integer; 1534 UpdateLoc: array [0 .. numax - 1] of Integer; 1535 1535 Radius: TVicinity21Loc; 1536 1536 ShowShipChange: TShowShipChange; 1537 TribeExtinct, JobDone, MirBuilt: boolean;1537 TribeExtinct, JobDone, MirBuilt: Boolean; 1538 1538 begin 1539 {$IFOPT O-} assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}1540 assert(1 shl pTurn and (GAlive or GWatching) <> 0);1539 {$IFOPT O-}Assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF} 1540 Assert(1 shl pTurn and (GAlive or GWatching) <> 0); 1541 1541 if (1 shl pTurn and GAlive = 0) and (Difficulty[pTurn] > 0) then 1542 exit;1542 Exit; 1543 1543 1544 1544 if (GWonder[woGrLibrary].EffectiveOwner = pTurn) and (GWinner = 0) then … … 1547 1547 for p1 := 0 to nPl - 1 do 1548 1548 if 1 shl p1 and GAlive <> 0 then 1549 inc(nAlive);1549 Inc(nAlive); 1550 1550 ad := 0; 1551 1551 while ad <= (nAdv - 5) do begin … … 1556 1556 if (p1 <> pTurn) and (1 shl p1 and GAlive <> 0) and 1557 1557 (RW[p1].Tech[ad] >= tsApplicable) then 1558 inc(nAppliers);1558 Inc(nAppliers); 1559 1559 if nAppliers * 2 > nAlive then 1560 1560 begin 1561 1561 SeeTech(pTurn, ad); 1562 inc(nTech[pTurn]);1562 Inc(nTech[pTurn]); 1563 1563 if Mode >= moMovie then 1564 1564 CallPlayer(cShowGreatLibTech, pTurn, ad); … … 1577 1577 RW[pTurn].nEnemyUn := 0; 1578 1578 1579 MirBuilt := false;1579 MirBuilt := False; 1580 1580 if (Difficulty[pTurn] > 0) and (GWinner = 0) then 1581 1581 with RW[pTurn] do … … 1600 1600 begin // transport unload 1601 1601 if Model[mix].Domain = dAir then 1602 dec(Un[Master].AirLoad)1602 Dec(Un[Master].AirLoad) 1603 1603 else 1604 dec(Un[Master].TroopLoad);1604 Dec(Un[Master].TroopLoad); 1605 1605 Master := -1; 1606 1606 end … … 1622 1622 if Mode >= moMovie then 1623 1623 FillChar(ShowShipChange, SizeOf(ShowShipChange), 0); 1624 TribeExtinct := true;1624 TribeExtinct := True; 1625 1625 nUpdateLoc := 0; 1626 1626 for cix := 0 to nCity - 1 do … … 1638 1638 begin 1639 1639 Loc1 := Radius[V21]; 1640 assert((Loc1 >= 0) and (Loc1 < MapSize) and1640 Assert((Loc1 >= 0) and (Loc1 < MapSize) and 1641 1641 (UsedByCity[Loc1] = Loc)); 1642 1642 p1 := RealMap[Loc1] shr 27; … … 1649 1649 UsedByCity[Loc1] := -1; 1650 1650 Flags := Flags or chSiege; 1651 inc(SiegedTiles);1651 Inc(SiegedTiles); 1652 1652 end; 1653 1653 end; … … 1656 1656 if not AddBestCityTile(pTurn, cix) then 1657 1657 Break; 1658 dec(SiegedTiles);1658 Dec(SiegedTiles); 1659 1659 end; 1660 1660 … … 1664 1664 1665 1665 if CityTurn(pTurn, cix) then 1666 TribeExtinct := false1666 TribeExtinct := False 1667 1667 else 1668 1668 begin // city is erased … … 1671 1671 Map[Loc] := Map[Loc] and not fCity; // !!! do this in inner core 1672 1672 UpdateLoc[nUpdateLoc] := Loc; 1673 inc(nUpdateLoc);1674 DestroyCity_TellPlayers(pTurn, cix, true);1673 Inc(nUpdateLoc); 1674 DestroyCity_TellPlayers(pTurn, cix, True); 1675 1675 end; 1676 1676 … … 1679 1679 begin 1680 1680 if Project0 and cpIndex = woMIR then // MIR completed 1681 MirBuilt := true1681 MirBuilt := True 1682 1682 else if Project0 and cpIndex = woManhattan then 1683 1683 GColdWarStart := GTurn 1684 1684 else if Imp[Project0 and cpIndex].Kind = ikShipPart 1685 1685 then { ship parts produced } 1686 inc(ShowShipChange.Ship1Change[Project0 and cpIndex -1686 Inc(ShowShipChange.Ship1Change[Project0 and cpIndex - 1687 1687 imShipComp]); 1688 1688 end; … … 1692 1692 begin 1693 1693 CheckBorders(-1, pTurn); 1694 for i:= 0 to nUpdateLoc - 1 do1695 UpdateUnitMap(UpdateLoc[ i], true);1694 for I := 0 to nUpdateLoc - 1 do 1695 UpdateUnitMap(UpdateLoc[I], True); 1696 1696 if Mode >= moMovie then 1697 1697 for p1 := 0 to nPl - 1 do 1698 1698 if (1 shl p1 and GWatching <> 0) and (p1 <> pTurn) then 1699 for i:= 0 to nUpdateLoc - 1 do1700 if ObserveLevel[UpdateLoc[ i]] shr (2 * p1) and 3 >= lObserveUnhidden1699 for I := 0 to nUpdateLoc - 1 do 1700 if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden 1701 1701 then 1702 CallPlayer(cShowCityChanged, p1, UpdateLoc[ i]);1702 CallPlayer(cShowCityChanged, p1, UpdateLoc[I]); 1703 1703 end; 1704 1704 … … 1718 1718 Movement := UnitSpeed(pTurn, mix, Health); { refresh movement } 1719 1719 1720 assert(Loc >= 0);1720 Assert(Loc >= 0); 1721 1721 if Model[mix].Kind <> mkDiplomat then 1722 1722 begin // check treaty violation … … 1762 1762 begin 1763 1763 AddBestCityTile(pTurn, RW[pTurn].nCity - 1); 1764 UpdateUnitMap(Loc1, true);1764 UpdateUnitMap(Loc1, True); 1765 1765 if Mode >= moMovie then // tell enemies 1766 1766 for p1 := 0 to nPl - 1 do … … 1810 1810 end; 1811 1811 end; 1812 exit1812 Exit; 1813 1813 end; 1814 1814 … … 1824 1824 DiscoverTech(pTurn, ResearchTech); 1825 1825 1826 dec(Research, Cost);1826 Dec(Research, Cost); 1827 1827 Happened := Happened or phTech; 1828 ResearchTech := -1 1828 ResearchTech := -1; 1829 1829 end 1830 1830 else if (ResearchTech = -2) and (nCity > 0) then … … 1839 1839 (Treaty[p1] >= trPeace) then 1840 1840 begin 1841 inc(Credibility);1841 Inc(Credibility); 1842 1842 Break; 1843 1843 end; … … 1856 1856 if (p1 <> pTurn) and (1 shl p1 and (GAlive or GWatching) <> 0) then 1857 1857 begin 1858 move(GShip, RW[p1].Ship, SizeOf(GShip));1858 Move(GShip, RW[p1].Ship, SizeOf(GShip)); 1859 1859 if 1 shl p1 and GWatching <> 0 then 1860 1860 CallPlayer(cShowShipChange, p1, ShowShipChange); 1861 end 1861 end; 1862 1862 end; 1863 1863 if WinOnAlone and (GAlive and not(1 shl pTurn or 1) = 0) then … … 1871 1871 if (p1 <> pTurn) and ((GAlive or GWatching) and (1 shl p1) <> 0) then 1872 1872 RW[p1].EnemyReport[pTurn].Government := gDespotism; 1873 inc(Happened, phChangeGov)1873 Inc(Happened, phChangeGov); 1874 1874 end; 1875 1875 end; // if Difficulty[pTurn]>0 … … 1908 1908 end; 1909 1909 // CheckContact; 1910 end; { BeforeTurn }1910 end; 1911 1911 1912 1912 procedure AfterTurn; 1913 1913 var 1914 cix, uix, p1, Loc1, Job0: integer;1915 JobDone: boolean;1914 cix, uix, p1, Loc1, Job0: Integer; 1915 JobDone: Boolean; 1916 1916 begin 1917 1917 with RW[pTurn] do … … 1925 1925 end; 1926 1926 1927 inc(Money, OracleIncome);1927 Inc(Money, OracleIncome); 1928 1928 OracleIncome := 0; 1929 1929 if GWonder[woOracle].EffectiveOwner = pTurn then … … 1935 1935 if (RW[p1].City[cix].Loc >= 0) and 1936 1936 (RW[p1].City[cix].built[imTemple] > 0) then 1937 inc(OracleIncome);1937 Inc(OracleIncome); 1938 1938 end; 1939 1939 … … 1962 1962 begin 1963 1963 AddBestCityTile(pTurn, RW[pTurn].nCity - 1); 1964 UpdateUnitMap(Loc1, true);1964 UpdateUnitMap(Loc1, True); 1965 1965 if Mode >= moMovie then // tell enemies 1966 1966 for p1 := 0 to nPl - 1 do … … 1993 1993 else 1994 1994 begin 1995 dec(Fuel);1995 Dec(Fuel); 1996 1996 if Fuel < 0 then 1997 1997 begin … … 2013 2013 Flags := Flags and not unWithdrawn; 2014 2014 if (Loc >= 0) and (Model[mix].Domain = dGround) and (Master < 0) and 2015 (( integer(Movement) = Model[mix].Speed) or2015 ((Integer(Movement) = Model[mix].Speed) or 2016 2016 (Model[mix].Cap[mcAcademy] > 0) and (Movement * 2 >= Model[mix].Speed)) 2017 2017 then … … 2035 2035 CheckWin(p1); 2036 2036 end; 2037 end; // Afterturn2037 end; 2038 2038 2039 2039 procedure NextPlayer; … … 2049 2049 end; 2050 2050 2051 function ExecuteMove( p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;2052 ShowMove: TShowMove): integer;2051 function ExecuteMove(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo; 2052 ShowMove: TShowMove): Integer; 2053 2053 var 2054 i, p1, FromLoc, uix1, nUpdateLoc: integer;2054 I, p1, FromLoc, uix1, nUpdateLoc: Integer; 2055 2055 MinLevel, MissionResult: Cardinal; 2056 2056 PModel: ^TModel; 2057 UpdateLoc: array [0 .. numax - 1] of integer;2058 SeeFrom, SeeTo, ExtDiscover: boolean;2057 UpdateLoc: array [0 .. numax - 1] of Integer; 2058 SeeFrom, SeeTo, ExtDiscover: Boolean; 2059 2059 begin 2060 result := 0;2061 with RW[ p], Un[uix] do2060 Result := 0; 2061 with RW[P], Un[uix] do 2062 2062 begin 2063 2063 PModel := @Model[mix]; … … 2065 2065 2066 2066 if Master < 0 then 2067 FreeUnit( p, uix);2067 FreeUnit(P, uix); 2068 2068 if (MoveInfo.MoveType in [mtMove, mtCapture]) and MoveInfo.MountainDelay 2069 2069 then … … 2073 2073 Loc := -2; 2074 2074 if TroopLoad + AirLoad > 0 then 2075 for i:= 0 to nUn - 1 do2076 if (Un[ i].Loc >= 0) and (Un[i].Master = uix) then2077 Un[ i].Loc := -2;2075 for I := 0 to nUn - 1 do 2076 if (Un[I].Loc >= 0) and (Un[I].Master = uix) then 2077 Un[I].Loc := -2; 2078 2078 UpdateUnitMap(FromLoc); 2079 2079 … … 2093 2093 ShowMove.Flags := ShowMove.Flags or umShipLoading; 2094 2094 for p1 := 0 to nPl - 1 do 2095 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2095 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2096 2096 then 2097 2097 begin … … 2102 2102 else 2103 2103 MinLevel := lObserveUnhidden; 2104 SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and2104 SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and 2105 2105 3 >= MinLevel); 2106 SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and2106 SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and 2107 2107 3 >= MinLevel); 2108 2108 if SeeFrom and SeeTo then 2109 2109 begin 2110 TellAboutModel(p1, p, mix);2111 if p1 = pthen2110 TellAboutModel(p1, P, mix); 2111 if p1 = P then 2112 2112 ShowMove.emix := -1 2113 2113 else 2114 ShowMove.emix := emixSafe(p1, p, mix);2114 ShowMove.emix := emixSafe(p1, P, mix); 2115 2115 if MoveInfo.MoveType = mtCapture then 2116 2116 CallPlayer(cShowCapturing, p1, ShowMove) … … 2126 2126 Loc := ToLoc; 2127 2127 if TroopLoad + AirLoad > 0 then 2128 for i:= 0 to nUn - 1 do2129 if Un[ i].Loc = -2 then2130 Un[ i].Loc := ToLoc;2131 2132 ExtDiscover := false;2128 for I := 0 to nUn - 1 do 2129 if Un[I].Loc = -2 then 2130 Un[I].Loc := ToLoc; 2131 2132 ExtDiscover := False; 2133 2133 nUpdateLoc := 0; 2134 2134 if MoveInfo.MoveType = mtCapture then 2135 2135 begin 2136 assert(Occupant[ToLoc] < 0);2136 Assert(Occupant[ToLoc] < 0); 2137 2137 for uix1 := 0 to RW[MoveInfo.Defender].nUn - 1 do 2138 2138 with RW[MoveInfo.Defender].Un[uix1] do … … 2140 2140 begin 2141 2141 UpdateLoc[nUpdateLoc] := Loc; 2142 inc(nUpdateLoc);2142 Inc(nUpdateLoc); 2143 2143 end; 2144 2144 // unit will be removed -- remember position and update for all players … … 2147 2147 then 2148 2148 begin // city captured 2149 ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, p);2149 ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, P); 2150 2150 City[nCity - 1].Flags := CaptureTurns shl 16; 2151 CityShrink( p, nCity - 1);2151 CityShrink(P, nCity - 1); 2152 2152 if Mode = moPlaying then 2153 with RW[ p].City[nCity - 1] do2153 with RW[P].City[nCity - 1] do 2154 2154 begin 2155 2155 // SavedResourceWeights[nCity-1]:=ResourceWeights; 2156 2156 SavedTiles[nCity - 1] := Tiles; 2157 2157 end; 2158 ExtDiscover := true;2158 ExtDiscover := True; 2159 2159 2160 2160 // Temple of Zeus effect 2161 if GWonder[woZeus].EffectiveOwner = pthen2161 if GWonder[woZeus].EffectiveOwner = P then 2162 2162 begin 2163 GiveCivilReport( p, MoveInfo.Defender);2164 for i:= 0 to nAdv - 1 do2165 if not( i in FutureTech) and (RW[p].Tech[i] < tsSeen) and2166 (RW[MoveInfo.Defender].Tech[ i] >= tsApplicable) then2163 GiveCivilReport(P, MoveInfo.Defender); 2164 for I := 0 to nAdv - 1 do 2165 if not(I in FutureTech) and (RW[P].Tech[I] < tsSeen) and 2166 (RW[MoveInfo.Defender].Tech[I] >= tsApplicable) then 2167 2167 begin 2168 2168 Happened := Happened or phStealTech; … … 2172 2172 end; 2173 2173 if Mode = moPlaying then 2174 LogCheckBorders( p, nCity - 1, MoveInfo.Defender);2174 LogCheckBorders(P, nCity - 1, MoveInfo.Defender); 2175 2175 {$IFOPT O-} if Mode < moPlaying then 2176 InvalidTreatyMap := not(1 shl p); {$ENDIF}2176 InvalidTreatyMap := not(1 shl P); {$ENDIF} 2177 2177 // territory should not be considered for the rest of the command 2178 2178 // execution, because during loading a game it's incorrect before … … 2181 2181 else // city destroyed 2182 2182 begin 2183 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);2183 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False); 2184 2184 CheckBorders(ToLoc, MoveInfo.Defender); 2185 2185 end; 2186 RecalcPeaceMap( p);2186 RecalcPeaceMap(P); 2187 2187 if Mode >= moMovie then 2188 move(GWonder, Wonder, SizeOf(GWonder));2188 Move(GWonder, Wonder, SizeOf(GWonder)); 2189 2189 end; { if MoveInfo.MoveType=mtCapture } 2190 2190 2191 2191 if MoveInfo.MoveType = mtSpyMission then 2192 2192 begin 2193 MissionResult := DoSpyMission( p, MoveInfo.Defender, MoveInfo.Dcix,2193 MissionResult := DoSpyMission(P, MoveInfo.Defender, MoveInfo.Dcix, 2194 2194 SpyMission); 2195 2195 if (Mode = moPlaying) and (SpyMission = smStealForeignReports) then 2196 CallPlayer(cShowMissionResult, p, MissionResult);2196 CallPlayer(cShowMissionResult, P, MissionResult); 2197 2197 end; 2198 2198 2199 2199 Health := MoveInfo.EndHealth; 2200 dec(Movement, MoveInfo.Cost);2200 Dec(Movement, MoveInfo.Cost); 2201 2201 // transport unload 2202 2202 if Master >= 0 then 2203 2203 begin 2204 2204 if PModel.Domain = dAir then 2205 dec(Un[Master].AirLoad)2206 else 2207 begin 2208 dec(Un[Master].TroopLoad);2209 assert(Movement <= 0);2205 Dec(Un[Master].AirLoad) 2206 else 2207 begin 2208 Dec(Un[Master].TroopLoad); 2209 Assert(Movement <= 0); 2210 2210 end; 2211 2211 Master := -1; … … 2213 2213 2214 2214 if (Health <= 0) or (MoveInfo.MoveType = mtSpyMission) then 2215 RemoveUnit( p, uix) // spy mission or victim of HostileDamage2215 RemoveUnit(P, uix) // spy mission or victim of HostileDamage 2216 2216 else 2217 2217 begin // transport load … … 2220 2220 begin 2221 2221 if PModel.Domain = dAir then 2222 inc(Un[MoveInfo.ToMaster].AirLoad)2222 Inc(Un[MoveInfo.ToMaster].AirLoad) 2223 2223 else 2224 inc(Un[MoveInfo.ToMaster].TroopLoad);2224 Inc(Un[MoveInfo.ToMaster].TroopLoad); 2225 2225 end 2226 2226 else 2227 PlaceUnit( p, uix);2227 PlaceUnit(P, uix); 2228 2228 end; 2229 2229 2230 2230 if (MoveInfo.MoveType = mtCapture) and (nUpdateLoc > 0) then 2231 RecalcMapZoC( p);2231 RecalcMapZoC(P); 2232 2232 UpdateUnitMap(ToLoc, MoveInfo.MoveType = mtCapture); 2233 for i:= 0 to nUpdateLoc - 1 do2234 UpdateUnitMap(UpdateLoc[ i]);2233 for I := 0 to nUpdateLoc - 1 do 2234 UpdateUnitMap(UpdateLoc[I]); 2235 2235 // tell about lost units of defender 2236 2236 … … 2242 2242 (RealMap[ToLoc] and fTerImp = tiFort) or 2243 2243 (RealMap[ToLoc] and fTerImp = tiBase) then 2244 ExtDiscover := true;2244 ExtDiscover := True; 2245 2245 if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then 2246 i:= lObserveSuper2246 I := lObserveSuper 2247 2247 else if (PModel.Domain = dAir) or 2248 2248 (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) then 2249 i:= lObserveAll2250 else 2251 i:= lObserveUnhidden;2249 I := lObserveAll 2250 else 2251 I := lObserveUnhidden; 2252 2252 if ExtDiscover then 2253 2253 begin 2254 if Discover21(ToLoc, p, i, true, PModel.Domain = dGround) then2255 result := result or rEnemySpotted;2254 if Discover21(ToLoc, P, I, True, PModel.Domain = dGround) then 2255 Result := Result or rEnemySpotted; 2256 2256 end 2257 2257 else 2258 2258 begin 2259 if Discover9(ToLoc, p, i, true, PModel.Domain = dGround) then2260 result := result or rEnemySpotted;2259 if Discover9(ToLoc, P, I, True, PModel.Domain = dGround) then 2260 Result := Result or rEnemySpotted; 2261 2261 end; 2262 2262 end; … … 2264 2264 if Mode >= moMovie then { show after-move in interface modules } 2265 2265 for p1 := 0 to nPl - 1 do 2266 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2266 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2267 2267 then 2268 2268 begin … … 2273 2273 else 2274 2274 MinLevel := lObserveUnhidden; 2275 SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and2275 SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and 2276 2276 3 >= MinLevel); 2277 SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and2277 SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and 2278 2278 3 >= MinLevel); 2279 2279 if SeeTo and (MoveInfo.MoveType = mtCapture) then … … 2283 2283 else if (MoveInfo.MoveType <> mtSpyMission) and SeeTo then 2284 2284 CallPlayer(cShowUnitChanged, p1, ToLoc); 2285 for i:= 0 to nUpdateLoc - 1 do2286 if ObserveLevel[UpdateLoc[ i]] shr (2 * p1) and 3 >= lObserveUnhidden2285 for I := 0 to nUpdateLoc - 1 do 2286 if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden 2287 2287 then 2288 CallPlayer(cShowUnitChanged, p1, UpdateLoc[ i]);2288 CallPlayer(cShowUnitChanged, p1, UpdateLoc[I]); 2289 2289 end; 2290 2290 end; 2291 end; // ExecuteMove2292 2293 function ExecuteAttack( p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;2294 ShowMove: TShowMove): integer;2291 end; 2292 2293 function ExecuteAttack(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo; 2294 ShowMove: TShowMove): Integer; 2295 2295 2296 2296 procedure WriteBattleHistory(ToLoc, FromLoc, Attacker, Defender, mixAttacker, 2297 mixDefender: integer; AttackerLost, DefenderLost: boolean);2297 mixDefender: Integer; AttackerLost, DefenderLost: Boolean); 2298 2298 var 2299 2299 AttackerBattle, DefenderBattle: ^TBattle; … … 2307 2307 ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle))); 2308 2308 AttackerBattle := @BattleHistory[nBattleHistory]; 2309 inc(nBattleHistory);2309 Inc(nBattleHistory); 2310 2310 end; 2311 2311 with RW[Defender] do … … 2317 2317 ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle))); 2318 2318 DefenderBattle := @BattleHistory[nBattleHistory]; 2319 inc(nBattleHistory);2319 Inc(nBattleHistory); 2320 2320 end; 2321 2321 AttackerBattle.Enemy := Defender; … … 2346 2346 2347 2347 var 2348 i, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: integer;2348 I, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: Integer; 2349 2349 PModel: ^TModel; 2350 UpdateLoc: array [0 .. numax - 1] of integer;2351 LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: boolean;2350 UpdateLoc: array [0 .. numax - 1] of Integer; 2351 LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: Boolean; 2352 2352 begin 2353 result := 0;2354 with RW[ p].Un[uix] do2353 Result := 0; 2354 with RW[P].Un[uix] do 2355 2355 begin 2356 PModel := @RW[ p].Model[mix];2356 PModel := @RW[P].Model[mix]; 2357 2357 FromLoc := Loc; 2358 2358 … … 2360 2360 ShowMove.EndHealthDef := MoveInfo.EndHealthDef; 2361 2361 if MoveInfo.MoveType = mtAttack then 2362 WriteBattleHistory(ToLoc, FromLoc, p, MoveInfo.Defender, mix,2362 WriteBattleHistory(ToLoc, FromLoc, P, MoveInfo.Defender, mix, 2363 2363 RW[MoveInfo.Defender].Un[MoveInfo.Duix].mix, MoveInfo.EndHealth <= 0, 2364 2364 MoveInfo.EndHealthDef <= 0); … … 2367 2367 begin 2368 2368 if Mode>=moMovie then 2369 CallPlayer(cShowCancelTreaty,MoveInfo.Defender, p);2370 CancelTreaty( p,MoveInfo.Defender)2369 CallPlayer(cShowCancelTreaty,MoveInfo.Defender,P); 2370 CancelTreaty(P,MoveInfo.Defender) 2371 2371 end; } 2372 2372 if Mode >= moMovie then { show attack in interface modules } 2373 2373 for p1 := 0 to nPl - 1 do 2374 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2374 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2375 2375 then 2376 2376 begin … … 2380 2380 if SeeFrom and SeeTo then 2381 2381 begin 2382 TellAboutModel(p1, p, mix);2383 if p1 = pthen2382 TellAboutModel(p1, P, mix); 2383 if p1 = P then 2384 2384 ShowMove.emix := -1 2385 2385 else 2386 ShowMove.emix := emixSafe(p1, p, mix);2386 ShowMove.emix := emixSafe(p1, P, mix); 2387 2387 CallPlayer(cShowAttacking, p1, ShowMove); 2388 2388 end; 2389 2389 end; 2390 2390 2391 LoseCityPop := false;2391 LoseCityPop := False; 2392 2392 if (RealMap[ToLoc] and fCity <> 0) and 2393 2393 ((MoveInfo.MoveType = mtAttack) and (MoveInfo.EndHealthDef <= 0) or … … 2411 2411 if MoveInfo.MoveType = mtBombard then 2412 2412 begin 2413 assert(Movement >= 100);2413 Assert(Movement >= 100); 2414 2414 if PModel.Attack = 0 then 2415 2415 Flags := Flags and not unBombsLoaded; 2416 dec(Movement, 100);2416 Dec(Movement, 100); 2417 2417 end 2418 2418 else if MoveInfo.MoveType = mtExpel then 2419 2419 begin 2420 assert(Movement >= 100);2420 Assert(Movement >= 100); 2421 2421 Job := jNone; 2422 2422 Flags := Flags and not unFortified; 2423 dec(Movement, 100);2423 Dec(Movement, 100); 2424 2424 end 2425 2425 else 2426 2426 begin 2427 assert(MoveInfo.MoveType = mtAttack);2427 Assert(MoveInfo.MoveType = mtAttack); 2428 2428 if MoveInfo.EndHealth = 0 then 2429 RemoveUnit( p, uix, MoveInfo.Defender) // destroy attacker2429 RemoveUnit(P, uix, MoveInfo.Defender) // destroy attacker 2430 2430 else 2431 2431 begin // update attacker … … 2434 2434 Exp := (nExp - 1) * ExpCost 2435 2435 else 2436 inc(Exp, ExpGain);2436 Inc(Exp, ExpGain); 2437 2437 Health := MoveInfo.EndHealth; 2438 2438 Job := jNone; … … 2442 2442 Flags := Flags and not unFortified; 2443 2443 if Movement > 100 then 2444 dec(Movement, 100)2444 Dec(Movement, 100) 2445 2445 else 2446 2446 Movement := 0; … … 2448 2448 end; 2449 2449 2450 ZoCDefenderDestroyed := false;2450 ZoCDefenderDestroyed := False; 2451 2451 nUpdateLoc := 0; 2452 2452 if MoveInfo.MoveType = mtExpel then … … 2469 2469 PlaceUnit(MoveInfo.Defender, MoveInfo.Duix); 2470 2470 UpdateLoc[nUpdateLoc] := Loc; 2471 inc(nUpdateLoc);2471 Inc(nUpdateLoc); 2472 2472 Flags := Flags or unWithdrawn; 2473 2473 end; … … 2480 2480 Exp := (nExp - 1) * ExpCost 2481 2481 else 2482 inc(Exp, ExpGain);2482 Inc(Exp, ExpGain); 2483 2483 Health := MoveInfo.EndHealthDef; 2484 2484 end … … 2493 2493 (RealMap[ToLoc] and fTerImp <> tiFort)) or LoseCityPop and 2494 2494 (RW[MoveInfo.Defender].City[MoveInfo.Dcix].Size = 2) then 2495 RemoveAllUnits(MoveInfo.Defender, ToLoc, p)2495 RemoveAllUnits(MoveInfo.Defender, ToLoc, P) 2496 2496 { no city, base or fortress } 2497 2497 else 2498 RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, p);2498 RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, P); 2499 2499 end; 2500 2500 … … 2509 2509 begin 2510 2510 UpdateLoc[nUpdateLoc] := Loc; 2511 inc(nUpdateLoc);2511 Inc(nUpdateLoc); 2512 2512 end; 2513 2513 // unit will be removed -- remember position and update for all players 2514 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);2514 DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False); 2515 2515 CheckBorders(ToLoc, MoveInfo.Defender); 2516 RecalcPeaceMap( p);2516 RecalcPeaceMap(P); 2517 2517 end; 2518 2518 end; 2519 2519 2520 2520 if CityDestroyed and (nUpdateLoc > 0) then 2521 RecalcMapZoC( p)2521 RecalcMapZoC(P) 2522 2522 else if ZoCDefenderDestroyed then 2523 RecalcV8ZoC( p, ToLoc);2523 RecalcV8ZoC(P, ToLoc); 2524 2524 UpdateUnitMap(FromLoc); 2525 2525 UpdateUnitMap(ToLoc, LoseCityPop); 2526 for i:= 0 to nUpdateLoc - 1 do2527 UpdateUnitMap(UpdateLoc[ i]);2526 for I := 0 to nUpdateLoc - 1 do 2527 UpdateUnitMap(UpdateLoc[I]); 2528 2528 // tell about lost units of defender 2529 2529 2530 2530 if Mode >= moMovie then 2531 2531 begin 2532 for i := 0 to RW[p].nEnemyModel - 1 do2533 with RW[ p].EnemyModel[i] do2534 Lost := Destroyed[ p, Owner, mix];2532 for I := 0 to RW[P].nEnemyModel - 1 do 2533 with RW[P].EnemyModel[I] do 2534 Lost := Destroyed[P, Owner, mix]; 2535 2535 for p1 := 0 to nPl - 1 do { show after-attack in interface modules } 2536 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))2536 if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm)) 2537 2537 then 2538 2538 begin … … 2559 2559 end; 2560 2560 end; 2561 end; // ExecuteAttack2562 2563 function MoveUnit( p, uix, dx, dy: integer; TestOnly: boolean): integer;2561 end; 2562 2563 function MoveUnit(P, uix, dx, dy: Integer; TestOnly: Boolean): Integer; 2564 2564 var 2565 ToLoc: integer;2565 ToLoc: Integer; 2566 2566 MoveInfo: TMoveInfo; 2567 2567 ShowMove: TShowMove; 2568 2568 begin 2569 {$IFOPT O-} assert(1 shl pand InvalidTreatyMap = 0); {$ENDIF}2570 with RW[ p].Un[uix] do2569 {$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF} 2570 with RW[P].Un[uix] do 2571 2571 begin 2572 2572 ToLoc := dLoc(Loc, dx, dy); 2573 2573 if (ToLoc < 0) or (ToLoc >= MapSize) then 2574 2574 begin 2575 result := eInvalid;2576 exit;2575 Result := eInvalid; 2576 Exit; 2577 2577 end; 2578 result := CalculateMove(p, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);2579 if result = eZOC_EnemySpotted then2578 Result := CalculateMove(P, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo); 2579 if Result = eZOC_EnemySpotted then 2580 2580 ZOCTile := ToLoc; 2581 if ( result >= rExecuted) and not TestOnly then2581 if (Result >= rExecuted) and not TestOnly then 2582 2582 begin 2583 2583 ShowMove.dx := dx; … … 2589 2589 ShowMove.Exp := Exp; 2590 2590 ShowMove.Load := TroopLoad + AirLoad; 2591 ShowMove.Owner := p;2591 ShowMove.Owner := P; 2592 2592 if (TroopLoad > 0) or (AirLoad > 0) then 2593 2593 ShowMove.Flags := unMulti … … 2606 2606 case MoveInfo.MoveType of 2607 2607 mtMove, mtCapture, mtSpyMission: 2608 result := ExecuteMove(p, uix, ToLoc, MoveInfo, ShowMove) or result;2608 Result := ExecuteMove(P, uix, ToLoc, MoveInfo, ShowMove) or Result; 2609 2609 mtAttack, mtBombard, mtExpel: 2610 result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result;2610 Result := ExecuteAttack(P, uix, ToLoc, MoveInfo, ShowMove) or Result; 2611 2611 end; 2612 2612 end; 2613 end; // with2614 end; { MoveUnit }2615 2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;2617 2618 function CountPrice(const Offer: TOffer; PriceType: integer): integer;2613 end; 2614 end; 2615 2616 function Server(Command, Player, Subject: Integer; var Data): Integer; stdcall; 2617 2618 function CountPrice(const Offer: TOffer; PriceType: Integer): Integer; 2619 2619 var 2620 i: integer;2620 I: Integer; 2621 2621 begin 2622 result := 0;2623 for i:= 0 to Offer.nDeliver + Offer.nCost - 1 do2624 if Offer.Price[ i] and $FFFF0000 = Cardinal(PriceType) then2625 inc(result);2622 Result := 0; 2623 for I := 0 to Offer.nDeliver + Offer.nCost - 1 do 2624 if Offer.Price[I] and $FFFF0000 = Cardinal(PriceType) then 2625 Inc(Result); 2626 2626 end; 2627 2627 2628 2628 { procedure UpdateBorderHelper; 2629 2629 var 2630 x, y, Loc, Loc1, dx, dy, ObserveMask: integer;2630 X, Y, Loc, Loc1, dx, dy, ObserveMask: Integer; 2631 2631 begin 2632 2632 ObserveMask:=3 shl (2*pTurn); 2633 for x:=0 to lx-1 do for y:=0 to ly shr 1-1 do2633 for X:=0 to lx-1 do for Y:=0 to ly shr 1-1 do 2634 2634 begin 2635 Loc:=lx*( y*2)+x;2635 Loc:=lx*(Y*2)+X; 2636 2636 if ObserveLevel[Loc] and ObserveMask<>0 then 2637 2637 begin 2638 2638 for dy:=0 to 1 do for dx:=0 to 1 do 2639 2639 begin 2640 Loc1:=(Loc+dx-1+lx) mod lx +lx*(( y+dy)*2-1);2640 Loc1:=(Loc+dx-1+lx) mod lx +lx*((Y+dy)*2-1); 2641 2641 if (Loc1>=0) and (Loc1<MapSize) 2642 2642 and (ObserveLevel[Loc1] and ObserveMask<>0) then … … 2666 2666 ptInvalid = 8; 2667 2667 2668 function ProjectType(Project: integer): integer;2668 function ProjectType(Project: Integer): Integer; 2669 2669 begin 2670 2670 if Project and cpCompleted <> 0 then 2671 result := ptSelect2671 Result := ptSelect 2672 2672 else if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 2673 result := ptTrGoods2673 Result := ptTrGoods 2674 2674 else if Project and cpImp = 0 then 2675 2675 if RW[Player].Model[Project and cpIndex].Kind = mkCaravan then 2676 result := ptCaravan2677 else 2678 result := ptUn2676 Result := ptCaravan 2677 else 2678 Result := ptUn 2679 2679 else if Project and cpIndex >= nImp then 2680 result := ptInvalid2680 Result := ptInvalid 2681 2681 else if Imp[Project and cpIndex].Kind = ikWonder then 2682 result := ptWonder2682 Result := ptWonder 2683 2683 else if Imp[Project and cpIndex].Kind = ikShipPart then 2684 result := ptShip2684 Result := ptShip 2685 2685 else 2686 result := ptImp;2686 Result := ptImp; 2687 2687 end; 2688 2688 2689 2689 var 2690 d, i, j, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,2690 D, I, J, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap, 2691 2691 MaxCap, CapWeight, Cost, NextProd, Preq, TotalFood, TotalProd, CheckSum, 2692 2692 StopTurn, FutureMCost, NewProject, OldImp, mix, V8, V21, AStr, DStr, 2693 ABaseDamage, DBaseDamage: integer;2693 ABaseDamage, DBaseDamage: Integer; 2694 2694 CityReport: TCityReport; 2695 2695 FormerCLState: TCmdListState; … … 2698 2698 ShowShipChange: TShowShipChange; 2699 2699 ShowNegoData: TShowNegoData; 2700 logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: boolean; 2701 2702 begin { >>>server } 2700 logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: Boolean; 2701 begin 2703 2702 if Command = sTurn then 2704 2703 begin … … 2709 2708 end; 2710 2709 2711 assert(MapSize = lx * ly);2712 assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);2710 Assert(MapSize = lx * ly); 2711 Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute); 2713 2712 // not for internal commands 2714 2713 if (Command < 0) or (Command >= $10000) then 2715 2714 begin 2716 result := eUnknown;2717 exit;2715 Result := eUnknown; 2716 Exit; 2718 2717 end; 2719 2718 … … 2722 2721 ((Subject < 0) or (Subject >= $1000))) then 2723 2722 begin 2724 result := eInvalid;2725 exit;2723 Result := eInvalid; 2724 Exit; 2726 2725 end; 2727 2726 … … 2732 2731 begin 2733 2732 PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player])); 2734 result := eNoTurn;2735 exit;2733 Result := eNoTurn; 2734 Exit; 2736 2735 end; 2737 2736 2738 result := eOK;2737 Result := eOK; 2739 2738 2740 2739 // check if command allowed now … … 2759 2758 PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x', 2760 2759 [Player, Command shr 4])); 2761 result := eNoTurn;2762 exit;2760 Result := eNoTurn; 2761 Exit; 2763 2762 end; 2764 2763 … … 2768 2767 HandoverStack[nHandoverStack] := Player + $1000; 2769 2768 HandoverStack[nHandoverStack + 1] := Command; 2770 inc(nHandoverStack, 2);2769 Inc(nHandoverStack, 2); 2771 2770 2772 2771 InvalidTreatyMap := 0; … … 2781 2780 FormerCLState := CL.State; 2782 2781 CL.Put(Command, Player, Subject, @Data); 2783 logged := true;2782 logged := True; 2784 2783 end 2785 2784 else 2786 logged := false;2785 logged := False; 2787 2786 2788 2787 case Command of … … 2799 2798 2800 2799 sGetDebugMap: 2801 pointer(Data) := DebugMap[Subject];2800 Pointer(Data) := DebugMap[Subject]; 2802 2801 2803 2802 { sChangeSuperView: 2804 2803 if Difficulty[Player]=0 then 2805 2804 begin 2806 for i:=0 to nBrain-1 do if Brain[i].Initialized then2807 CallClient( i, cShowSuperView, Subject)2805 for I:=0 to nBrain-1 do if Brain[I].Initialized then 2806 CallClient(I, cShowSuperView, Subject) 2808 2807 end 2809 else result:=eInvalid; }2808 else Result:=eInvalid; } 2810 2809 2811 2810 sRefreshDebugMap: … … 2830 2829 else 2831 2830 StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1; 2832 move(Stat[Command shr 4 and $F, Subject]^, Data,2833 StopTurn * SizeOf( integer));2831 Move(Stat[Command shr 4 and $F, Subject]^, Data, 2832 StopTurn * SizeOf(Integer)); 2834 2833 FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) * 2835 SizeOf( integer), 0);2834 SizeOf(Integer), 0); 2836 2835 end 2837 2836 else 2838 result := eInvalid;2837 Result := eInvalid; 2839 2838 2840 2839 sGetTechCost: 2841 integer(Data) := TechCost(Player);2840 Integer(Data) := TechCost(Player); 2842 2841 2843 2842 sGetAIInfo: 2844 2843 if AIInfo[Subject] = '' then 2845 pchar(Data) := nil2846 else 2847 pchar(Data) := @AIInfo[Subject][1];2844 PChar(Data) := nil 2845 else 2846 PChar(Data) := @AIInfo[Subject][1]; 2848 2847 2849 2848 sGetAICredits: 2850 2849 if AICredits = '' then 2851 pchar(Data) := nil2852 else 2853 pchar(Data) := @AICredits[1];2850 PChar(Data) := nil 2851 else 2852 PChar(Data) := @AICredits[1]; 2854 2853 2855 2854 sGetVersion: 2856 integer(Data) := CevoVersion;2855 Integer(Data) := CevoVersion; 2857 2856 2858 2857 sGetGameChanged: 2859 2858 if Player <> 0 then 2860 result := eInvalid2859 Result := eInvalid 2861 2860 else if (CL <> nil) and (CL.State.nLog = nLogOpened) and 2862 2861 (CL.State.MoveCode = 0) and not HasCityTileChanges and 2863 2862 not HasChanges(Player) then 2864 result := eNotChanged;2863 Result := eNotChanged; 2865 2864 2866 2865 sGetTileInfo: 2867 2866 if (Subject >= 0) and (Subject < MapSize) then 2868 result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))2869 else 2870 result := eInvalid;2867 Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data)) 2868 else 2869 Result := eInvalid; 2871 2870 2872 2871 sGetCityTileInfo: 2873 2872 if (Subject >= 0) and (Subject < MapSize) then 2874 result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))2875 else 2876 result := eInvalid;2873 Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data)) 2874 else 2875 Result := eInvalid; 2877 2876 2878 2877 sGetHypoCityTileInfo: … … 2881 2880 if (TTileInfo(Data).ExplCity < 0) or 2882 2881 (TTileInfo(Data).ExplCity >= RW[Player].nCity) then 2883 result := eInvalid2882 Result := eInvalid 2884 2883 else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2885 result := eNoPreq2884 Result := eNoPreq 2886 2885 else 2887 result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,2886 Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject, 2888 2887 TTileInfo(Data)); 2889 2888 end 2890 2889 else 2891 result := eInvalid;2890 Result := eInvalid; 2892 2891 2893 2892 sGetJobProgress: … … 2895 2894 begin 2896 2895 if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then 2897 result := eNoPreq2896 Result := eNoPreq 2898 2897 else 2899 result := GetJobProgress(Player, Subject, TJobProgressData(Data));2898 Result := GetJobProgress(Player, Subject, TJobProgressData(Data)); 2900 2899 end 2901 2900 else 2902 result := eInvalid;2901 Result := eInvalid; 2903 2902 2904 2903 sGetModels: … … 2912 2911 end 2913 2912 else 2914 result := eInvalid;2913 Result := eInvalid; 2915 2914 2916 2915 sGetUnits: 2917 2916 if (Subject >= 0) and (Subject < MapSize) and 2918 2917 (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then 2919 integer(Data) := GetUnitStack(Player, Subject)2920 else 2921 result := eNoPreq;2918 Integer(Data) := GetUnitStack(Player, Subject) 2919 else 2920 Result := eNoPreq; 2922 2921 2923 2922 sGetDefender: 2924 2923 if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player) 2925 2924 then 2926 Strongest(Subject, integer(Data), d, i, j)2927 else 2928 result := eInvalid;2925 Strongest(Subject, Integer(Data), D, I, J) 2926 else 2927 Result := eInvalid; 2929 2928 2930 2929 sGetBattleForecast, sGetBattleForecastEx: … … 2936 2935 ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then 2937 2936 begin 2938 result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,2937 Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1, 2939 2938 cix1, AStr, DStr, ABaseDamage, DBaseDamage); 2940 2939 if Command = sGetBattleForecastEx then … … 2945 2944 TBattleForecastEx(Data).DBaseDamage := DBaseDamage; 2946 2945 end; 2947 if result = eOK then2948 result := eInvalid; // no enemy unit there!2946 if Result = eOK then 2947 Result := eInvalid; // no enemy unit there! 2949 2948 end 2950 2949 else 2951 result := eInvalid2952 else 2953 result := eInvalid;2950 Result := eInvalid 2951 else 2952 Result := eInvalid; 2954 2953 2955 2954 sGetUnitReport: 2956 2955 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2957 2956 (RW[Player].Un[Subject].Loc < 0) then 2958 result := eInvalid2957 Result := eInvalid 2959 2958 else 2960 2959 GetUnitReport(Player, Subject, TUnitReport(Data)); … … 2963 2962 if (Subject < 0) or (Subject >= RW[Player].nUn) or 2964 2963 (RW[Player].Un[Subject].Loc < 0) then 2965 result := eInvalid2966 else 2967 result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));2964 Result := eInvalid 2965 else 2966 Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data)); 2968 2967 2969 2968 sGetPlaneReturn: … … 2971 2970 (RW[Player].Un[Subject].Loc < 0) or 2972 2971 (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then 2973 result := eInvalid2972 Result := eInvalid 2974 2973 else 2975 2974 begin 2976 2975 if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then 2977 result := eOK2976 Result := eOK 2978 2977 else 2979 result := eNoWay;2978 Result := eNoWay; 2980 2979 end; 2981 2980 … … 2988 2987 Owner := Player; 2989 2988 SearchCity(Subject, Owner, cix1); 2990 c:= RW[Owner].City[cix1];2991 if (Owner <> Player) and ( c.Project and cpImp = 0) then2992 TellAboutModel(Player, Owner, c.Project and cpIndex);2989 C := RW[Owner].City[cix1]; 2990 if (Owner <> Player) and (C.Project and cpImp = 0) then 2991 TellAboutModel(Player, Owner, C.Project and cpIndex); 2993 2992 end 2994 2993 else 2995 result := eInvalid;2994 Result := eInvalid; 2996 2995 2997 2996 sGetCityReport: 2998 2997 if (Subject < 0) or (Subject >= RW[Player].nCity) or 2999 2998 (RW[Player].City[Subject].Loc < 0) then 3000 result := eInvalid3001 else 3002 result := GetCityReport(Player, Subject, TCityReport(Data));2999 Result := eInvalid 3000 else 3001 Result := GetCityReport(Player, Subject, TCityReport(Data)); 3003 3002 3004 3003 sGetCityReportNew: 3005 3004 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3006 3005 (RW[Player].City[Subject].Loc < 0) then 3007 result := eInvalid3006 Result := eInvalid 3008 3007 else 3009 3008 GetCityReportNew(Player, Subject, TCityReportNew(Data)); … … 3012 3011 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3013 3012 (RW[Player].City[Subject].Loc < 0) then 3014 result := eInvalid3013 Result := eInvalid 3015 3014 else 3016 3015 GetCityAreaInfo(Player, RW[Player].City[Subject].Loc, … … 3032 3031 end 3033 3032 else 3034 result := eInvalid;3033 Result := eInvalid; 3035 3034 3036 3035 sGetEnemyCityReportNew: … … 3049 3048 end 3050 3049 else 3051 result := eInvalid;3050 Result := eInvalid; 3052 3051 3053 3052 sGetEnemyCityAreaInfo: … … 3063 3062 end 3064 3063 else 3065 result := eInvalid;3064 Result := eInvalid; 3066 3065 3067 3066 sGetCityTileAdvice: 3068 3067 if (Subject < 0) or (Subject >= RW[Player].nCity) or 3069 3068 (RW[Player].City[Subject].Loc < 0) then 3070 result := eInvalid3069 Result := eInvalid 3071 3070 else 3072 3071 GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data)); … … 3081 3080 EditTile(Loc, NewTile) 3082 3081 else 3083 result := eInvalid;3082 Result := eInvalid; 3084 3083 3085 3084 sRandomMap: … … 3087 3086 begin 3088 3087 CreateElevation; 3089 PreviewElevation := false;3090 CreateMap( false);3088 PreviewElevation := False; 3089 CreateMap(False); 3091 3090 FillChar(ObserveLevel, MapSize * 4, 0); 3092 3091 DiscoverAll(Player, lObserveSuper); 3093 3092 end 3094 3093 else 3095 result := eInvalid;3094 Result := eInvalid; 3096 3095 3097 3096 sMapGeneratorRequest: 3098 3097 if not MapGeneratorAvailable then 3099 result := eInvalid;3098 Result := eInvalid; 3100 3099 3101 3100 { … … 3105 3104 sTurn, sTurn - sExecute: 3106 3105 begin 3107 AllHumansDead := true;3106 AllHumansDead := True; 3108 3107 for p1 := 0 to nPl - 1 do 3109 3108 if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then 3110 AllHumansDead := false;3109 AllHumansDead := False; 3111 3110 if (pDipActive >= 0) // still in negotiation mode 3112 3111 or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or 3113 3112 (Difficulty[0] > 0) and AllHumansDead) then // game end reached 3114 result := eViolation3113 Result := eViolation 3115 3114 else if Command >= sExecute then 3116 3115 begin … … 3123 3122 begin 3124 3123 LogChanges; 3125 SaveGame('~' + LogFileName, true);3124 SaveGame('~' + LogFileName, True); 3126 3125 end; 3127 3126 {$ENDIF} … … 3138 3137 TotalFood := 0; 3139 3138 TotalProd := 0; 3140 for i:= 0 to RW[pTurn].nCity - 1 do3141 if RW[pTurn].City[ i].Loc >= 0 then3139 for I := 0 to RW[pTurn].nCity - 1 do 3140 if RW[pTurn].City[I].Loc >= 0 then 3142 3141 begin 3143 inc(TotalFood, RW[pTurn].City[i].Food);3144 inc(TotalProd, RW[pTurn].City[i].Prod);3142 Inc(TotalFood, RW[pTurn].City[I].Food); 3143 Inc(TotalProd, RW[pTurn].City[I].Prod); 3145 3144 end; 3146 3145 CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 + … … 3153 3152 begin 3154 3153 if CheckSum <> Subject then 3155 LoadOK := false;3154 LoadOK := False; 3156 3155 end 3157 3156 else // save checksum … … 3180 3179 pTurn := (pTurn + 1) mod nPl; 3181 3180 if pTurn = 0 then 3182 inc(GTurn);3181 Inc(GTurn); 3183 3182 if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then 3184 3183 begin // already made extinct -- continue statistics … … 3219 3218 sBreak, sResign, sNextRound, sReload: 3220 3219 if Mode = moMovie then 3221 MovieStopped := true3220 MovieStopped := True 3222 3221 else 3223 3222 begin … … 3225 3224 begin 3226 3225 ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and 3227 ( integer(Data) >= 0) and (integer(Data) < GTurn);3226 (Integer(Data) >= 0) and (Integer(Data) < GTurn); 3228 3227 for p1 := 1 to nPl - 1 do 3229 3228 if bix[p1].Kind = btTerm then 3230 ok := false;3229 ok := False; 3231 3230 // allow reload in AI-only games only 3232 3231 end … … 3237 3236 if (Command = sBreak) or (Command = sResign) then 3238 3237 Notify(ntBackOn); 3239 for i:= 0 to Brains.Count - 1 do3240 if Brains[ i].Initialized then3238 for I := 0 to Brains.Count - 1 do 3239 if Brains[I].Initialized then 3241 3240 begin 3242 if Brains[ i].Kind = btAI then3243 Notify(ntDeinitModule, i);3244 CallClient( i, cBreakGame, nil^);3241 if Brains[I].Kind = btAI then 3242 Notify(ntDeinitModule, I); 3243 CallClient(I, cBreakGame, nil^); 3245 3244 end; 3246 3245 Notify(ntEndInfo); … … 3249 3248 LogCityTileChanges; 3250 3249 LogChanges; 3251 SaveGame(LogFileName, false);3250 SaveGame(LogFileName, False); 3252 3251 end; 3253 3252 DeleteFile(SavePath + '~' + LogFileName); … … 3262 3261 LandMass, MaxTurn); 3263 3262 sReload: 3264 LoadGame(SavePath, LogFileName, integer(Data), false);3263 LoadGame(SavePath, LogFileName, Integer(Data), False); 3265 3264 end; 3266 3265 end 3267 3266 else 3268 result := eInvalid;3267 Result := eInvalid; 3269 3268 end; 3270 3269 … … 3283 3282 end 3284 3283 else 3285 result := eInvalid;3284 Result := eInvalid; 3286 3285 3287 3286 scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact 3288 3287 - sExecute + (nPl - 1) shl 4: 3289 3288 if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then 3290 result := eInvalid3289 Result := eInvalid 3291 3290 else if GWinner > 0 then 3292 result := eViolation // game end reached3291 Result := eViolation // game end reached 3293 3292 else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then 3294 result := eNoPreq3293 Result := eNoPreq 3295 3294 else if GTurn < GColdWarStart + ColdWarTurns then 3296 result := eColdWar3295 Result := eColdWar 3297 3296 else if RW[Player].Government = gAnarchy then 3298 result := eAnarchy3297 Result := eAnarchy 3299 3298 else if RW[Command shr 4 and $F].Government = gAnarchy then 3300 3299 begin 3301 result := eAnarchy;3300 Result := eAnarchy; 3302 3301 LastEndClientCommand := scReject; // enable cancel treaty 3303 3302 pContacted := Command shr 4 and $F; … … 3307 3306 pContacted := Command shr 4 and $F; 3308 3307 pDipActive := pContacted; 3309 assert(Mode = moPlaying);3308 Assert(Mode = moPlaying); 3310 3309 Inform(pDipActive); 3311 3310 ChangeClientWhenDone(scContact, pDipActive, pTurn, 4); … … 3318 3317 begin // contact requested and not accepted yet 3319 3318 pDipActive := -1; 3320 assert(Mode = moPlaying);3319 Assert(Mode = moPlaying); 3321 3320 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3322 3321 end; 3323 3322 end 3324 3323 else 3325 result := eInvalid;3324 Result := eInvalid; 3326 3325 3327 3326 scDipStart, scDipStart - sExecute: … … 3334 3333 RW[pTurn].Credibility; 3335 3334 pDipActive := pTurn; 3336 assert(Mode = moPlaying);3335 Assert(Mode = moPlaying); 3337 3336 IntServer(sIntHaveContact, pTurn, pContacted, nil^); 3338 3337 ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0); … … 3340 3339 end 3341 3340 else 3342 result := eInvalid;3341 Result := eInvalid; 3343 3342 3344 3343 scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak, … … 3347 3346 if pDipActive >= 0 then 3348 3347 begin 3349 assert(Mode = moPlaying);3348 Assert(Mode = moPlaying); 3350 3349 if pDipActive = pTurn then 3351 3350 p1 := pContacted … … 3363 3362 // check if offer can be accepted 3364 3363 if nDeliver + nCost = 0 then 3365 result := eOfferNotAcceptable;3366 for i:= 0 to nDeliver + nCost - 1 do3367 if Price[ i] = opChoose then3368 result := eOfferNotAcceptable;3369 for i:= 0 to nCost - 1 do3370 if not PayPrice(pDipActive, p1, Price[nDeliver + i], false) then3371 result := eOfferNotAcceptable;3372 if (Command >= sExecute) and ( result >= rExecuted) then3364 Result := eOfferNotAcceptable; 3365 for I := 0 to nDeliver + nCost - 1 do 3366 if Price[I] = opChoose then 3367 Result := eOfferNotAcceptable; 3368 for I := 0 to nCost - 1 do 3369 if not PayPrice(pDipActive, p1, Price[nDeliver + I], False) then 3370 Result := eOfferNotAcceptable; 3371 if (Command >= sExecute) and (Result >= rExecuted) then 3373 3372 begin 3374 3373 IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive, … … 3377 3376 3378 3377 // tell other players about ship part trades 3379 HasShipChanged := false;3378 HasShipChanged := False; 3380 3379 FillChar(ShowShipChange, SizeOf(ShowShipChange), 0); 3381 for i:= 0 to nDeliver + nCost - 1 do3382 if Price[ i] and opMask = opShipParts then3380 for I := 0 to nDeliver + nCost - 1 do 3381 if Price[I] and opMask = opShipParts then 3383 3382 begin 3384 HasShipChanged := true;3385 if i>= nDeliver then3383 HasShipChanged := True; 3384 if I >= nDeliver then 3386 3385 begin // p1 has demanded from pDipActive 3387 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3388 + integer(Price[i] and $FFFF);3389 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3390 - integer(Price[i] and $FFFF);3386 ShowShipChange.Ship1Change[Price[I] shr 16 and 3] := 3387 +Integer(Price[I] and $FFFF); 3388 ShowShipChange.Ship2Change[Price[I] shr 16 and 3] := 3389 -Integer(Price[I] and $FFFF); 3391 3390 end 3392 3391 else 3393 3392 begin // p1 has delivered to pDipActive 3394 ShowShipChange.Ship1Change[Price[ i] shr 16 and 3] :=3395 - integer(Price[i] and $FFFF);3396 ShowShipChange.Ship2Change[Price[ i] shr 16 and 3] :=3397 + integer(Price[i] and $FFFF);3393 ShowShipChange.Ship1Change[Price[I] shr 16 and 3] := 3394 -Integer(Price[I] and $FFFF); 3395 ShowShipChange.Ship2Change[Price[I] shr 16 and 3] := 3396 +Integer(Price[I] and $FFFF); 3398 3397 end; 3399 3398 end; … … 3407 3406 (1 shl p2 and (GAlive or GWatching) <> 0) then 3408 3407 begin 3409 move(GShip, RW[p2].Ship, SizeOf(GShip));3408 Move(GShip, RW[p2].Ship, SizeOf(GShip)); 3410 3409 if 1 shl p2 and GWatching <> 0 then 3411 3410 CallPlayer(cShowShipChange, p2, ShowShipChange); … … 3420 3419 (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns) 3421 3420 then 3422 result := eCancelTreatyRush3421 Result := eCancelTreatyRush 3423 3422 else if Command >= sExecute then 3424 3423 begin … … 3427 3426 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3428 3427 begin 3429 i:= p1 shl 4 + pDipActive;3430 CallPlayer(cShowSupportAllianceAgainst, p2, i);3428 I := p1 shl 4 + pDipActive; 3429 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3431 3430 end; 3432 3431 for p2 := 0 to nPl - 1 do 3433 3432 if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then 3434 3433 begin 3435 i:= p2;3436 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);3434 I := p2; 3435 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I); 3437 3436 end; 3438 3437 end; 3439 3438 end 3440 3439 else 3441 result := eInvalid;3442 if (Command >= sExecute) and ( result >= rExecuted) then3440 Result := eInvalid; 3441 if (Command >= sExecute) and (Result >= rExecuted) then 3443 3442 if LastEndClientCommand = scDipBreak then 3444 3443 begin // break negotiation … … 3462 3461 end 3463 3462 else 3464 result := eInvalid;3463 Result := eInvalid; 3465 3464 3466 3465 scDipOffer, scDipOffer - sExecute: … … 3475 3474 pDipActive := -1; 3476 3475 CallPlayer(cShowEndContact, pContacted, nil^); 3477 assert(Mode = moPlaying);3476 Assert(Mode = moPlaying); 3478 3477 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3479 3478 end; … … 3488 3487 if RW[pDipActive].Treaty[p1] < trPeace then 3489 3488 begin // no tribute allowed! 3490 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3491 if (TOffer(Data).Price[ i] and opMask = opTribute) then3492 result := eInvalidOffer;3493 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3494 if (TOffer(Data).Price[ i] = opTreaty + trPeace) then3495 result := eOK;3489 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3490 if (TOffer(Data).Price[I] and opMask = opTribute) then 3491 Result := eInvalidOffer; 3492 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3493 if (TOffer(Data).Price[I] = opTreaty + trPeace) then 3494 Result := eOK; 3496 3495 end; 3497 for i:= 0 to TOffer(Data).nDeliver - 1 do3498 if (TOffer(Data).Price[ i] <> opChoose) and3499 not PayPrice(pDipActive, p1, TOffer(Data).Price[ i], false) then3500 result := eInvalidOffer;3496 for I := 0 to TOffer(Data).nDeliver - 1 do 3497 if (TOffer(Data).Price[I] <> opChoose) and 3498 not PayPrice(pDipActive, p1, TOffer(Data).Price[I], False) then 3499 Result := eInvalidOffer; 3501 3500 if CountPrice(TOffer(Data), opTreaty) > 1 then 3502 result := eInvalidOffer;3503 for i:= 0 to nShipPart - 1 do3504 if CountPrice(TOffer(Data), opShipParts + ishl 16) > 1 then3505 result := eInvalidOffer;3501 Result := eInvalidOffer; 3502 for I := 0 to nShipPart - 1 do 3503 if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then 3504 Result := eInvalidOffer; 3506 3505 if CountPrice(TOffer(Data), opMoney) > 1 then 3507 result := eInvalidOffer;3506 Result := eInvalidOffer; 3508 3507 if CountPrice(TOffer(Data), opTribute) > 1 then 3509 result := eInvalidOffer;3508 Result := eInvalidOffer; 3510 3509 case CountPrice(TOffer(Data), opChoose) of 3511 3510 0: … … 3513 3512 1: 3514 3513 if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then 3515 result := eInvalidOffer;3514 Result := eInvalidOffer; 3516 3515 else 3517 result := eInvalidOffer;3516 Result := eInvalidOffer; 3518 3517 end; 3519 3518 3520 3519 // !!! check here if cost can be demanded 3521 3520 3522 if (Command >= sExecute) and ( result >= rExecuted) then3521 if (Command >= sExecute) and (Result >= rExecuted) then 3523 3522 begin 3524 3523 OfferFullySupported := (TOffer(Data).nDeliver <= 2) and 3525 3524 (TOffer(Data).nCost <= 2); // >2 no more allowed 3526 for i:= 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do3525 for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do 3527 3526 begin 3528 if TOffer(Data).Price[ i] and opMask = opTribute then3529 OfferFullySupported := false;3527 if TOffer(Data).Price[I] and opMask = opTribute then 3528 OfferFullySupported := False; 3530 3529 // tribute no more part of the game 3531 if (TOffer(Data).Price[ i] and opMask = opTreaty) and3532 (TOffer(Data).Price[ i] - opTreaty <= RW[pDipActive].Treaty[p1])3530 if (TOffer(Data).Price[I] and opMask = opTreaty) and 3531 (TOffer(Data).Price[I] - opTreaty <= RW[pDipActive].Treaty[p1]) 3533 3532 then 3534 OfferFullySupported := false;3533 OfferFullySupported := False; 3535 3534 // agreed treaty end no more part of the game 3536 if TOffer(Data).Price[ i] = opTreaty + trCeaseFire then3537 OfferFullySupported := false;3535 if TOffer(Data).Price[I] = opTreaty + trCeaseFire then 3536 OfferFullySupported := False; 3538 3537 // ceasefire no more part of the game 3539 3538 end; … … 3560 3559 LastOffer := TOffer(Data); 3561 3560 // show offered things to receiver 3562 for i:= 0 to LastOffer.nDeliver - 1 do3563 ShowPrice(pDipActive, p1, LastOffer.Price[ i]);3561 for I := 0 to LastOffer.nDeliver - 1 do 3562 ShowPrice(pDipActive, p1, LastOffer.Price[I]); 3564 3563 pDipActive := p1; 3565 assert(Mode = moPlaying);3564 Assert(Mode = moPlaying); 3566 3565 ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer, 3567 3566 SizeOf(LastOffer)); 3568 end 3569 end 3567 end; 3568 end; 3570 3569 end 3571 3570 else 3572 result := eInvalid;3571 Result := eInvalid; 3573 3572 3574 3573 { … … 3583 3582 end 3584 3583 else 3585 result := eInvalid;3584 Result := eInvalid; 3586 3585 3587 3586 sSetTestFlag: … … 3593 3592 end 3594 3593 else 3595 result := eInvalid;3594 Result := eInvalid; 3596 3595 3597 3596 sSetGovernment, sSetGovernment - sExecute: … … 3599 3598 {$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF} 3600 3599 if RW[Player].Happened and phChangeGov = 0 then 3601 result := eViolation3600 Result := eViolation 3602 3601 else if RW[Player].Government = Subject then 3603 result := eNotChanged3602 Result := eNotChanged 3604 3603 else if (Subject >= nGov) then 3605 result := eInvalid3604 Result := eInvalid 3606 3605 else if (Subject >= gMonarchy) and 3607 3606 (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then 3608 result := eNoPreq3607 Result := eNoPreq 3609 3608 else if Command >= sExecute then 3610 3609 begin … … 3614 3613 then 3615 3614 RW[p1].EnemyReport[Player].Government := Subject; 3616 end 3615 end; 3617 3616 end; 3618 3617 … … 3621 3620 {$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF} 3622 3621 if Subject and $F + Subject shr 4 > 10 then 3623 result := eInvalid3622 Result := eInvalid 3624 3623 else if (RW[Player].TaxRate = Subject and $F * 10) and 3625 3624 (RW[Player].LuxRate = Subject shr 4 * 10) then 3626 result := eNotChanged3625 Result := eNotChanged 3627 3626 else if Command >= sExecute then 3628 3627 begin 3629 3628 RW[Player].TaxRate := Subject and $F * 10; 3630 3629 RW[Player].LuxRate := Subject shr 4 * 10; 3631 end 3630 end; 3632 3631 end; 3633 3632 … … 3636 3635 {$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF} 3637 3636 if RW[Player].Government = gAnarchy then 3638 result := eInvalid3637 Result := eInvalid 3639 3638 else 3640 3639 begin … … 3658 3657 if (Mode = moPlaying) and (Subject = adMilitary) and 3659 3658 (DevModelTurn[Player] <> GTurn) then 3660 result := eNoModel3659 Result := eNoModel 3661 3660 else if Subject <> adMilitary then 3662 3661 begin … … 3664 3663 begin 3665 3664 if Tech[Subject] >= MaxFutureTech_Computing then 3666 result := eInvalid;3665 Result := eInvalid; 3667 3666 end 3668 3667 else if Subject in FutureTech then 3669 3668 begin 3670 3669 if Tech[Subject] >= MaxFutureTech then 3671 result := eInvalid;3670 Result := eInvalid; 3672 3671 end 3673 3672 else if Tech[Subject] >= tsApplicable then 3674 result := eInvalid; // already discovered3673 Result := eInvalid; // already discovered 3675 3674 if Tech[Subject] <> tsSeen then // look if preqs met 3676 3675 if AdvPreq[Subject, 2] <> preNone then 3677 3676 begin // 2 of 3 required 3678 i:= 0;3679 for j:= 0 to 2 do3680 if Tech[AdvPreq[Subject, j]] >= tsApplicable then3681 inc(i);3682 if i< 2 then3683 result := eNoPreq;3677 I := 0; 3678 for J := 0 to 2 do 3679 if Tech[AdvPreq[Subject, J]] >= tsApplicable then 3680 Inc(I); 3681 if I < 2 then 3682 Result := eNoPreq; 3684 3683 end 3685 3684 else if (AdvPreq[Subject, 0] <> preNone) and … … 3687 3686 (AdvPreq[Subject, 1] <> preNone) and 3688 3687 (Tech[AdvPreq[Subject, 1]] < tsApplicable) then 3689 result := eNoPreq;3688 Result := eNoPreq; 3690 3689 end; 3691 if ( result = eOK) and (Command >= sExecute) then3690 if (Result = eOK) and (Command >= sExecute) then 3692 3691 begin 3693 3692 if (Mode = moPlaying) and (Subject = adMilitary) then … … 3698 3697 end 3699 3698 else 3700 result := eViolation;3699 Result := eViolation; 3701 3700 end; 3702 3701 … … 3706 3705 {$ENDIF} 3707 3706 if RW[Player].Happened and phStealTech = 0 then 3708 result := eInvalid3707 Result := eInvalid 3709 3708 else if (Subject >= nAdv) or (Subject in FutureTech) or 3710 3709 (RW[Player].Tech[Subject] >= tsSeen) or 3711 3710 (RW[GStealFrom].Tech[Subject] < tsApplicable) then 3712 result := eInvalid3711 Result := eInvalid 3713 3712 else if Command >= sExecute then 3714 3713 begin 3715 3714 SeeTech(Player, Subject); 3716 dec(RW[Player].Happened, phStealTech);3715 Dec(RW[Player].Happened, phStealTech); 3717 3716 end; 3718 3717 end; … … 3725 3724 if (Subject >= nAttitude) or (p1 >= nPl) or 3726 3725 (RW[Player].EnemyReport[p1] = nil) then 3727 result := eInvalid3726 Result := eInvalid 3728 3727 else if RW[Player].Treaty[p1] = trNoContact then 3729 result := eNoPreq3728 Result := eNoPreq 3730 3729 else if RW[Player].Attitude[p1] = Subject then 3731 result := eNotChanged3730 Result := eNotChanged 3732 3731 else if Command >= sExecute then 3733 3732 begin … … 3740 3739 if (LastEndClientCommand <> scReject) or 3741 3740 (RW[Player].Treaty[pContacted] < trPeace) then 3742 result := eInvalid3741 Result := eInvalid 3743 3742 else if (ServerVersion[Player] >= $010100) and 3744 3743 (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns) 3745 3744 then 3746 result := eCancelTreatyRush3745 Result := eCancelTreatyRush 3747 3746 else if Command >= sExecute then 3748 3747 begin … … 3752 3751 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3753 3752 begin 3754 i:= pContacted shl 4 + Player;3755 CallPlayer(cShowSupportAllianceAgainst, p2, i);3753 I := pContacted shl 4 + Player; 3754 CallPlayer(cShowSupportAllianceAgainst, p2, I); 3756 3755 end; 3757 3756 for p2 := 0 to nPl - 1 do 3758 3757 if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then 3759 3758 begin 3760 i:= p2;3761 CallPlayer(cShowCancelTreatyByAlliance, Player, i);3759 I := p2; 3760 CallPlayer(cShowCancelTreatyByAlliance, Player, I); 3762 3761 end; 3763 3762 LastEndClientCommand := sTurn; … … 3772 3771 {$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF} 3773 3772 if Subject >= 4 then 3774 result := eInvalid3773 Result := eInvalid 3775 3774 else if (upgrade[Subject, 0].Preq <> preNone) and 3776 3775 (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then 3777 result := eNoPreq3776 Result := eNoPreq 3778 3777 else if Command >= sExecute then 3779 3778 begin … … 3786 3785 Upgrades := 0; 3787 3786 FutureMCost := 0; 3788 for i:= 0 to nUpgrade - 1 do3789 with upgrade[Domain, i] do3787 for I := 0 to nUpgrade - 1 do 3788 with upgrade[Domain, I] do 3790 3789 if (Preq = preNone) or (Preq >= 0) and 3791 3790 ((RW[Player].Tech[Preq] >= tsApplicable) or … … 3794 3793 if Preq in FutureTech then 3795 3794 begin 3796 j:= RW[Player].Tech[Preq];3797 inc(FutureMCost, j* Cost);3795 J := RW[Player].Tech[Preq]; 3796 Inc(FutureMCost, J * Cost); 3798 3797 end 3799 3798 else 3800 3799 begin 3801 j:= 1;3800 J := 1; 3802 3801 if Cost > MCost then 3803 3802 MCost := Cost; 3804 3803 end; 3805 inc(Upgrades, 1 shl i);3806 inc(MStrength, j* Strength);3807 inc(MTrans, j* Trans);3804 Inc(Upgrades, 1 shl I); 3805 Inc(MStrength, J * Strength); 3806 Inc(MTrans, J * Trans); 3808 3807 end; 3809 inc(MCost, FutureMCost);3808 Inc(MCost, FutureMCost); 3810 3809 FillChar(Cap, SizeOf(Cap), 0); 3811 3810 Cap[mcOffense] := 2; 3812 3811 Cap[mcDefense] := 1; 3813 for i:= 0 to nFeature - 1 do3814 with Feature[ i] do3812 for I := 0 to nFeature - 1 do 3813 with Feature[I] do 3815 3814 if (1 shl Domain and Domains <> 0) and 3816 3815 ((Preq = preNone) or (Preq = preSun) and 3817 3816 (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and 3818 (RW[Player].Tech[Preq] >= tsApplicable)) and ( iin AutoFeature)3817 (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature) 3819 3818 then 3820 Cap[ i] := 1;3819 Cap[I] := 1; 3821 3820 MaxWeight := 5; 3822 3821 if (WeightPreq7[Domain] <> preNA) and … … 3840 3839 {$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF} 3841 3840 if Subject >= nFeature then 3842 result := eInvalid3841 Result := eInvalid 3843 3842 else if DevModelTurn[Player] = GTurn then 3844 3843 begin … … 3846 3845 with RW[Player].DevModel do 3847 3846 if 1 shl Domain and Feature[Subject].Domains = 0 then 3848 result := eDomainMismatch3847 Result := eDomainMismatch 3849 3848 else if not((Feature[Subject].Preq = preNone) or 3850 3849 (Feature[Subject].Preq = preSun) and … … 3852 3851 (Feature[Subject].Preq >= 0) and 3853 3852 (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then 3854 result := eNoPreq3853 Result := eNoPreq 3855 3854 else 3856 3855 begin … … 3868 3867 MaxCap := 3; 3869 3868 if RW[Player].Tech[adSteel] >= tsApplicable then 3870 inc(MaxCap);3869 Inc(MaxCap); 3871 3870 end 3872 3871 else … … 3878 3877 if (NewCap < MinCap) or (NewCap > MaxCap) or 3879 3878 (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then 3880 result := eViolation3879 Result := eViolation 3881 3880 else if Command >= sExecute then 3882 3881 begin … … 3921 3920 end 3922 3921 else 3923 result := eNoModel;3922 Result := eNoModel; 3924 3923 end; 3925 3924 … … 3932 3931 {$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3933 3932 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3934 result := eInvalid3933 Result := eInvalid 3935 3934 else 3936 3935 begin 3937 result := eRemoved;3936 Result := eRemoved; 3938 3937 Loc0 := RW[Player].Un[Subject].Loc; 3939 3938 if RealMap[Loc0] and fCity <> 0 then { check utilize } … … 3947 3946 (Project and cpImp = 0) and 3948 3947 (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then 3949 result := eUtilized;3948 Result := eUtilized; 3950 3949 if Command >= sExecute then 3951 3950 begin 3952 if result = eUtilized then3951 if Result = eUtilized then 3953 3952 begin 3954 3953 with RW[Player].Un[Subject] do 3955 3954 begin 3956 Cost := integer(RW[Player].Model[mix].Cost) * Health *3955 Cost := Integer(RW[Player].Model[mix].Cost) * Health * 3957 3956 BuildCostMod[Difficulty[Player]] div 1200; 3958 3957 if RW[Player].Model[mix].Cap[mcLine] > 0 then … … 3960 3959 end; 3961 3960 if Project and (cpImp + cpIndex) = cpImp + imTrGoods then 3962 inc(RW[Player].Money, Cost)3961 Inc(RW[Player].Money, Cost) 3963 3962 else 3964 3963 begin 3965 inc(Prod, Cost * 2 div 3);3964 Inc(Prod, Cost * 2 div 3); 3966 3965 Project0 := Project0 and not cpCompleted; 3967 3966 if Project0 and not cpAuto <> Project and not cpAuto then … … 3983 3982 {$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 3984 3983 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 3985 result := eInvalid3984 Result := eInvalid 3986 3985 else 3987 3986 begin 3988 3987 Loc0 := RW[Player].Un[Subject].Loc; 3989 3988 if RealMap[Loc0] and fCity = 0 then 3990 result := eInvalid3989 Result := eInvalid 3991 3990 else 3992 3991 begin 3993 3992 SearchCity(Loc0, Player, cix1); 3994 3993 if RW[Player].City[cix1].Flags and chCaptured <> 0 then 3995 result := eViolation3994 Result := eViolation 3996 3995 else if Command >= sExecute then 3997 3996 RW[Player].Un[Subject].Home := cix1; … … 4010 4009 {$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4011 4010 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4012 result := eInvalid4011 Result := eInvalid 4013 4012 else 4014 result := LoadUnit(Player, Subject, Command < sExecute);4013 Result := LoadUnit(Player, Subject, Command < sExecute); 4015 4014 end; 4016 4015 … … 4019 4018 {$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4020 4019 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4021 result := eInvalid4020 Result := eInvalid 4022 4021 else 4023 result := UnloadUnit(Player, Subject, Command < sExecute);4022 Result := UnloadUnit(Player, Subject, Command < sExecute); 4024 4023 end; 4025 4024 4026 4025 sSelectTransport, sSelectTransport - sExecute: 4027 4026 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4028 result := eInvalid4027 Result := eInvalid 4029 4028 else 4030 4029 with RW[Player].Model[RW[Player].Un[Subject].mix] do 4031 4030 begin 4032 4031 if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then 4033 result := eInvalid4032 Result := eInvalid 4034 4033 else if Command >= sExecute then 4035 4034 uixSelectedTransport := Subject; … … 4042 4041 begin 4043 4042 p1 := Command shr 4 and $F; 4044 Loc1 := integer(Data);4043 Loc1 := Integer(Data); 4045 4044 if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or 4046 4045 (RealMap[Loc1] and fCity <> 0) and 4047 4046 (RealMap[Loc1] shr 27 <> Cardinal(p1)) or 4048 4047 (RW[p1].Model[Subject].Domain < dAir) and 4049 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[ integer(Data)] and4048 ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and 4050 4049 fTerrain < fGrass)) then 4051 result := eViolation4050 Result := eViolation 4052 4051 else if Command >= sExecute then 4053 4052 begin 4054 4053 CreateUnit(p1, Subject); 4055 RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);4054 RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data); 4056 4055 PlaceUnit(p1, RW[p1].nUn - 1); 4057 UpdateUnitMap( integer(Data));4056 UpdateUnitMap(Integer(Data)); 4058 4057 end; 4059 4058 end 4060 4059 else 4061 result := eInvalid;4060 Result := eInvalid; 4062 4061 4063 4062 sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16, … … 4076 4075 {$IFDEF TEXTLOG}CmdInfo := Format('MoveUnit P%d I%d Mod%d Loc%d (%d,%d)', [Player, Subject, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc, dx, dy]); {$ENDIF} 4077 4076 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4078 result := eInvalid4077 Result := eInvalid 4079 4078 else 4080 result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);4079 Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute); 4081 4080 end; 4082 4081 … … 4089 4088 {$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF} 4090 4089 if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then 4091 result := eInvalid4090 Result := eInvalid 4092 4091 else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind 4093 4092 in [mkSettler, mkSlaves]) and 4094 4093 (RW[Player].Un[Subject].Flags and unConscripts = 0) then 4095 result := eViolation4094 Result := eViolation 4096 4095 else 4097 4096 begin 4098 4097 Loc0 := RW[Player].Un[Subject].Loc; 4099 4098 if RealMap[Loc0] and fCity = 0 then 4100 result := eInvalid4099 Result := eInvalid 4101 4100 else 4102 4101 begin … … 4104 4103 with RW[Player].City[cix1] do 4105 4104 if not CanCityGrow(Player, cix1) then 4106 result := eMaxSize4105 Result := eMaxSize 4107 4106 else if Command >= sExecute then 4108 4107 begin { add to city } … … 4124 4123 begin 4125 4124 Loc0 := RW[Player].Un[Subject].Loc; 4126 i:= Command shr 4 and $3F; // new job4127 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, i]); {$ENDIF}4125 I := Command shr 4 and $3F; // new job 4126 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, I]); {$ENDIF} 4128 4127 if (Subject >= RW[Player].nUn) or (Loc0 < 0) then 4129 result := eInvalid4130 else if i>= nJob then4131 result := eInvalid4128 Result := eInvalid 4129 else if I >= nJob then 4130 Result := eInvalid 4132 4131 else 4133 4132 begin 4134 result := StartJob(Player, Subject, i, Command < sExecute);4135 if result = eCity then4133 Result := StartJob(Player, Subject, I, Command < sExecute); 4134 if Result = eCity then 4136 4135 begin // new city 4137 4136 cix1 := RW[Player].nCity - 1; … … 4158 4157 sSetCityProject, sSetCityProject - sExecute: 4159 4158 begin 4160 NewProject := integer(Data) and not cpAuto;4159 NewProject := Integer(Data) and not cpAuto; 4161 4160 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF} 4162 4161 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4163 4162 then 4164 result := eInvalid4163 Result := eInvalid 4165 4164 else 4166 4165 with RW[Player].City[Subject] do 4167 4166 begin 4168 4167 if NewProject = Project then 4169 result := eNotChanged4168 Result := eNotChanged 4170 4169 else 4171 4170 begin … … 4175 4174 begin 4176 4175 if NewProject and cpIndex >= RW[Player].nModel then 4177 result := eInvalid4176 Result := eInvalid 4178 4177 else if (NewProject and cpConscripts <> 0) and 4179 4178 not((RW[Player].Tech[adConscription] >= tsApplicable) and … … 4181 4180 and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout)) 4182 4181 then 4183 result := eViolation4182 Result := eViolation 4184 4183 // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves) 4185 4184 // and (GWonder[woPyramids].EffectiveOwner<>Player) then … … 4187 4186 end 4188 4187 else if NewProject and cpIndex >= nImp then 4189 result := eInvalid4188 Result := eInvalid 4190 4189 else 4191 4190 begin 4192 4191 Preq := Imp[NewProject and cpIndex].Preq; 4193 for i:= 0 to nImpReplacement - 1 do4194 if (ImpReplacement[ i].OldImp = NewProject and cpIndex) and4195 (built[ImpReplacement[ i].NewImp] > 0) then4196 result := eObsolete;4197 if result = eObsolete then4192 for I := 0 to nImpReplacement - 1 do 4193 if (ImpReplacement[I].OldImp = NewProject and cpIndex) and 4194 (built[ImpReplacement[I].NewImp] > 0) then 4195 Result := eObsolete; 4196 if Result = eObsolete then 4198 4197 else if Preq = preNA then 4199 result := eInvalid4198 Result := eInvalid 4200 4199 else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable) 4201 4200 then 4202 result := eNoPreq4201 Result := eNoPreq 4203 4202 else if built[NewProject and cpIndex] > 0 then 4204 result := eInvalid4203 Result := eInvalid 4205 4204 else if (NewProject and cpIndex < nWonder) and 4206 4205 (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then 4207 result := eViolation // wonder already exists4206 Result := eViolation // wonder already exists 4208 4207 else if (NewProject and cpIndex = imSpacePort) and 4209 4208 (RW[Player].NatBuilt[imSpacePort] > 0) then 4210 result := eViolation // space port already exists4209 Result := eViolation // space port already exists 4211 4210 else if (NewProject = cpImp + imBank) and (built[imMarket] = 0) 4212 4211 or (NewProject = cpImp + imUniversity) and … … 4214 4213 (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant) 4215 4214 and (built[imFactory] = 0) then 4216 result := eNoPreq;4215 Result := eNoPreq; 4217 4216 case NewProject - cpImp of 4218 4217 woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform: … … 4225 4224 if (Loc1 >= 0) and (Loc1 < MapSize) and 4226 4225 (RealMap[Loc1] and fTerrain = fShore) then 4227 inc(Preq);4226 Inc(Preq); 4228 4227 end; 4229 4228 if Preq = 0 then 4230 result := eNoPreq;4229 Result := eNoPreq; 4231 4230 end; 4232 4231 woHoover, imHydro: … … 4240 4239 ((RealMap[Loc1] and fTerrain = fMountains) or 4241 4240 (RealMap[Loc1] and fRiver <> 0)) then 4242 inc(Preq);4241 Inc(Preq); 4243 4242 end; 4244 4243 if Preq = 0 then 4245 result := eNoPreq;4244 Result := eNoPreq; 4246 4245 end; 4247 4246 woMIR, imShipComp, imShipPow, imShipHab: 4248 4247 if RW[Player].NatBuilt[imSpacePort] = 0 then 4249 result := eNoPreq;4248 Result := eNoPreq; 4250 4249 end; 4251 4250 if (GTestFlags and tfNoRareNeed = 0) and 4252 4251 (Imp[NewProject and cpIndex].Kind = ikShipPart) then 4253 4252 if RW[Player].Tech[adMassProduction] < tsApplicable then 4254 result := eNoPreq4253 Result := eNoPreq 4255 4254 else 4256 4255 begin // check for rare resources 4257 4256 if NewProject and cpIndex = imShipComp then 4258 j:= 14257 J := 1 4259 4258 else if NewProject and cpIndex = imShipPow then 4260 j:= 24259 J := 2 4261 4260 else { if NewProject and cpIndex=imShipHab then } 4262 j:= 3;4261 J := 3; 4263 4262 // j = rare resource required 4264 4263 Preq := 0; … … 4268 4267 Loc1 := Radius[V21]; 4269 4268 if (Loc1 >= 0) and (Loc1 < MapSize) and 4270 (RealMap[Loc1] shr 25 and 3 = Cardinal( j)) then4271 inc(Preq);4269 (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then 4270 Inc(Preq); 4272 4271 end; 4273 4272 if Preq = 0 then 4274 result := eNoPreq;4273 Result := eNoPreq; 4275 4274 end; 4276 4275 end; 4277 4276 4278 if (Command >= sExecute) and ( result >= rExecuted) then4277 if (Command >= sExecute) and (Result >= rExecuted) then 4279 4278 begin 4280 4279 if pt0 <> ptSelect then … … 4285 4284 and (pt0 <> ptCaravan) then 4286 4285 begin 4287 inc(RW[Player].Money, Prod0);4286 Inc(RW[Player].Money, Prod0); 4288 4287 Prod := 0; 4289 4288 Prod0 := 0; … … 4292 4291 else 4293 4292 Prod := Prod0 * 2 div 3; 4294 Project := NewProject 4293 Project := NewProject; 4295 4294 end; 4296 4295 end; … … 4303 4302 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4304 4303 then 4305 result := eInvalid4304 Result := eInvalid 4306 4305 else 4307 4306 with RW[Player].City[Subject] do 4308 4307 if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0) 4309 4308 then 4310 result := eOutOfControl4309 Result := eOutOfControl 4311 4310 else if (Project and cpImp <> 0) and 4312 4311 ((Project and cpIndex = imTrGoods) or 4313 4312 (Imp[Project and cpIndex].Kind = ikShipPart)) then 4314 result := eInvalid // don't buy colony ship4313 Result := eInvalid // don't buy colony ship 4315 4314 else 4316 4315 begin … … 4331 4330 Cost := Cost * 4; 4332 4331 if Cost <= 0 then 4333 result := eNotChanged4332 Result := eNotChanged 4334 4333 else if Cost > RW[Player].Money then 4335 result := eViolation4334 Result := eViolation 4336 4335 else if Command >= sExecute then 4337 4336 IntServer(sIntBuyMaterial, Player, Subject, Cost); … … 4346 4345 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4347 4346 then 4348 result := eInvalid4347 Result := eInvalid 4349 4348 else if Command >= sExecute then 4350 4349 with RW[Player].City[Subject] do 4351 4350 begin 4352 inc(RW[Player].Money, Prod0);4351 Inc(RW[Player].Money, Prod0); 4353 4352 Prod := 0; 4354 4353 Prod0 := 0; … … 4358 4357 sSellCityImprovement, sSellCityImprovement - sExecute: 4359 4358 begin 4360 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}4359 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF} 4361 4360 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4362 4361 then 4363 result := eInvalid4362 Result := eInvalid 4364 4363 else 4365 4364 with RW[Player].City[Subject] do 4366 if built[ integer(Data)] = 0 then4367 result := eInvalid4365 if built[Integer(Data)] = 0 then 4366 Result := eInvalid 4368 4367 else if (RW[Player].Government = gAnarchy) or 4369 4368 (Flags and chCaptured <> 0) then 4370 result := eOutOfControl4369 Result := eOutOfControl 4371 4370 else if Flags and chImprovementSold <> 0 then 4372 result := eOnlyOnce4371 Result := eOnlyOnce 4373 4372 else if Command >= sExecute then 4374 4373 begin 4375 inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod4374 Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod 4376 4375 [Difficulty[Player]] div 12); 4377 built[ integer(Data)] := 0;4378 if Imp[ integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then4376 built[Integer(Data)] := 0; 4377 if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then 4379 4378 begin 4380 RW[Player].NatBuilt[ integer(Data)] := 0;4381 case integer(Data) of4379 RW[Player].NatBuilt[Integer(Data)] := 0; 4380 case Integer(Data) of 4382 4381 imGrWall: 4383 4382 GrWallContinent[Player] := -1; … … 4386 4385 end; 4387 4386 end; 4388 inc(Flags, chImprovementSold);4387 Inc(Flags, chImprovementSold); 4389 4388 end; 4390 4389 end; … … 4392 4391 sRebuildCityImprovement, sRebuildCityImprovement - sExecute: 4393 4392 begin 4394 OldImp := integer(Data);4393 OldImp := Integer(Data); 4395 4394 {$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF} 4396 4395 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4397 4396 then 4398 result := eInvalid4397 Result := eInvalid 4399 4398 else 4400 4399 begin 4401 4400 if (OldImp < 0) or (OldImp >= nImp) or 4402 4401 not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then 4403 result := eInvalid4402 Result := eInvalid 4404 4403 else 4405 4404 with RW[Player].City[Subject] do … … 4407 4406 not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal, 4408 4407 ikNatGlobal]) then 4409 result := eInvalid4408 Result := eInvalid 4410 4409 else if (RW[Player].Government = gAnarchy) or 4411 4410 (Flags and chCaptured <> 0) then 4412 result := eOutOfControl4411 Result := eOutOfControl 4413 4412 else if Flags and chImprovementSold <> 0 then 4414 result := eOnlyOnce4413 Result := eOnlyOnce 4415 4414 else if Command >= sExecute then 4416 4415 begin 4417 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]4416 Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]] 4418 4417 div 12 * 2 div 3); 4419 4418 Project0 := Project0 and not cpCompleted; … … 4432 4431 end; 4433 4432 end; 4434 inc(Flags, chImprovementSold);4433 Inc(Flags, chImprovementSold); 4435 4434 end; 4436 4435 end; … … 4439 4438 sSetCityTiles, sSetCityTiles - sExecute: 4440 4439 begin 4441 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}4440 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF} 4442 4441 if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0) 4443 4442 then 4444 result := eInvalid4443 Result := eInvalid 4445 4444 else 4446 result := SetCityTiles(Player, Subject, integer(Data),4445 Result := SetCityTiles(Player, Subject, Integer(Data), 4447 4446 Command < sExecute); 4448 4447 end; … … 4461 4460 end 4462 4461 else 4463 result := eUnknown;4462 Result := eUnknown; 4464 4463 end; { case command } 4465 4464 4466 4465 // do not log invalid and non-relevant commands 4467 if result = eZOC_EnemySpotted then4466 if Result = eZOC_EnemySpotted then 4468 4467 begin 4469 assert(Mode = moPlaying);4468 Assert(Mode = moPlaying); 4470 4469 CL.State := FormerCLState; 4471 4470 IntServer(sIntDiscoverZOC, Player, 0, ZOCTile); 4472 4471 end 4473 else if result and rEffective = 0 then4472 else if Result and rEffective = 0 then 4474 4473 if Mode < moPlaying then 4475 4474 begin 4476 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [ result]) + CmdInfo;4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo; 4477 4476 {$ENDIF} 4478 LoadOK := false;4477 LoadOK := False; 4479 4478 end 4480 4479 else … … 4482 4481 if logged then 4483 4482 CL.State := FormerCLState; 4484 if ( result < rExecuted) and (Command >= sExecute) then4483 if (Result < rExecuted) and (Command >= sExecute) then 4485 4484 PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)', 4486 4485 [Player, Command, Subject])); … … 4488 4487 4489 4488 if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient) 4490 and ( result >= rExecuted) then4489 and (Result >= rExecuted) then 4491 4490 LastEndClientCommand := Command; 4492 {$IFOPT O-} dec(nHandoverStack, 2); {$ENDIF}4493 end; { <<<server }4491 {$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF} 4492 end; 4494 4493 4495 4494
Note:
See TracChangeset
for help on using the changeset viewer.