- Timestamp:
- May 8, 2018, 4:37:34 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Direct.pas
r112 r143 53 53 procedure TDirectDlg.DlgNotify(ID: integer); 54 54 var 55 hMem: Cardinal;56 p: pointer;55 // hMem: Cardinal; 56 // p: pointer; 57 57 s: string; 58 58 begin … … 71 71 begin 72 72 s := Format(Phrases.Lookup('BUSY_MOD'), 73 [Brain [ID - ntInitModule].Name]);73 [Brains[ID - ntInitModule].Name]); 74 74 while BiColorTextWidth(Canvas, s) + 64 > ClientWidth do 75 75 Delete(s, Length(s), 1); … … 98 98 ntDLLError .. ntDLLError + 128: 99 99 SimpleMessage(Format(Phrases.Lookup('DLLERROR'), 100 [Brain [ID - ntDLLError].FileName]));100 [Brains[ID - ntDLLError].FileName])); 101 101 ntAIError: 102 102 SimpleMessage(Format(Phrases.Lookup('AIERROR'), [NotifyMessage])); 103 103 ntClientError .. ntClientError + 128: 104 104 SimpleMessage(Format(Phrases.Lookup('CLIENTERROR'), 105 [Brain [ID - ntClientError].FileName]));105 [Brains[ID - ntClientError].FileName])); 106 106 ntEndInfo: 107 107 begin … … 157 157 begin 158 158 Info := Format(Phrases2.Lookup('BUSY_DEINIT'), 159 [Brain [ID - ntDeinitModule].Name]);159 [Brains[ID - ntDeinitModule].Name]); 160 160 while BiColorTextWidth(Canvas, Info) + 64 > ClientWidth do 161 161 Delete(Info, Length(Info), 1); … … 183 183 Info := ''; 184 184 GameServer.Init(Notify); 185 Brain [bixNoTerm].Client := NoTerm.Client;186 Brain [bixSuper_Virtual].Client := nil;187 Brain [bixTerm].Client := LocalPlayer.Client;188 Brain [bixNoTerm].Name := Phrases.Lookup('AIT');189 Brain [bixSuper_Virtual].Name := Phrases.Lookup('SUPER');190 Brain [bixTerm].Name := Phrases.Lookup('HUMAN');191 Brain [bixRandom].Name := Phrases.Lookup('RANDOMAI');185 BrainNoTerm.Client := NoTerm.Client; 186 BrainNoTerm.Name := Phrases.Lookup('AIT'); 187 BrainSuperVirtual.Client := nil; 188 BrainSuperVirtual.Name := Phrases.Lookup('SUPER'); 189 BrainTerm.Client := LocalPlayer.Client; 190 BrainTerm.Name := Phrases.Lookup('HUMAN'); 191 BrainRandom.Name := Phrases.Lookup('RANDOMAI'); 192 192 Canvas.Font.Assign(UniFont[ftNormal]); 193 193 Canvas.Brush.Style := bsClear; … … 214 214 begin 215 215 Hide; 216 if nBrain= 3 then216 if Brains.Count = 3 then 217 217 begin 218 218 Application.MessageBox(PChar(Phrases.Lookup('NOAI')), 'C-evo', 0); … … 268 268 begin 269 269 Application.MessageBox(PChar(Format(Phrases.Lookup('AIEXCEPTION'), 270 [Brain [Msg.WParam].Name])), 'C-evo', 0);270 [Brains[Msg.WParam].Name])), 'C-evo', 0); 271 271 end; 272 272 -
trunk/GameServer.pas
r133 r143 7 7 8 8 uses 9 Protocol, Database, dynlibs, Platform, dateutils ;9 Protocol, Database, dynlibs, Platform, dateutils, fgl, FileUtil, Graphics; 10 10 11 11 const … … 50 50 51 51 maxBrain = 255; 52 bixNoTerm = 0;53 bixSuper_Virtual = 1;54 bixTerm = 2;55 bixRandom = 3;56 bixFirstAI = 4;57 52 58 53 type 59 54 TNotifyFunction = procedure(ID: integer); 60 55 61 TBrainInfo = record 62 FileName, DLLName, Name, Credits: string; { filename and full name } 56 TBrainType = (btNoTerm, btSuperVirtual, btTerm, btRandom, btAI); 57 58 { TBrain } 59 60 TBrain = class 61 FileName: string; 62 DLLName: string; 63 Name: string; 64 Credits: string; { filename and full name } 63 65 hm: TLibHandle; { module handle } 64 Flags, ServerVersion, DataVersion, DataSize: integer; 66 Flags: Integer; 67 ServerVersion: Integer; 68 DataVersion: Integer; 69 DataSize: Integer; 65 70 Client: TClientCall; { client function address } 66 Initialized: boolean; 71 Initialized: Boolean; 72 Kind: TBrainType; 73 Picture: TBitmap; 74 procedure LoadFromFile(AIFileName: string); 75 constructor Create; 76 destructor Destroy; override; 77 end; 78 79 { TBrains } 80 81 TBrains = class(TFPGObjectList<TBrain>) 82 function AddNew: TBrain; 83 function GetKindCount(Kind: TBrainType): Integer; 84 procedure GetByKind(Kind: TBrainType; Brains: TBrains); 67 85 end; 68 86 … … 75 93 // READ ONLY 76 94 DotNetClient: TClientCall; 77 bixBeginner, // AI to use for beginner level 78 nBrain: integer; { number of brains available } 79 Brain: array [-1 .. maxBrain - 1] of TBrainInfo; { available brains } 95 Brains: TBrains; // { available brains } 80 96 NotifyMessage: string; 97 98 BrainNoTerm: TBrain; 99 BrainSuperVirtual: TBrain; 100 BrainTerm: TBrain; 101 BrainRandom: TBrain; 102 BrainBeginner: TBrain; // AI to use for beginner level 81 103 82 104 procedure Init(NotifyFunction: TNotifyFunction); … … 145 167 HandoverStack[nHandoverStack + 1] := Command; 146 168 inc(nHandoverStack, 2); 147 Brain [bix[p]].Client(Command, p, Data);169 Brains[bix[p]].Client(Command, p, Data); 148 170 dec(nHandoverStack, 2); 149 171 {$ELSE} … … 165 187 HandoverStack[nHandoverStack + 1] := Command; 166 188 inc(nHandoverStack, 2); 167 Brain [bix].Client(Command, -1, Data);189 Brains[bix].Client(Command, -1, Data); 168 190 dec(nHandoverStack, 2); 169 191 {$ELSE} … … 179 201 procedure Init(NotifyFunction: TNotifyFunction); 180 202 var 181 i: integer;182 203 f: TSearchRec; 183 T: TextFile;184 s: string;185 Key: string;186 Value: string;187 204 BasePath: string; 188 AIFileName: string;205 NewBrain: TBrain; 189 206 begin 190 207 Notify := NotifyFunction; … … 192 209 193 210 { get available brains } 194 Brain[bixNoTerm].FileName := ':AIT'; 195 Brain[bixNoTerm].Flags := 0; 196 Brain[bixNoTerm].Initialized := false; 197 Brain[bixSuper_Virtual].FileName := ':Supervisor'; 198 Brain[bixSuper_Virtual].Flags := 0; 199 Brain[bixSuper_Virtual].Initialized := false; 200 Brain[bixTerm].FileName := ':StdIntf'; 201 Brain[bixTerm].Flags := fMultiple; 202 Brain[bixTerm].Initialized := false; 203 Brain[bixTerm].ServerVersion := Version; 204 Brain[bixRandom].FileName := ':Random'; 205 Brain[bixRandom].Flags := fMultiple; 206 Brain[bixRandom].Initialized := false; 207 nBrain := bixFirstAI; 208 bixBeginner := bixFirstAI; 211 Brains := TBrains.Create; 212 BrainNoTerm := Brains.AddNew; 213 BrainNoTerm.FileName := ':AIT'; 214 BrainNoTerm.Flags := 0; 215 BrainNoTerm.Initialized := false; 216 BrainNoTerm.Kind := btNoTerm; 217 BrainSuperVirtual := Brains.AddNew; 218 BrainSuperVirtual.FileName := ':Supervisor'; 219 BrainSuperVirtual.Flags := 0; 220 BrainSuperVirtual.Initialized := false; 221 BrainSuperVirtual.Kind := btSuperVirtual; 222 BrainTerm := Brains.AddNew; 223 BrainTerm.FileName := ':StdIntf'; 224 BrainTerm.Flags := fMultiple; 225 BrainTerm.Initialized := false; 226 BrainTerm.ServerVersion := Version; 227 BrainTerm.Kind := btTerm; 228 BrainRandom := Brains.AddNew; 229 BrainRandom.FileName := ':Random'; 230 BrainRandom.Flags := fMultiple; 231 BrainRandom.Initialized := false; 232 BrainRandom.Kind := btRandom; 233 234 BrainBeginner := nil; 235 209 236 if FindFirst(HomeDir + 'AI' + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then 210 237 repeat 211 238 BasePath := HomeDir + 'AI' + DirectorySeparator + f.Name; 212 239 if (f.Name <> '.') and (f.Name <> '..') and DirectoryExists(BasePath) then begin 213 with Brain[nBrain] do begin 214 FileName := f.Name; 215 DLLName := BasePath + DirectorySeparator + FileName + '.dll'; 216 AIFileName := BasePath + DirectorySeparator + f.Name + '.ai.txt'; 217 Name := f.Name; 218 Credits := ''; 219 Flags := fMultiple; 220 Client := nil; 221 Initialized := false; 222 ServerVersion := 0; 223 if not FileExists(AIFileName) then 224 raise Exception.Create(Format('AI specification file %s not found', [AIFileName])); 225 AssignFile(T, AIFileName); 226 Reset(T); 227 while not EOF(T) do 228 begin 229 ReadLn(T, s); 230 s := trim(s); 231 if Pos(' ', S) > 0 then begin 232 Key := Copy(S, 1, Pos(' ', S) - 1); 233 Value := Trim(Copy(S, Pos(' ', S) + 1, Length(S))); 234 end else begin 235 Key := S; 236 Value := ''; 237 end; 238 if Key = '#NAME' then 239 Name := Value 240 else if Key = '#.NET' then 241 Flags := Flags or fDotNet 242 else if Key = '#BEGINNER' then 243 bixBeginner := nBrain 244 else if Key = '#PATH' then 245 DLLName := BasePath + DirectorySeparator + Value 246 {$IFDEF WINDOWS}{$IFDEF CPU32} 247 else if Key = '#PATH_WIN32' then 248 DLLName := BasePath + DirectorySeparator + Value 249 {$ENDIF}{$ENDIF} 250 {$IFDEF WINDOWS}{$IFDEF CPU64} 251 else if Key = '#PATH_WIN64' then 252 DLLName := BasePath + DirectorySeparator + Value 253 {$ENDIF}{$ENDIF} 254 {$IFDEF LINUX}{$IFDEF CPU32} 255 else if Key = '#PATH_LINUX32' then 256 DLLName := BasePath + DirectorySeparator + Value 257 {$ENDIF}{$ENDIF} 258 {$IFDEF LINUX}{$IFDEF CPU64} 259 else if Key = '#PATH_LINUX64' then 260 DLLName := BasePath + DirectorySeparator + Value 261 {$ENDIF}{$ENDIF} 262 else if Key = '#GAMEVERSION' then 263 for i := 1 to Length(Value) do 264 case Value[i] of 265 '0' .. '9': 266 ServerVersion := ServerVersion and $FFFF00 + ServerVersion and 267 $FF * 10 + ord(Value[i]) - 48; 268 '.': 269 ServerVersion := ServerVersion shl 8; 270 end 271 else if Key = '#CREDITS' then 272 Credits := Value 273 end; 274 CloseFile(T); 275 end; 276 if (Brain[nBrain].ServerVersion >= FirstAICompatibleVersion) and 277 (Brain[nBrain].ServerVersion <= Version) and 278 ((Brain[nBrain].Flags and fDotNet = 0) or (@DotNetClient <> nil)) then 279 inc(nBrain); 240 NewBrain := Brains.AddNew; 241 NewBrain.Kind := btAI; 242 NewBrain.LoadFromFile(BasePath + DirectorySeparator + F.Name + '.ai.txt'); 243 if (NewBrain.ServerVersion >= FirstAICompatibleVersion) and 244 (NewBrain.ServerVersion <= Version) and 245 ((NewBrain.Flags and fDotNet = 0) or (@DotNetClient <> nil)) then begin 246 end else Brains.Delete(Brains.Count - 1); 280 247 end; 281 248 until FindNext(f) <> 0; 282 249 FindClose(F); 283 250 284 if nBrain= 0 then251 if Brains.GetKindCount(btAI) = 0 then 285 252 raise Exception.Create(Format('No AI libraries found in directory %s', [HomeDir + 'AI'])); 286 253 end; … … 288 255 procedure Done; 289 256 var 290 i: integer;257 I: Integer; 291 258 begin 292 for i := 0 to nBrain- 1 do293 if Brain[i].Initialized then294 begin295 CallClient( i, cReleaseModule, nil^);296 if ( i >= bixFirstAI) and (Brain[i].Flags and fDotNet= 0) then297 FreeLibrary( Brain[i].hm);259 for I := 0 to Brains.Count - 1 do 260 with Brains[I] do 261 if Initialized then begin 262 CallClient(I, cReleaseModule, nil^); 263 if (Kind = btAI) and ((Flags and fDotNet) = 0) then 264 FreeLibrary(hm); 298 265 end; 266 Brains.Free; 299 267 end; 300 268 … … 327 295 procedure PutMessage(Level: integer; Text: string); 328 296 begin 329 Brain [bix[0]].Client(cDebugMessage, Level, pchar(Text)^);297 Brains[bix[0]].Client(cDebugMessage, Level, pchar(Text)^); 330 298 end; 331 299 … … 362 330 LastClientTime := T; 363 331 PutMessage(1 shl 16 + 2, Format('CLIENT: calling %d (%s)', 364 [CCPlayer, Brain [bix[CCPlayer]].Name]));332 [CCPlayer, Brains[bix[CCPlayer]].Name])); 365 333 if CCCommand = cTurn then 366 334 for p := 0 to nPl - 1 do … … 371 339 CCPlayer := -1; 372 340 CallPlayer(CCCommand, p, CCData); 373 if (Mode = moPlaying) and (Brain [bix[p]].Flags and aiThreaded = 0) and341 if (Mode = moPlaying) and (Brains[bix[p]].Flags and aiThreaded = 0) and 374 342 (CCPlayer < 0) then 375 343 begin … … 449 417 end; 450 418 // log data changes 451 if Brain [bix[p]].DataSize > 0 then419 if Brains[bix[p]].DataSize > 0 then 452 420 begin 453 421 CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data, 454 Brain [bix[p]].DataSize);455 move(RW[p].Data^, SavedData[p]^, Brain [bix[p]].DataSize * 4);422 Brains[bix[p]].DataSize); 423 move(RW[p].Data^, SavedData[p]^, Brains[bix[p]].DataSize * 4); 456 424 end 457 425 end; … … 477 445 with RW[p].EnemyCity[ix] do 478 446 SavedStatus := Status; 479 if Brain [bix[p]].DataSize > 0 then480 move(RW[p].Data^, SavedData[p]^, Brain [bix[p]].DataSize * 4);447 if Brains[bix[p]].DataSize > 0 then 448 move(RW[p].Data^, SavedData[p]^, Brains[bix[p]].DataSize * 4); 481 449 end; 482 450 end; … … 507 475 result := true; 508 476 if RW[p].Data <> nil then 509 for ix := 0 to Brain [bix[p]].DataSize - 1 do477 for ix := 0 to Brains[bix[p]].DataSize - 1 do 510 478 if PDWortList(SavedData[p])[ix] <> PDWortList(RW[p].Data)[ix] then 511 479 result := true … … 516 484 InitModuleData: TInitModuleData; 517 485 begin 518 assert(bix <> bixSuper_Virtual); 519 with Brain[bix] do 520 begin 486 assert(Brains[bix].Kind <> btSuperVirtual); 487 with Brains[bix] do begin 521 488 if Initialized then 522 489 exit; 523 if bix >= bixFirstAI then490 if Kind = btAI then 524 491 begin { get client function } 525 492 Notify(ntInitModule + bix); … … 635 602 nLocal := 0; 636 603 for i := 0 to nPl - 1 do 637 if bix[i] = bixTermthen604 if (bix[i] <> -1) and (Brains[bix[i]].Kind = btTerm) then 638 605 inc(nLocal); 639 606 if Difficulty[0] = 0 then … … 683 650 else 684 651 begin 685 if bixView[i] >= bixRandomthen686 s := Brain [bix[i]].FileName687 else 688 s := Brain [bixView[i]].FileName;652 if Brains[bixView[i]].Kind in [btRandom, btAI] then 653 s := Brains[bix[i]].FileName 654 else 655 s := Brains[bixView[i]].FileName; 689 656 move(zero, s[Length(s) + 1], 4); 690 657 LogFile.write(s, (Length(s) div 4 + 1) * 4); … … 715 682 Path: shortstring; 716 683 BrainUsed: Set of 0 .. 254; { used brains } 684 AIBrains: TBrains; 717 685 begin 718 for p1 := 0 to nPl - 1 do 719 begin 720 if bixView[p1] = bixSuper_Virtual then 721 bix[p1] := bixTerm // supervisor and local human use same module 722 else if bixView[p1] = bixRandom then 723 if nBrain <= bixFirstAI then 686 for p1 := 0 to nPl - 1 do begin 687 if (bixView[p1] <> -1) and (Brains[bixView[p1]].Kind = btSuperVirtual) then 688 bix[p1] := Brains.IndexOf(BrainTerm) // supervisor and local human use same module 689 else if (bixView[p1] <> -1) and (Brains[bixView[p1]].Kind = btRandom) then 690 if Brains.GetKindCount(btAI) = 0 then 724 691 bix[p1] := -1 725 else 726 bix[p1] := bixFirstAI + Delphirandom(nBrain - bixFirstAI) 692 else begin 693 AIBrains := TBrains.Create(False); 694 bix[p1] := Brains.IndexOf(AIBrains[DelphiRandom(AIBrains.Count)]); 695 AIBrains.Free; 696 end 727 697 else 728 698 bix[p1] := bixView[p1]; … … 731 701 end; 732 702 733 if bix[0] <> bixNoTerm then703 if Brains[bix[0]].Kind <> btNoTerm then 734 704 Notify(ntInitLocalHuman); 735 705 BrainUsed := []; … … 737 707 if (bix[p] >= 0) and ((Mode <> moMovie) or (p = 0)) then 738 708 begin { initiate selected control module } 739 AIInfo[p] := Brain [bix[p]].Name + #0;709 AIInfo[p] := Brains[bix[p]].Name + #0; 740 710 InitBrain(bix[p]); 741 711 if Mode = moPlaying then 742 712 begin // new game, this data version is original 743 OriginalDataVersion[p] := Brain [bix[p]].DataVersion;713 OriginalDataVersion[p] := Brains[bix[p]].DataVersion; 744 714 ProcessClientData[p] := true; 745 715 end 746 716 else // loading game, compare with data version read from file 747 717 ProcessClientData[p] := ProcessClientData[p] and 748 (OriginalDataVersion[p] = Brain [bix[p]].DataVersion);749 if @Brain [bix[p]].Client = nil then // client function not found750 if bix[0] = bixNoTerm then718 (OriginalDataVersion[p] = Brains[bix[p]].DataVersion); 719 if @Brains[bix[p]].Client = nil then // client function not found 720 if Brains[bix[0]].Kind = btNoTerm then 751 721 bix[p] := -1 752 722 else 753 723 begin 754 bix[p] := bixTerm;724 bix[p] := Brains.IndexOf(BrainTerm); 755 725 OriginalDataVersion[p] := -1; 756 726 ProcessClientData[p] := false; … … 773 743 if Mode <> moMovie then 774 744 inc(GWatching, 1 shl p1); 775 if bix[p1] >= bixFirstAI then745 if Brains[bix[p1]].Kind = btAI then 776 746 inc(GAI, 1 shl p1); 777 747 if Difficulty[p1] > 0 then … … 780 750 inc(nAlive); 781 751 end; 782 ServerVersion[p1] := Brain [bix[p1]].ServerVersion;752 ServerVersion[p1] := Brains[bix[p1]].ServerVersion; 783 753 end; 784 WinOnAlone := ( bix[0] = bixNoTerm) and (nAlive > 1);754 WinOnAlone := (Brains[bix[0]].Kind = btNoTerm) and (nAlive > 1); 785 755 GWinner := 0; 786 756 GColdWarStart := -ColdWarTurns - 1; … … 817 787 OracleIncome := 0; 818 788 819 if Brain [bix[p]].DataSize > 0 then789 if Brains[bix[p]].DataSize > 0 then 820 790 begin 821 GetMem(SavedData[p], Brain [bix[p]].DataSize * 4);822 GetMem(Data, Brain [bix[p]].DataSize * 4);823 FillChar(SavedData[p]^, Brain [bix[p]].DataSize * 4, 0);824 FillChar(Data^, Brain [bix[p]].DataSize * 4, 0);791 GetMem(SavedData[p], Brains[bix[p]].DataSize * 4); 792 GetMem(Data, Brains[bix[p]].DataSize * 4); 793 FillChar(SavedData[p]^, Brains[bix[p]].DataSize * 4, 0); 794 FillChar(Data^, Brains[bix[p]].DataSize * 4, 0); 825 795 end 826 796 else … … 839 809 for i := 0 to nStat - 1 do 840 810 GetMem(Stat[i, p], 4 * (MaxTurn + 1)); 841 if Brain [bix[p]].Flags and fDotNet <> 0 then811 if Brains[bix[p]].Flags and fDotNet <> 0 then 842 812 begin 843 813 GetMem(RW[p].DefaultDebugMap, MapSize * 4); … … 865 835 Human := 0; 866 836 for p1 := 0 to nPl - 1 do 867 if bix[p1] = bixTerm then837 if Brains[bix[p1]].Kind = btTerm then 868 838 inc(Human, 1 shl p1); 869 839 InitMapGame(Human); … … 876 846 877 847 pTurn := -1; 878 if bix[0] <> bixNoTerm then848 if Brains[bix[0]].Kind <> btNoTerm then 879 849 Notify(ntInitLocalHuman); 880 850 Game.lx := lx; … … 887 857 // move(Difficulty,GameEx.Difficulty,SizeOf(Difficulty)); 888 858 AICredits := ''; 889 for i := 0 to nBrain - 1 do 890 if Brain[i].Initialized then 859 for i := 0 to Brains.Count - 1 do 860 with Brains[I] do begin 861 if Initialized then 891 862 if i in BrainUsed then 892 863 begin 893 if i >= bixFirstAI then864 if Kind = btAI then 894 865 Notify(ntInitPlayers); 895 866 for p := 0 to nPl - 1 do … … 899 870 else 900 871 Game.RO[p] := nil; 901 if ( i = bixTerm) and (Difficulty[0] = 0) and (bix[p] >= 0) then872 if (Kind = btTerm) and (Difficulty[0] = 0) and (bix[p] >= 0) then 902 873 Game.SuperVisorRO[p] := @RW[p] 903 874 else 904 875 Game.SuperVisorRO[p] := nil; 905 876 end; 906 if Brain[i].Flags and fDotNet > 0 then877 if Flags and fDotNet > 0 then 907 878 begin 908 Path := Brain[i].DLLName;879 Path := DLLName; 909 880 move(Path[1], Game.AssemblyPath, Length(Path)); 910 881 Game.AssemblyPath[Length(Path)] := #0; … … 920 891 CallClient(i, cNewGame, Game); 921 892 end; 922 if ( i >= bixFirstAI) and (Brain[i].Credits <> '') then893 if (Kind = btAI) and (Credits <> '') then 923 894 if AICredits = '' then 924 AICredits := Brain[i].Credits895 AICredits := Credits 925 896 else 926 AICredits := AICredits + '\' + Brain[i].Credits897 AICredits := AICredits + '\' + Credits; 927 898 end 928 899 else 929 900 begin { module no longer used -- unload } 930 901 CallClient(i, cReleaseModule, nil^); 931 if i >= bixFirstAI then902 if Kind = btAI then 932 903 begin 933 if Brain[i].Flags and fDotNet = 0 then934 FreeLibrary( Brain[i].hm);935 Brain[i].Client := nil;904 if Flags and fDotNet = 0 then 905 FreeLibrary(hm); 906 Client := nil; 936 907 end; 937 Brain[i].Initialized := false; 938 end; 908 Initialized := false; 909 end; 910 end; 939 911 AICredits := AICredits + #0; 940 912 941 if bix[0] <> bixNoTerm then913 if Brains[bix[0]].Kind <> btNoTerm then 942 914 begin 943 915 // uni ai? 944 916 bixUni := -1; 945 917 for p1 := 0 to nPl - 1 do 946 if bix[p1] >= bixFirstAIthen918 if (bix[p1] <> - 1) and (Brains[bix[p1]].Kind = btAI) then 947 919 if bixUni = -1 then 948 920 bixUni := bix[p1] … … 950 922 bixUni := -2; 951 923 for p1 := 0 to nPl - 1 do 952 if bix[p1] >= bixFirstAIthen924 if (bix[p1] <> -1) and (Brains[bix[p1]].Kind = btAI) then 953 925 begin 954 926 if bixUni = -2 then 955 NotifyMessage := Brain [bix[p1]].FileName927 NotifyMessage := Brains[bix[p1]].FileName 956 928 else 957 929 NotifyMessage := ''; … … 1159 1131 LogFile.read(d, 4); { behavior } 1160 1132 LogFile.read(Difficulty[p1], 4); 1161 j := nBrain- 1;1162 while (j >= 0) and (AnsiCompareFileName(Brain [j].FileName, s) <> 0) do1133 j := Brains.Count - 1; 1134 while (j >= 0) and (AnsiCompareFileName(Brains[j].FileName, s) <> 0) do 1163 1135 dec(j); 1164 1136 if j < 0 then … … 1167 1139 NotifyMessage := s; 1168 1140 Notify(ntAIError); 1169 j := bixTerm;1141 j := Brains.IndexOf(BrainTerm); 1170 1142 end 1171 1143 else 1172 1144 ProcessClientData[p1] := true; 1173 if j = bixNoTerm then1174 j := bixSuper_Virtual;1145 if Brains[j].Kind = btNoTerm then 1146 j := Brains.IndexOf(BrainSuperVirtual); 1175 1147 // crashed tournament -- load as supervisor 1176 1148 bixView[p1] := j; … … 1205 1177 if MovieMode then 1206 1178 begin 1207 Brain [bix[0]].Client(cShowGame, 0, nil^);1179 Brains[bix[0]].Client(cShowGame, 0, nil^); 1208 1180 Notify(ntBackOff); 1209 1181 end … … 1257 1229 {$IFDEF TEXTLOG}LoadPos0 := CL.State.LoadPos; {$ENDIF} 1258 1230 if ProcessClientData[p1] then 1259 CL.GetDataChanges(RW[p1].Data, Brain [bix[p1]].DataSize)1231 CL.GetDataChanges(RW[p1].Data, Brains[bix[p1]].DataSize) 1260 1232 else 1261 1233 CL.GetDataChanges(nil, 0); … … 1281 1253 begin 1282 1254 Notify(ntBackOn); 1283 Brain [bix[0]].Client(cBreakGame, -1, nil^);1255 Brains[bix[0]].Client(cBreakGame, -1, nil^); 1284 1256 EndGame; 1285 1257 Notify(ntStartGo); … … 1326 1298 Notify(ntLoadError); 1327 1299 end; 1328 Brain [bix[0]].Client(cShowGame, 0, nil^);1300 Brains[bix[0]].Client(cShowGame, 0, nil^); 1329 1301 Notify(ntBackOff); 1330 1302 Inform(pTurn); … … 1397 1369 nLogOpened := -1; 1398 1370 LastEndClientCommand := -1; 1399 Brain [bix[0]].Client(cShowGame, 0, nil^);1371 Brains[bix[0]].Client(cShowGame, 0, nil^); 1400 1372 Notify(ntBackOff); 1401 1373 Inform(pTurn); … … 1405 1377 procedure DirectHelp(Command: integer); 1406 1378 begin 1407 InitBrain( bixTerm);1408 Brain [bixTerm].Client(Command, -1, nil^);1379 InitBrain(Brains.IndexOf(BrainTerm)); 1380 BrainTerm.Client(Command, -1, nil^); 1409 1381 AICredits := #0; 1410 1382 end; … … 1422 1394 MapSize := lx * ly; 1423 1395 LandMass := NewLandMass; 1424 bix[0] := bixTerm;1396 bix[0] := Brains.IndexOf(BrainTerm); 1425 1397 Difficulty[0] := 0; 1426 InitBrain( bixTerm);1398 InitBrain(Brains.IndexOf(BrainTerm)); 1427 1399 1428 1400 DelphiRandomize; … … 1446 1418 Game.Difficulty[p1] := -1 1447 1419 end; 1448 Brain [bixTerm].Client(cNewMap, -1, Game);1420 BrainTerm.Client(cNewMap, -1, Game); 1449 1421 1450 1422 DiscoverAll(0, lObserveSuper); 1451 1423 Notify(ntEndInfo); 1452 Brain [bix[0]].Client(cShowGame, 0, nil^);1424 Brains[bix[0]].Client(cShowGame, 0, nil^); 1453 1425 Notify(ntBackOff); 1454 1426 ChangeClientWhenDone(cEditMap, 0, nil^, 0) … … 1905 1877 then { supervisor - all tiles visible } 1906 1878 begin 1907 if ( bix[pTurn] <> bixNoTerm) and1879 if (Brains[bix[pTurn]].Kind <> btNoTerm) and 1908 1880 ((Difficulty[pTurn] > 0) or (Mode > moLoading_Fast)) then 1909 1881 DiscoverAll(pTurn, lObserveSuper) … … 2102 2074 ShowMove.Flags := ShowMove.Flags or umShipLoading; 2103 2075 for p1 := 0 to nPl - 1 do 2104 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( bix[p1] = bixTerm))2076 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (Brains[bix[p1]].Kind = btTerm)) 2105 2077 then 2106 2078 begin … … 2273 2245 if Mode >= moMovie then { show after-move in interface modules } 2274 2246 for p1 := 0 to nPl - 1 do 2275 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( bix[p1] = bixTerm))2247 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (Brains[bix[p1]].Kind = btTerm)) 2276 2248 then 2277 2249 begin … … 2381 2353 if Mode >= moMovie then { show attack in interface modules } 2382 2354 for p1 := 0 to nPl - 1 do 2383 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( bix[p1] = bixTerm))2355 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (Brains[bix[p1]].Kind = btTerm)) 2384 2356 then 2385 2357 begin … … 2543 2515 Lost := Destroyed[p, Owner, mix]; 2544 2516 for p1 := 0 to nPl - 1 do { show after-attack in interface modules } 2545 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( bix[p1] = bixTerm))2517 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (Brains[bix[p1]].Kind = btTerm)) 2546 2518 then 2547 2519 begin … … 2807 2779 } 2808 2780 sMessage: 2809 Brain [bix[0]].Client(cDebugMessage, Subject, Data);2781 Brains[bix[0]].Client(cDebugMessage, Subject, Data); 2810 2782 2811 2783 sSetDebugMap: … … 2824 2796 2825 2797 sRefreshDebugMap: 2826 Brain [bix[0]].Client(cRefreshDebugMap, -1, Player);2798 Brains[bix[0]].Client(cRefreshDebugMap, -1, Player); 2827 2799 2828 2800 sGetChart .. sGetChart + (nStat - 1) shl 4: … … 3121 3093 AllHumansDead := true; 3122 3094 for p1 := 0 to nPl - 1 do 3123 if (1 shl p1 and GAlive <> 0) and ( bix[p1] = bixTerm) then3095 if (1 shl p1 and GAlive <> 0) and (Brains[bix[p1]].Kind = btTerm) then 3124 3096 AllHumansDead := false; 3125 3097 if (pDipActive >= 0) // still in negotiation mode … … 3238 3210 if Command = sReload then 3239 3211 begin 3240 ok := (Difficulty[0] = 0) and ( bix[0] <> bixNoTerm) and3212 ok := (Difficulty[0] = 0) and (Brains[bix[0]].Kind <> btNoTerm) and 3241 3213 (integer(Data) >= 0) and (integer(Data) < GTurn); 3242 3214 for p1 := 1 to nPl - 1 do 3243 if bix[p1] = bixTerm then3215 if Brains[bix[p1]].Kind = btTerm then 3244 3216 ok := false; 3245 3217 // allow reload in AI-only games only … … 3251 3223 if (Command = sBreak) or (Command = sResign) then 3252 3224 Notify(ntBackOn); 3253 for i := 0 to nBrain- 1 do3254 if Brain [i].Initialized then3225 for i := 0 to Brains.Count - 1 do 3226 if Brains[i].Initialized then 3255 3227 begin 3256 if i >= bixFirstAI then3228 if Brains[i].Kind = btAI then 3257 3229 Notify(ntDeinitModule + i); 3258 3230 CallClient(i, cBreakGame, nil^); … … 3289 3261 SaveMap(MapFileName); 3290 3262 Notify(ntBackOn); 3291 Brain [bixTerm].Client(cBreakGame, -1, nil^);3263 BrainTerm.Client(cBreakGame, -1, nil^); 3292 3264 ReleaseMapEditor; 3293 3265 if Command = sSaveMap then … … 3469 3441 pTarget := p1; 3470 3442 Action := Command; 3471 Brain [bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData);3443 Brains[bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData); 3472 3444 end; 3473 3445 pDipActive := p1; … … 3570 3542 Action := Command; 3571 3543 Offer := TOffer(Data); 3572 Brain [bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData);3544 Brains[bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData); 3573 3545 end; 3574 3546 LastOffer := TOffer(Data); … … 4507 4479 end; { <<<server } 4508 4480 4481 { TBrain } 4482 4483 procedure TBrain.LoadFromFile(AIFileName: string); 4484 var 4485 T: Text; 4486 Key: string; 4487 Value: string; 4488 S: string; 4489 BasePath: string; 4490 I: Integer; 4491 begin 4492 BasePath := ExtractFileDir(AIFileName); 4493 FileName := ExtractFileName(ExtractFileNameWithoutExt(ExtractFileNameWithoutExt(AIFileName))); 4494 Name := FileName; 4495 DLLName := BasePath + DirectorySeparator + Name + '.dll'; 4496 Credits := ''; 4497 Flags := fMultiple; 4498 Client := nil; 4499 Initialized := false; 4500 ServerVersion := 0; 4501 if not FileExists(AIFileName) then 4502 raise Exception.Create(Format('AI specification file %s not found', [AIFileName])); 4503 AssignFile(T, AIFileName); 4504 Reset(T); 4505 while not EOF(T) do 4506 begin 4507 ReadLn(T, s); 4508 s := trim(s); 4509 if Pos(' ', S) > 0 then begin 4510 Key := Copy(S, 1, Pos(' ', S) - 1); 4511 Value := Trim(Copy(S, Pos(' ', S) + 1, Length(S))); 4512 end else begin 4513 Key := S; 4514 Value := ''; 4515 end; 4516 if Key = '#NAME' then 4517 Name := Value 4518 else if Key = '#.NET' then 4519 Flags := Flags or fDotNet 4520 else if Key = '#BEGINNER' then 4521 BrainBeginner := Self 4522 else if Key = '#PATH' then 4523 DLLName := BasePath + DirectorySeparator + Value 4524 {$IFDEF WINDOWS}{$IFDEF CPU32} 4525 else if Key = '#PATH_WIN32' then 4526 DLLName := BasePath + DirectorySeparator + Value 4527 {$ENDIF}{$ENDIF} 4528 {$IFDEF WINDOWS}{$IFDEF CPU64} 4529 else if Key = '#PATH_WIN64' then 4530 DLLName := BasePath + DirectorySeparator + Value 4531 {$ENDIF}{$ENDIF} 4532 {$IFDEF LINUX}{$IFDEF CPU32} 4533 else if Key = '#PATH_LINUX32' then 4534 DLLName := BasePath + DirectorySeparator + Value 4535 {$ENDIF}{$ENDIF} 4536 {$IFDEF LINUX}{$IFDEF CPU64} 4537 else if Key = '#PATH_LINUX64' then 4538 DLLName := BasePath + DirectorySeparator + Value 4539 {$ENDIF}{$ENDIF} 4540 else if Key = '#GAMEVERSION' then 4541 for i := 1 to Length(Value) do 4542 case Value[i] of 4543 '0' .. '9': 4544 ServerVersion := ServerVersion and $FFFF00 + ServerVersion and 4545 $FF * 10 + ord(Value[i]) - 48; 4546 '.': 4547 ServerVersion := ServerVersion shl 8; 4548 end 4549 else if Key = '#CREDITS' then 4550 Credits := Value; 4551 end; 4552 CloseFile(T); 4553 end; 4554 4555 constructor TBrain.Create; 4556 begin 4557 Picture := nil; 4558 end; 4559 4560 destructor TBrain.Destroy; 4561 begin 4562 if Assigned(Picture) then Picture.Free; 4563 inherited Destroy; 4564 end; 4565 4566 { TBrains } 4567 4568 function TBrains.AddNew: TBrain; 4569 begin 4570 Result := TBrain.Create; 4571 Add(Result); 4572 end; 4573 4574 function TBrains.GetKindCount(Kind: TBrainType): Integer; 4575 var 4576 I: Integer; 4577 begin 4578 Result := 0; 4579 for I := 0 to Count - 1 do 4580 if Items[I].Kind = Kind then Inc(Result); 4581 end; 4582 4583 procedure TBrains.GetByKind(Kind: TBrainType; Brains: TBrains); 4584 var 4585 I: Integer; 4586 begin 4587 Brains.Clear; 4588 for I := 0 to Count - 1 do 4589 if Items[I].Kind = Kind then Brains.Add(Items[I]); 4590 end; 4591 4509 4592 initialization 4510 4593 -
trunk/NoTerm.pas
r118 r143 43 43 implementation 44 44 45 uses GameServer, log, Start; 45 uses 46 GameServer, log; 46 47 47 48 {$R *.lfm} … … 327 328 yBrain[i] - 8 - 16 + 111, MainTexture.clBevelShade, 328 329 MainTexture.clBevelShade); 329 FrameImage(Canvas, StartDlg.BrainPicture[bixView[i]], xBrain[i],330 FrameImage(Canvas, Brains[bixView[i]].Picture, xBrain[i], 330 331 yBrain[i] - 16, 64, 64, 0, 0); 331 332 if 1 shl i and G.RO[me].Alive = 0 then -
trunk/Start.pas
r137 r143 70 70 procedure ReplayBtnClick(Sender: TObject); 71 71 public 72 BrainPicture: array [0 .. maxBrain - 1] of TBitmap;73 72 EmptyPicture: TBitmap; 74 73 procedure UpdateFormerGames; 75 74 procedure UpdateMaps; 76 75 private 77 WorldSize, StartLandMass, MaxTurn, AutoEnemies, AutoDiff, MultiControl, 78 MiniWidth, MiniHeight, SelectedAction, Page, ShowTab, Tab, Diff0, 79 bixDefault, nMapLandTiles, nMapStartPositions, LoadTurn, LastTurn, 76 WorldSize: Integer; 77 StartLandMass: Integer; 78 MaxTurn: Integer; 79 AutoEnemies: Integer; 80 AutoDiff: Integer; 81 MultiControl: Integer; 82 MiniWidth: Integer; 83 MiniHeight: Integer; 84 SelectedAction: Integer; 85 Page: Integer; 86 ShowTab: Integer; 87 Tab: Integer; 88 Diff0: Integer; 89 bixDefault: Integer; 90 nMapLandTiles: Integer; 91 nMapStartPositions: Integer; 92 LoadTurn: Integer; 93 LastTurn: Integer; 80 94 { last turn of selected former game } 81 SlotAvailable, bixPopup: integer; { brain concerned by brain context menu } 95 SlotAvailable: Integer; 96 bixPopup: Integer; { brain concerned by brain context menu } 82 97 ListIndex: array [0 .. 3] of integer; 83 98 MapFileName: string; … … 186 201 r0, r1: HRgn; 187 202 Location: TPoint; 203 AIBrains: TBrains; 188 204 begin 189 205 LoadConfig; … … 195 211 196 212 bixDefault := -1; 197 for i := bixRandom to nBrain- 1 do198 if AnsiCompareFileName(DefaultAI, Brain [i].FileName) = 0 then213 for i := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do 214 if AnsiCompareFileName(DefaultAI, Brains[i].FileName) = 0 then 199 215 bixDefault := i; 200 if (bixDefault = bixRandom) and (nBrain < bixFirstAI +2) then216 if (bixDefault = Brains.IndexOf(BrainRandom)) and (Brains.GetKindCount(btAI) < 2) then 201 217 bixDefault := -1; 202 if (bixDefault < 0) and (nBrain > bixFirstAI) then 203 bixDefault := bixFirstAI; // default AI not found, use any 218 if (bixDefault < 0) and (Brains.GetKindCount(btAI) > 0) then 219 begin 220 AIBrains := TBrains.Create(False); 221 Brains.GetByKind(btAI, AIBrains); 222 bixDefault := Brains.IndexOf(Brains[0]); 223 AIBrains.Free; 224 end; // default AI not found, use any 204 225 205 226 DirectDlg.Left := (Screen.Width - DirectDlg.Width) div 2; … … 269 290 CustomizeBtn.ButtonIndex := 2; 270 291 271 Brain Picture[0]:= TBitmap.Create;272 Brain Picture[0].SetSize(64, 64);273 BitBlt(Brain Picture[0].Canvas.Handle, 0, 0, 64, 64,292 Brains[0].Picture := TBitmap.Create; 293 Brains[0].Picture.SetSize(64, 64); 294 BitBlt(Brains[0].Picture.Canvas.Handle, 0, 0, 64, 64, 274 295 GrExt[HGrSystem2].Data.Canvas.Handle, 1, 111, SRCCOPY); 275 Brain Picture[1]:= TBitmap.Create;276 Brain Picture[1].SetSize(64, 64);277 BitBlt(Brain Picture[1].Canvas.Handle, 0, 0, 64, 64,296 Brains[1].Picture := TBitmap.Create; 297 Brains[1].Picture.SetSize(64, 64); 298 BitBlt(Brains[1].Picture.Canvas.Handle, 0, 0, 64, 64, 278 299 GrExt[HGrSystem2].Data.Canvas.Handle, 66, 111, SRCCOPY); 279 Brain Picture[2]:= TBitmap.Create;280 Brain Picture[2].SetSize(64, 64);281 BitBlt(Brain Picture[2].Canvas.Handle, 0, 0, 64, 64,300 Brains[2].Picture := TBitmap.Create; 301 Brains[2].Picture.SetSize(64, 64); 302 BitBlt(Brains[2].Picture.Canvas.Handle, 0, 0, 64, 64, 282 303 GrExt[HGrSystem2].Data.Canvas.Handle, 131, 111, SRCCOPY); 283 Brain Picture[3]:= TBitmap.Create;284 Brain Picture[3].SetSize(64, 64);285 BitBlt(Brain Picture[3].Canvas.Handle, 0, 0, 64, 64,304 Brains[3].Picture := TBitmap.Create; 305 Brains[3].Picture.SetSize(64, 64); 306 BitBlt(Brains[3].Picture.Canvas.Handle, 0, 0, 64, 64, 286 307 GrExt[HGrSystem2].Data.Canvas.Handle, 131, 46, SRCCOPY); 287 for i := bixFirstAI to nBrain - 1 do begin 288 BrainPicture[i] := TBitmap.Create; 289 if not LoadGraphicFile(BrainPicture[i], HomeDir + 'AI' + DirectorySeparator + 290 Brain[i].FileName + DirectorySeparator + Brain[i].FileName + '.png', 291 gfNoError) then begin 292 BrainPicture[i].SetSize(64, 64); 293 with BrainPicture[i].Canvas do begin 308 309 AIBrains := TBrains.Create(False); 310 Brains.GetByKind(btAI, AIBrains); 311 for i := 0 to AIBrains.Count - 1 do 312 with AIBrains[I] do 313 begin 314 AIBrains[i].Picture := TBitmap.Create; 315 if not LoadGraphicFile(AIBrains[i].Picture, HomeDir + 'AI' + DirectorySeparator + 316 FileName + DirectorySeparator + FileName + '.png', gfNoError) then begin 317 AIBrains[i].Picture.SetSize(64, 64); 318 with AIBrains[i].Picture.Canvas do begin 294 319 Brush.Color := $904830; 295 320 FillRect(Rect(0, 0, 64, 64)); … … 297 322 Font.Style := []; 298 323 Font.Color := $5FDBFF; 299 Textout(32 - TextWidth( Brain[i].FileName) div 2,300 32 - TextHeight( Brain[i].FileName) div 2, Brain[i].FileName);324 Textout(32 - TextWidth(FileName) div 2, 325 32 - TextHeight(FileName) div 2, FileName); 301 326 end; 302 327 end; 303 328 end; 329 AIBrains.Free; 304 330 305 331 EmptyPicture := TBitmap.Create; … … 318 344 InitButtons; 319 345 320 bixView[0] := bixTerm;346 bixView[0] := Brains.IndexOf(BrainTerm); 321 347 SlotAvailable := -1; 322 348 Tab := 2; … … 333 359 334 360 procedure TStartDlg.FormDestroy(Sender: TObject); 335 var336 i: integer;337 361 begin 338 362 FreeAndNil(FormerGames); … … 341 365 FreeAndNil(EmptyPicture); 342 366 FreeAndNil(LogoBuffer); 343 for i := 0 to nBrain - 1 do344 FreeAndNil(BrainPicture[i]);345 367 end; 346 368 … … 624 646 begin 625 647 if bixView[i] >= 0 then 626 FrameImage(Canvas, Brain Picture[bixView[i]], xBrain[i], yBrain[i],648 FrameImage(Canvas, Brains[bixView[i]].Picture, xBrain[i], yBrain[i], 627 649 64, 64, 0, 0, true) 628 650 else 629 651 FrameImage(Canvas, EmptyPicture, xBrain[i], yBrain[i], 64, 64, 630 652 0, 0, true); 631 if bixView[i] >= bixTermthen653 if Brains[bixView[i]].Kind in [btTerm, btRandom, btAI] then 632 654 begin 633 655 BitBlt(Canvas.Handle, xBrain[i] - 18, yBrain[i] + 19, 12, 14, … … 658 680 begin 659 681 DiffUpBtn[i].Hint := Format(Phrases.Lookup('STARTCONTROLS', 9), 660 [Brain [bixView[i]].Name]);682 [Brains[bixView[i]].Name]); 661 683 DiffDownBtn[i].Hint := DiffUpBtn[i].Hint; 662 684 end … … 681 703 yMain + 164 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 16)); 682 704 if AutoDiff = 1 then 683 FrameImage(Canvas, Brain Picture[bixBeginner], xDefault, yDefault, 64,705 FrameImage(Canvas, BrainBeginner.Picture, xDefault, yDefault, 64, 684 706 64, 0, 0, false) 685 707 else 686 FrameImage(Canvas, Brain Picture[bixDefault], xDefault, yDefault, 64, 64,708 FrameImage(Canvas, Brains[bixDefault].Picture, xDefault, yDefault, 64, 64, 687 709 0, 0, true); 688 710 DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.clBevelLight, … … 895 917 else GameCount := 0; 896 918 897 if (AutoDiff < 0) and ( bixView[0] = bixNoTerm) then919 if (AutoDiff < 0) and (Brains[bixView[0]].Kind = btNoTerm) then 898 920 FileName := 'Round' + IntToStr(GetProcessID()) 899 921 else begin … … 913 935 Reg.WriteString('Control' + IntToStr(i), '') 914 936 else Reg.WriteString('Control' + IntToStr(i), 915 Brain [bixView[i]].FileName);937 Brains[bixView[i]].FileName); 916 938 WriteInteger('Diff' + IntToStr(i), Difficulty[i]); 917 939 end; … … 922 944 if AutoDiff > 0 then 923 945 begin 924 WriteString('DefaultAI', Brain [bixDefault].FileName);946 WriteString('DefaultAI', Brains[bixDefault].FileName); 925 947 SlotAvailable := 0; // bixView will be invalid hereafter 926 bixView[0] := bixTerm;948 bixView[0] := Brains.IndexOf(BrainTerm); 927 949 Difficulty[0] := PlayerAutoDiff[AutoDiff]; 928 950 for i := 1 to nPl - 1 do 929 951 if (Page = pgStartRandom) and (i <= AutoEnemies) or 930 952 (Page = pgStartMap) and (i < nMapStartPositions) then begin 931 if AutoDiff = 1 then bixView[i] := bixBeginner953 if AutoDiff = 1 then bixView[i] := Brains.IndexOf(BrainBeginner) 932 954 else bixView[i] := bixDefault; 933 955 Difficulty[i] := EnemyAutoDiff[AutoDiff]; … … 935 957 end else begin 936 958 for i := 6 to 8 do 937 if ( bixView[0] <> bixNoTerm) and (MultiControl and (1 shl i) <> 0)959 if (Brains[bixView[0]].Kind <> btNoTerm) and (MultiControl and (1 shl i) <> 0) 938 960 then begin 939 961 bixView[i + 3] := bixView[i]; … … 1218 1240 else 1219 1241 begin 1220 Brain [bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags and1242 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags and 1221 1243 not fUsed; 1222 1244 bixView[bixPopup] := TMenuItem(Sender).Tag; 1223 DiffUpBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1224 DiffDownBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1245 DiffUpBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1246 DiffDownBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1225 1247 if bixPopup in OfferMultiple then 1226 1248 begin 1227 MultiBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1249 MultiBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1228 1250 MultiBtn[bixPopup].ButtonIndex := 2 + (MultiControl shr bixPopup) and 1; 1229 1251 end; 1230 Brain [bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags or fUsed;1231 if bixView[bixPopup] < bixTermthen1252 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags or fUsed; 1253 if Brains[bixView[bixPopup]].Kind in [btNoTerm, btSuperVirtual] then 1232 1254 Difficulty[bixPopup] := 0 { supervisor } 1233 1255 else … … 1238 1260 if (bixPopup = 0) and (MapFileName <> '') then 1239 1261 ChangePage(Page); 1240 if bixView[bixPopup] = bixNoTerm then1262 if Brains[bixView[bixPopup]].Kind = btNoTerm then 1241 1263 begin // turn all local players off 1242 1264 for i := 1 to nPlOffered - 1 do 1243 if bixView[i] = bixTerm then1265 if Brains[bixView[i]].Kind = btTerm then 1244 1266 begin 1245 1267 bixView[i] := -1; … … 1256 1278 DiffUpBtn[i].top + 25); 1257 1279 end; 1258 Brain [bixTerm].Flags := Brain[bixTerm].Flags and not fUsed;1280 BrainTerm.Flags := BrainTerm.Flags and not fUsed; 1259 1281 end; 1260 1282 SmartInvalidate(xBrain[bixPopup] - 31, yBrain[bixPopup] - 1, … … 1267 1289 i, FixedLines: integer; 1268 1290 m: TMenuItem; 1291 AIBrains: TBrains; 1269 1292 1270 1293 procedure OfferBrain(Index: integer); … … 1276 1299 m.Caption := Phrases.Lookup('NOMOD') 1277 1300 else 1278 m.Caption := Brain [Index].Name;1301 m.Caption := Brains[Index].Name; 1279 1302 m.Tag := Index; 1280 1303 m.OnClick := BrainClick; … … 1297 1320 begin // select default AI 1298 1321 FixedLines := 0; 1299 if nBrain >= bixFirstAI +2 then1322 if Brains.GetKindCount(btAI) >= 2 then 1300 1323 begin 1301 OfferBrain( bixRandom);1324 OfferBrain(Brains.IndexOf(BrainRandom)); 1302 1325 inc(FixedLines) 1303 1326 end; 1304 for i := bixFirstAI to nBrain - 1 do // offer available AIs 1305 if Brain[i].Flags and fMultiple <> 0 then 1306 OfferBrain(i); 1327 AIBrains := TBrains.Create(False); 1328 Brains.GetByKind(btAI, AIBrains); 1329 for i := 0 to AIBrains.Count - 1 do // offer available AIs 1330 if AIBrains[i].Flags and fMultiple <> 0 then 1331 OfferBrain(Brains.IndexOf(AIBrains[i])); 1332 AIBrains.Free; 1307 1333 end 1308 1334 else … … 1314 1340 inc(FixedLines); 1315 1341 end; 1316 for i := bixTermdownto 0 do // offer game interfaces1317 if (bixPopup = 0) or ( i = bixTerm) and (bixView[0] <> bixNoTerm) then1342 for i := Brains.IndexOf(BrainTerm) downto 0 do // offer game interfaces 1343 if (bixPopup = 0) or (Brains[i].Kind = btTerm) and (Brains[bixView[0]].Kind <> btNoTerm) then 1318 1344 begin 1319 1345 OfferBrain(i); … … 1326 1352 PopupMenu1.Items.Add(m); 1327 1353 inc(FixedLines); 1328 if nBrain >= bixFirstAI +2 then1329 begin 1330 OfferBrain( bixRandom);1354 if Brains.GetKindCount(btAI) >= 2 then 1355 begin 1356 OfferBrain(Brains.IndexOf(BrainRandom)); 1331 1357 inc(FixedLines); 1332 1358 end; 1333 for i := bixFirstAI to nBrain - 1 do // offer available AIs 1334 if (Brain[i].Flags and fMultiple <> 0) or (Brain[i].Flags and fUsed = 0) 1359 AIBrains := TBrains.Create(False); 1360 Brains.GetByKind(btAI, AIBrains); 1361 for i := 0 to AIBrains.Count - 1 do // offer available AIs 1362 if (AIBrains[i].Flags and fMultiple <> 0) or (AIBrains[i].Flags and fUsed = 0) 1335 1363 or (i = bixView[bixPopup]) then 1336 OfferBrain(i); 1364 OfferBrain(Brains.IndexOf(AIBrains[i])); 1365 AIBrains.Free; 1337 1366 end; 1338 1367 end … … 1397 1426 if i = 0 then 1398 1427 begin 1399 bixView[0] := bixSuper_Virtual;1428 bixView[0] := Brains.IndexOf(BrainSuperVirtual); 1400 1429 Difficulty[0] := 0 1401 1430 end; 1402 if bixView[0] < bixTermthen1431 if Brains[bixView[0]].Kind in [btNoTerm, btSuperVirtual] then 1403 1432 inc(i); 1404 1433 if i > nPl then … … 1421 1450 Difficulty[p1] := ReadInteger('Diff' + IntToStr(p1)); 1422 1451 if s <> '' then 1423 for j := 0 to nBrain- 1 do1424 if AnsiCompareFileName(s, Brain [j].FileName) = 0 then1452 for j := 0 to Brains.Count - 1 do 1453 if AnsiCompareFileName(s, Brains[j].FileName) = 0 then 1425 1454 bixView[p1] := j; 1426 1455 end; … … 1441 1470 SlotAvailable := InitAlive[i]; 1442 1471 for i := 0 to nPlOffered - 1 do 1443 if (AutoDiff < 0) and ( bixView[i] >= bixTerm) then1472 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1444 1473 begin 1445 1474 DiffUpBtn[i].Tag := 768; … … 1452 1481 end; 1453 1482 for i := 6 to 8 do 1454 if (AutoDiff < 0) and ( bixView[i] >= bixTerm) then1483 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1455 1484 begin 1456 1485 MultiBtn[i].Tag := 768; … … 1593 1622 (x >= xDefault) and (y >= yDefault) and (x < xDefault + 64) and 1594 1623 (y < yDefault + 64) then 1595 if nBrain < bixFirstAI +2 then1624 if Brains.GetKindCount(btAI) < 2 then 1596 1625 SimpleMessage(Phrases.Lookup('NOALTAI')) 1597 1626 else
Note:
See TracChangeset
for help on using the changeset viewer.