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