Changeset 363


Ignore:
Timestamp:
Apr 12, 2021, 3:01:58 PM (3 years ago)
Author:
chronos
Message:
  • Modified: TBrain class moved to separate UBrain unit.
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r355 r363  
    88uses
    99  Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,
    10   Graphics;
     10  Graphics, UBrain;
    1111
    1212const
     
    1414  FirstAICompatibleVersion = $000D00;
    1515  FirstBookCompatibleVersion = $010103;
    16 
    17   // module flags
    18   fMultiple = $10000000;
    19   fDotNet = $20000000;
    20   fUsed = $40000000;
    2116
    2217  maxBrain = 255;
     
    5247  TNotifyFunction = procedure(ID: TNotify; Index: Integer = 0);
    5348
    54   TBrainType = (btNoTerm, btSuperVirtual, btTerm, btRandom, btAI);
    55 
    56   { TBrain }
    57 
    58   TBrain = class
    59     FileName: string;
    60     DLLName: string;
    61     Name: string;
    62     Credits: string; { filename and full name }
    63     hm: TLibHandle; { module handle }
    64     Flags: Integer;
    65     ServerVersion: Integer;
    66     DataVersion: Integer;
    67     DataSize: Integer;
    68     Client: TClientCall; { client function address }
    69     Initialized: Boolean;
    70     Kind: TBrainType;
    71     Picture: TBitmap;
    72     procedure LoadFromFile(AIFileName: string);
    73     constructor Create;
    74     destructor Destroy; override;
    75   end;
    76 
    77   { TBrains }
    78 
    79   TBrains = class(TFPGObjectList<TBrain>)
    80     function AddNew: TBrain;
    81     function GetKindCount(Kind: TBrainType): Integer;
    82     procedure GetByKind(Kind: TBrainType; Brains: TBrains);
    83   end;
    84 
    8549var
    8650  // PARAMETERS
     
    9862  BrainTerm: TBrain;
    9963  BrainRandom: TBrain;
    100   BrainBeginner: TBrain; // AI to use for beginner level
    10164
    10265procedure Init(NotifyFunction: TNotifyFunction);
     
    254217  BrainRandom.Initialized := false;
    255218  BrainRandom.Kind := btRandom;
    256 
    257   BrainBeginner := nil;
    258219
    259220  if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then
     
    45224483end;
    45234484
    4524 { TBrain }
    4525 
    4526 procedure TBrain.LoadFromFile(AIFileName: string);
    4527 var
    4528   T: Text;
    4529   Key: string;
    4530   Value: string;
    4531   S: string;
    4532   BasePath: string;
    4533   I: Integer;
    4534 begin
    4535   BasePath := ExtractFileDir(AIFileName);
    4536   FileName := ExtractFileName(ExtractFileNameWithoutExt(ExtractFileNameWithoutExt(AIFileName)));
    4537   Name := FileName;
    4538   DLLName := BasePath + DirectorySeparator + Name + '.dll';
    4539   Credits := '';
    4540   Flags := fMultiple;
    4541   Client := nil;
    4542   Initialized := false;
    4543   ServerVersion := 0;
    4544   if not FileExists(AIFileName) then
    4545     raise Exception.Create(Format('AI specification file %s not found', [AIFileName]));
    4546   AssignFile(T, AIFileName);
    4547   Reset(T);
    4548   while not EOF(T) do
    4549   begin
    4550     ReadLn(T, s);
    4551     s := trim(s);
    4552     if Pos(' ', S) > 0 then begin
    4553       Key := Copy(S, 1, Pos(' ', S) - 1);
    4554       Value := Trim(Copy(S, Pos(' ', S) + 1, Length(S)));
    4555     end else begin
    4556       Key := S;
    4557       Value := '';
    4558     end;
    4559     if Key = '#NAME' then
    4560       Name := Value
    4561     else if Key = '#.NET' then
    4562       Flags := Flags or fDotNet
    4563     else if Key = '#BEGINNER' then
    4564       BrainBeginner := Self
    4565     else if Key = '#PATH' then
    4566       DLLName := BasePath + DirectorySeparator + Value
    4567     {$IFDEF WINDOWS}{$IFDEF CPU32}
    4568     else if Key = '#PATH_WIN32' then
    4569       DLLName := BasePath + DirectorySeparator + Value
    4570     {$ENDIF}{$ENDIF}
    4571     {$IFDEF WINDOWS}{$IFDEF CPU64}
    4572     else if Key = '#PATH_WIN64' then
    4573       DLLName := BasePath + DirectorySeparator + Value
    4574     {$ENDIF}{$ENDIF}
    4575     {$IFDEF LINUX}{$IFDEF CPU32}
    4576     else if Key = '#PATH_LINUX32' then
    4577       DLLName := BasePath + DirectorySeparator + Value
    4578     {$ENDIF}{$ENDIF}
    4579     {$IFDEF LINUX}{$IFDEF CPU64}
    4580     else if Key = '#PATH_LINUX64' then
    4581       DLLName := BasePath + DirectorySeparator + Value
    4582     {$ENDIF}{$ENDIF}
    4583     else if Key = '#GAMEVERSION' then
    4584       for i := 1 to Length(Value) do
    4585         case Value[i] of
    4586           '0' .. '9':
    4587             ServerVersion := ServerVersion and $FFFF00 + ServerVersion and
    4588               $FF * 10 + ord(Value[i]) - 48;
    4589           '.':
    4590           ServerVersion := ServerVersion shl 8;
    4591       end
    4592     else if Key = '#CREDITS' then
    4593       Credits := Value;
    4594   end;
    4595   CloseFile(T);
    4596 end;
    4597 
    4598 constructor TBrain.Create;
    4599 begin
    4600   Picture := TBitmap.Create;
    4601   Picture.SetSize(64, 64);
    4602 end;
    4603 
    4604 destructor TBrain.Destroy;
    4605 begin
    4606   FreeAndNil(Picture);
    4607   inherited;
    4608 end;
    4609 
    4610 { TBrains }
    4611 
    4612 function TBrains.AddNew: TBrain;
    4613 begin
    4614   Result := TBrain.Create;
    4615   Add(Result);
    4616 end;
    4617 
    4618 function TBrains.GetKindCount(Kind: TBrainType): Integer;
    4619 var
    4620   I: Integer;
    4621 begin
    4622   Result := 0;
    4623   for I := 0 to Count - 1 do
    4624     if Items[I].Kind = Kind then Inc(Result);
    4625 end;
    4626 
    4627 procedure TBrains.GetByKind(Kind: TBrainType; Brains: TBrains);
    4628 var
    4629   I: Integer;
    4630 begin
    4631   Brains.Clear;
    4632   for I := 0 to Count - 1 do
    4633     if Items[I].Kind = Kind then Brains.Add(Items[I]);
    4634 end;
    46354485
    46364486initialization
  • trunk/Integrated.lpi

    r320 r363  
    9595      </Item2>
    9696    </RequiredPackages>
    97     <Units Count="43">
     97    <Units Count="44">
    9898      <Unit0>
    9999        <Filename Value="Integrated.lpr"/>
     
    340340        <IsPartOfProject Value="True"/>
    341341      </Unit42>
     342      <Unit43>
     343        <Filename Value="UBrain.pas"/>
     344        <IsPartOfProject Value="True"/>
     345      </Unit43>
    342346    </Units>
    343347  </ProjectOptions>
  • trunk/LocalPlayer/Select.pas

    r360 r363  
    15681568      DispLines := MaxLines;
    15691569    InnerHeight := LineDistance * (DispLines + 1) + 24;
    1570     ClientHeight := InnerHeight + TitleHeight + WideFrame
     1570    ClientHeight := InnerHeight + TitleHeight + WideFrame;
    15711571  end
    15721572  else
  • trunk/Start.pas

    r359 r363  
    77  GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types,
    88  LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
    9   Menus, Registry,  DrawDlg, fgl, Protocol, UMiniMap;
     9  Menus, Registry,  DrawDlg, fgl, Protocol, UMiniMap, UBrain;
    1010
    1111type
     
    750750        yMain + 164 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 16));
    751751      if AutoDiff = 1 then
    752         FrameImage(Canvas, BrainBeginner.Picture, xDefault, yDefault, 64,
     752        FrameImage(Canvas, Brains.GetBeginner.Picture, xDefault, yDefault, 64,
    753753          64, 0, 0, false)
    754754      else
     
    977977              if (Page = pgStartRandom) and (I <= AutoEnemies) or
    978978                (Page = pgStartMap) and (I < nMapStartPositions) then begin
    979                 if AutoDiff = 1 then PlayersBrain[I] := BrainBeginner
     979                if AutoDiff = 1 then PlayersBrain[I] := Brains.GetBeginner
    980980                  else PlayersBrain[I] := BrainDefault;
    981981                Difficulty[I] := EnemyAutoDiff[AutoDiff];
Note: See TracChangeset for help on using the changeset viewer.