Changeset 144 for trunk/GameServer.pas


Ignore:
Timestamp:
May 11, 2018, 11:57:25 PM (6 years ago)
Author:
chronos
Message:
  • Modified: More code refactoring related to players brain selection.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r143 r144  
    8787var
    8888  // PARAMETERS
    89   bixView: array [0 .. nPl - 1] of integer; { brain index of the players }
     89  PlayersBrain: TBrains; { brain index of the players }
    9090  Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty;
    9191  { difficulty }
     
    124124
    125125var
    126   MaxTurn, LoadTurn, { turn where to stop loading }
    127   nLogOpened, { nLog of opened book }
     126  MaxTurn: Integer;
     127  LoadTurn: Integer; { turn where to stop loading }
     128  nLogOpened: Integer; { nLog of opened book }
    128129{$IFOPT O-}nHandoverStack, {$ENDIF}
    129   LastEndClientCommand, pContacted, // player contacted for negotiation
    130   pDipActive, // player who's to speak in a negotiation
    131   pTurn, { player who's turn it is }
    132   GWinner, GColdWarStart, GStealFrom, SpyMission, ZOCTile, CCCommand,
    133     CCPlayer: integer;
    134   DebugMap: array [0 .. nPl - 1] of pointer;
     130  LastEndClientCommand: Integer;
     131  pContacted: Integer; // player contacted for negotiation
     132  pDipActive: Integer; // player who's to speak in a negotiation
     133  pTurn: Integer; { player who's turn it is }
     134  GWinner: Integer;
     135  GColdWarStart: Integer;
     136  GStealFrom: Integer;
     137  SpyMission: Integer;
     138  ZOCTile: Integer;
     139  CCCommand: Integer;
     140  CCPlayer: Integer;
     141  DebugMap: array [0 .. nPl - 1] of Pointer;
    135142  ExeInfo: TSearchRec;
    136143  Stat: array [0 .. nStat - 1, 0 .. nPl - 1] of ^TChart;
     
    144151  SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal;
    145152  SavedData: array [0 .. nPl - 1] of pointer;
    146   LogFileName, SavePath, { name of file for saving the current game }
    147   MapFileName, // name of map to use, empty for random
     153  LogFileName: string;
     154  SavePath: string; { name of file for saving the current game }
     155  MapFileName: string; // name of map to use, empty for random
    148156  AICredits: string;
    149157  AIInfo: array [0 .. nPl - 1] of string;
     
    151159  LastClientTime: TDateTime;
    152160{$IFOPT O-}HandoverStack: array [0 .. 31] of Cardinal; {$ENDIF}
    153   AutoSaveExists, LoadOK, WinOnAlone, PreviewElevation, MovieStopped: boolean;
     161  AutoSaveExists: Boolean;
     162  LoadOK: Boolean;
     163  WinOnAlone: Boolean;
     164  PreviewElevation: Boolean;
     165  MovieStopped: Boolean;
    154166
    155167const
     
    204216  BasePath: string;
    205217  NewBrain: TBrain;
     218  I: Integer;
    206219begin
    207220  Notify := NotifyFunction;
    208221  PreviewElevation := false;
     222  PlayersBrain := TBrains.Create(False);
     223  PlayersBrain.Count := nPl;
     224  for I := 0 to nPl - 1 do
     225    PlayersBrain[I] := nil;
    209226
    210227  { get available brains }
     
    264281        FreeLibrary(hm);
    265282    end;
     283  PlayersBrain.Free;
    266284  Brains.Free;
    267285end;
     
    650668    else
    651669    begin
    652       if Brains[bixView[i]].Kind in [btRandom, btAI] then
     670      if PlayersBrain[i].Kind in [btRandom, btAI] then
    653671        s := Brains[bix[i]].FileName
    654672      else
    655         s := Brains[bixView[i]].FileName;
     673        s := PlayersBrain[i].FileName;
    656674      move(zero, s[Length(s) + 1], 4);
    657675      LogFile.write(s, (Length(s) div 4 + 1) * 4);
     
    685703begin
    686704  for p1 := 0 to nPl - 1 do begin
    687     if (bixView[p1] <> -1) and (Brains[bixView[p1]].Kind = btSuperVirtual) then
     705    if Assigned(PlayersBrain[p1]) and (PlayersBrain[p1].Kind = btSuperVirtual) then
    688706      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
     707    else if Assigned(PlayersBrain[p1]) and (PlayersBrain[p1].Kind = btRandom) then
    690708      if Brains.GetKindCount(btAI) = 0 then
    691709        bix[p1] := -1
    692710      else begin
    693711        AIBrains := TBrains.Create(False);
     712        Brains.GetByKind(btAI, AIBrains);
    694713        bix[p1] := Brains.IndexOf(AIBrains[DelphiRandom(AIBrains.Count)]);
    695714        AIBrains.Free;
    696715      end
    697716    else
    698       bix[p1] := bixView[p1];
    699     if bixView[p1] < 0 then
     717      bix[p1] := Brains.IndexOf(PlayersBrain[p1]);
     718    if not Assigned(PlayersBrain[p1]) then
    700719      Difficulty[p1] := -1;
    701720  end;
     
    10861105  MovieMode: boolean): boolean;
    10871106var
    1088   i, j, ix, d, p1, Command, Subject: integer;
     1107  j: TBrain;
     1108  i, ix, d, p1, Command, Subject: integer;
    10891109{$IFDEF TEXTLOG}LoadPos0: integer; {$ENDIF}
    10901110  Data: pointer;
     
    11241144      LogFile.read(s[0], 4);
    11251145      if s[0] = #0 then
    1126         bixView[p1] := -1
     1146        PlayersBrain[p1] := nil
    11271147      else
    11281148      begin
     
    11311151        LogFile.read(d, 4); { behavior }
    11321152        LogFile.read(Difficulty[p1], 4);
    1133         j := Brains.Count - 1;
    1134         while (j >= 0) and (AnsiCompareFileName(Brains[j].FileName, s) <> 0) do
    1135           dec(j);
    1136         if j < 0 then
     1153        j := Brains.Last;
     1154        while Assigned(J) and (AnsiCompareFileName(j.FileName, s) <> 0) do
     1155          J := PlayersBrain[PlayersBrain.IndexOf(J) - 1];
     1156        if not Assigned(j) then
    11371157        begin // ai not found -- replace by local player
    11381158          ProcessClientData[p1] := false;
    11391159          NotifyMessage := s;
    11401160          Notify(ntAIError);
    1141           j := Brains.IndexOf(BrainTerm);
     1161          j := BrainTerm;
    11421162        end
    11431163        else
    11441164          ProcessClientData[p1] := true;
    1145         if Brains[j].Kind = btNoTerm then
    1146           j := Brains.IndexOf(BrainSuperVirtual);
     1165        if j.Kind = btNoTerm then
     1166          j := BrainSuperVirtual;
    11471167        // crashed tournament -- load as supervisor
    1148         bixView[p1] := j;
     1168        PlayersBrain[p1] := j;
    11491169      end;
    11501170    end;
Note: See TracChangeset for help on using the changeset viewer.