Changeset 124 for trunk/GameServer.pas


Ignore:
Timestamp:
Apr 21, 2018, 11:40:27 AM (6 years ago)
Author:
chronos
Message:
  • Added: Other available AI libraries to AI subdirectory. The game detects new AI libraries by searching subdirectories in AI directory and its specification file .ai.txt. Note that precompiled 32-bit DLLs work only under 32-bit Windows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r120 r124  
    185185  Key: string;
    186186  Value: string;
     187  BasePath: string;
     188  AIFileName: string;
    187189begin
    188190  Notify := NotifyFunction;
     
    205207  nBrain := bixFirstAI;
    206208  bixBeginner := bixFirstAI;
    207   if FindFirst(HomeDir + 'AI' + DirectorySeparator + '*.ai.txt', $21, f) = 0 then
    208     repeat
    209       with Brain[nBrain] do
    210       begin
    211         FileName := Copy(f.Name, 1, Length(f.Name) - 7);
    212         DLLName := HomeDir + 'AI' + DirectorySeparator + FileName;
    213         Name := Copy(f.Name, 1, Length(f.Name) - 7);
     209  if FindFirst(HomeDir + 'AI' + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then
     210  repeat
     211    if (f.Name <> '.') and (f.Name <> '..') then begin
     212      with Brain[nBrain] do begin
     213        BasePath := HomeDir + 'AI' + DirectorySeparator + f.Name;
     214        FileName := f.Name;
     215        DLLName := BasePath + DirectorySeparator + FileName + '.dll';
     216        AIFileName := BasePath + DirectorySeparator + f.Name + '.ai.txt';
     217        Name := f.Name;
    214218        Credits := '';
    215219        Flags := fMultiple;
     
    217221        Initialized := false;
    218222        ServerVersion := 0;
    219         AssignFile(T, HomeDir + 'AI' + DirectorySeparator + f.Name);
     223        if not FileExists(AIFileName) then
     224          raise Exception.Create(Format('AI specification file %s not found', [AIFileName]));
     225        AssignFile(T, AIFileName);
    220226        Reset(T);
    221227        while not EOF(T) do
     
    237243            bixBeginner := nBrain
    238244          else if Key = '#PATH' then
    239             DLLName := HomeDir + 'AI' + DirectorySeparator + Value
     245            DLLName := BasePath + DirectorySeparator + Value
    240246          {$IFDEF WINDOWS}{$IFDEF CPU32}
    241247          else if Key = '#PATH_WIN32' then
    242             DLLName := HomeDir + 'AI' + DirectorySeparator + Value
     248            DLLName := BasePath + DirectorySeparator + Value
    243249          {$ENDIF}{$ENDIF}
    244250          {$IFDEF WINDOWS}{$IFDEF CPU64}
    245251          else if Key = '#PATH_WIN64' then
    246             DLLName := HomeDir + 'AI' + DirectorySeparator + Value
     252            DLLName := BasePath + DirectorySeparator + Value
    247253          {$ENDIF}{$ENDIF}
    248254          {$IFDEF LINUX}{$IFDEF CPU32}
    249255          else if Key = '#PATH_LINUX32' then
    250             DLLName := HomeDir + 'AI' + DirectorySeparator + Value
     256            DLLName := BasePath + DirectorySeparator + Value
    251257          {$ENDIF}{$ENDIF}
    252258          {$IFDEF LINUX}{$IFDEF CPU64}
    253259          else if Key = '#PATH_LINUX64' then
    254             DLLName := HomeDir + 'AI' + DirectorySeparator + Value
     260            DLLName := BasePath + DirectorySeparator + Value
    255261          {$ENDIF}{$ENDIF}
    256262          else if Key = '#GAMEVERSION' then
     
    272278        ((Brain[nBrain].Flags and fDotNet = 0) or (@DotNetClient <> nil)) then
    273279        inc(nBrain);
    274     until FindNext(f) <> 0;
     280    end;
     281  until FindNext(f) <> 0;
    275282  FindClose(F);
     283
     284  if nBrain = 0 then
     285    raise Exception.Create(Format('No AI libraries found in directory %s', [HomeDir + 'AI']));
    276286end;
    277287
Note: See TracChangeset for help on using the changeset viewer.