Changeset 589


Ignore:
Timestamp:
Jul 24, 2024, 10:51:34 AM (4 months ago)
Author:
chronos
Message:
  • Fixed: With selected map it was not possible to start a new game due to wrong map path.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Brain.pas

    r544 r589  
    104104begin
    105105  BasePath := ExtractFileDir(AIFileName);
    106   FileName := ExtractFileName(ExtractFileNameWithoutExt(ExtractFileNameWithoutExt(AIFileName)));
     106  FileName := ExtractFileNameOnly(ExtractFileNameOnly(AIFileName));
    107107  Name := FileName;
    108108  DLLName := BasePath + DirectorySeparator + Name + '.dll';
  • trunk/Direct.pas

    r565 r589  
    239239      if ExtractFileExt(FileName) = CevoExt then begin
    240240        Quick := True;
    241         if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1)
    242         ), -1, False) then begin
     241        if not LoadGame(ParamStr(1), -1, False) then begin
    243242          SimpleMessage(Phrases.Lookup('LOADERR'));
    244243          Close;
  • trunk/GameServer.pas

    r558 r589  
    6969procedure Done;
    7070
    71 procedure StartNewGame(const Path, FileName, Map: string;
     71procedure StartNewGame(const FileName, AMapFileName: string;
    7272  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
    73 function LoadGame(const Path, FileName: string; Turn: Integer;
     73function LoadGame(const FileName: string; Turn: Integer;
    7474  MovieMode: Boolean): Boolean;
    7575procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);
    7676procedure DirectHelp(Command: Integer);
     77function ToAutoSaveFileName(FileName: string): string;
     78function IsAutoSaveFileName(FileName: string): Boolean;
    7779
    7880procedure ChangeClient;
     
    391393end;
    392394
     395function ToAutoSaveFileName(FileName: string): string;
     396begin
     397  Result := ExtractFileDir(FileName) + DirectorySeparator + '~' + ExtractFileName(FileName);
     398end;
     399
     400function IsAutoSaveFileName(FileName: string): Boolean;
     401begin
     402  FileName := ExtractFileName(FileName);
     403  Result := (Length(FileName) > 0) and (FileName[1] = '~');
     404end;
     405
    393406procedure LogChanges;
    394407var
     
    579592begin
    580593  Result := False;
    581   MapFile := nil;
     594  if not FileExists(FileName) then Exit;
     595  MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);
    582596  try
    583     MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);
    584597    MapFile.Position := 0;
    585598    MapFile.Read(S[1], 8); { file id }
     
    611624      Result := True;
    612625    end;
     626  finally
    613627    FreeAndNil(MapFile);
    614   except
    615     if MapFile <> nil then
    616       FreeAndNil(MapFile);
    617628  end;
    618629end;
     
    641652
    642653  if Auto and AutoSaveExists then // append to existing file
    643     LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or
    644       fmShareExclusive)
     654    LogFile := TFileStream.Create(FileName, fmOpenReadWrite or fmShareExclusive)
    645655  else // create new file
    646     LogFile := TFileStream.Create(SavePath + FileName,
    647       fmCreate or fmShareExclusive);
     656    LogFile := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
    648657
    649658  Zero := 0;
     
    11111120end;
    11121121
    1113 function LoadGame(const Path, FileName: string; Turn: Integer;
    1114   MovieMode: Boolean): Boolean;
     1122function LoadGame(const FileName: string; Turn: Integer; MovieMode: Boolean): Boolean;
    11151123var
    11161124  J: TBrain;
     
    11251133  Started, StatRequest: Boolean;
    11261134begin
    1127   SavePath := Path;
     1135  SavePath := ExtractFileDir(FileName);
    11281136  LogFileName := FileName;
    11291137  LoadTurn := Turn;
    1130   LogFile := TFileStream.Create(SavePath + LogFileName, fmOpenRead or
     1138  LogFile := TFileStream.Create(LogFileName, fmOpenRead or
    11311139    fmShareExclusive);
    11321140  LogFile.Position := 0;
     
    12031211  else
    12041212    Mode := moLoading_Fast;
    1205 {$IFDEF TEXTLOG}AssignFile(TextLog, SavePath + LogFileName + '.txt');
     1213{$IFDEF TEXTLOG}AssignFile(TextLog, LogFileName + '.txt');
    12061214  Rewrite(TextLog); {$ENDIF}
    12071215  LoadOK := True;
     
    12991307  NoLogChanges;
    13001308  NoLogCityTileChanges;
    1301   if LogFileName[1] = '~' then
    1302   begin
     1309  if IsAutoSaveFileName(LogFileName) then begin
    13031310    Delete(LogFileName, 1, 1);
    13041311    nLogOpened := -1;
     
    13271334  if not LoadOK then
    13281335  begin
    1329     NotifyMessage := SavePath + LogFileName;
     1336    NotifyMessage := LogFileName;
    13301337    Notify(ntLoadError);
    13311338  end;
     
    13601367end;
    13611368
    1362 procedure StartNewGame(const Path, FileName, Map: string;
     1369procedure StartNewGame(const FileName, AMapFileName: string;
    13631370  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
    13641371var
     
    13661373begin
    13671374  Notify(ntStartDone);
    1368   SavePath := Path;
     1375  SavePath := ExtractFileDir(FileName);
    13691376  LogFileName := FileName;
    1370   MapFileName := Map;
     1377  MapFileName := AMapFileName;
    13711378  {$IFDEF FastContact}
    13721379    lx := 24;
     
    31383145            begin
    31393146              LogChanges;
    3140               SaveGame('~' + LogFileName, True);
     3147              SaveGame(ToAutoSaveFileName(LogFileName), True);
    31413148            end;
    31423149{$ENDIF}
     
    32683275            SaveGame(LogFileName, False);
    32693276          end;
    3270           DeleteFile(SavePath + '~' + LogFileName);
     3277          DeleteFile(ToAutoSaveFileName(LogFileName));
    32713278          EndGame;
    32723279          case Command of
     
    32763283              Notify(ntStartGo);
    32773284            sNextRound:
    3278               StartNewGame(SavePath, LogFileName, MapFileName, lx, ly,
    3279                 LandMass, MaxTurn);
     3285              StartNewGame(LogFileName, MapFileName, lx, ly, LandMass, MaxTurn);
    32803286            sReload:
    3281               LoadGame(SavePath, LogFileName, Integer(Data), False);
     3287              LoadGame(LogFileName, Integer(Data), False);
    32823288          end;
    32833289        end
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r570 r589  
    529529
    530530    FileName := ExtractFileNameWithoutExt(FileName) + GraphicSetFileExt;
     531
    531532    if FileExists(FileName) then
    532533      Result.LoadFromFile(FileName);
  • trunk/Start.pas

    r579 r589  
    66uses
    77  GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types,
    8   LCLIntf, LCLType, SysUtils, Classes, BaseWin, ListBoxEx,
     8  LCLIntf, LCLType, SysUtils, Classes, BaseWin, ListBoxEx, LazFileUtils,
    99  Registry, DrawDlg, Generics.Collections, Protocol, MiniMap, Brain, Translator,
    1010  {$IFDEF DPI}System.UITypes, Dpi.Graphics, Dpi.Controls, Dpi.Forms, Dpi.StdCtrls,
     
    905905      S := Phrases.Lookup('MPMAP')
    906906    else if Page = pgStartMap then
    907       S := Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt))
     907      S := ExtractFileNameOnly(MapFileName)
    908908    else if Page = pgEditMap then
    909909      S := List.Items[List.ItemIndex]
     
    944944  I: Integer;
    945945begin
    946   if FileName[1] <> '~' then
    947     FileName := '~' + FileName;
     946  if not IsAutoSaveFileName(FileName) then
     947    FileName := ToAutoSaveFileName(FileName);
    948948  I := FormerGames.Count - 1;
    949   while (I >= 0) and (AnsiCompareFileName(FormerGames[I], FileName) <> 0) do
     949  while (I >= 0) and (AnsiCompareFileName(FormerGames[I], ExtractFileNameOnly(FileName)) <> 0) do
    950950    Dec(I);
    951   if I >= 0 then
    952   begin
     951  if I >= 0 then begin
    953952    FormerGames.Delete(I);
    954953    if ListIndex[tbNew] = I then
     
    966965    pgLoad:
    967966      begin // load
    968         FileName := List.Items[List.ItemIndex];
    969         if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, False)
     967        FileName := GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt;
     968        if LoadGame(FileName, LoadTurn, False)
    970969        then
    971970          UnlistBackupFile(FileName)
     
    992991
    993992          if (AutoDiff < 0) and (PlayersBrain[0].Kind = btNoTerm) then
    994             FileName := 'Round' + IntToStr(GetProcessID())
     993            FileName := GetSavedDir + DirectorySeparator + 'Round' + IntToStr(GetProcessID()) + CevoExt
    995994          else begin
    996995            Inc(GameCount);
    997             FileName := Format(Phrases.Lookup('GAME'), [GameCount]);
     996            FileName := GetSavedDir + DirectorySeparator + Format(Phrases.Lookup('GAME'), [GameCount]) + CevoExt;
    998997          end;
    999998
     
    10491048        end;
    10501049
    1051         StartNewGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, MapFileName,
    1052           WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y, StartLandMass, MaxTurn);
     1050        StartNewGame(FileName, MapFileName, WorldSizes[WorldSize].X,
     1051          WorldSizes[WorldSize].Y, StartLandMass, MaxTurn);
    10531052        UnlistBackupFile(FileName);
    10541053      end;
    10551054    pgEditMap:
    1056       EditMap(GetMapsDir + DirectorySeparator + MapFileName, lxmax, lymax, StartLandMass);
     1055      EditMap(MapFileName, lxmax, lymax, StartLandMass);
    10571056    pgEditRandom: // new map
    10581057      begin
     
    10681067          Free;
    10691068        end;
    1070         MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + CevoMapExt;
    1071         EditMap(GetMapsDir + DirectorySeparator + MapFileName,
    1072           WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y, StartLandMass);
     1069        MapFileName := GetMapsDir + DirectorySeparator + Format(Phrases.Lookup('MAP'),
     1070          [MapCount]) + CevoMapExt;
     1071        EditMap(MapFileName, WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y,
     1072          StartLandMass);
    10731073      end;
    10741074  end;
     
    11201120        if Page = pgEditMap then begin
    11211121          if List.ItemIndex >= 0 then
    1122             MapFileName := List.Items[List.ItemIndex] + CevoMapExt
     1122            MapFileName := GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoMapExt
    11231123            else Exit;
    11241124        end;
    1125         MiniMap.LoadFromMapFile(GetMapsDir + DirectorySeparator + MapFileName,
    1126           nMapLandTiles, nMapStartPositions);
     1125        MiniMap.LoadFromMapFile(MapFileName, nMapLandTiles, nMapStartPositions);
    11271126        if Page = pgEditMap then
    11281127          SmartInvalidate(x0Mini - 112, y0Mini + 61, x0Mini + 112, y0Mini + 91);
     
    12961295      while (I > 0) and (F.Time < Integer(FormerGames.Objects[I - 1])) do
    12971296        Dec(I);
    1298       FormerGames.InsertObject(I, Copy(F.Name, 1, Length(F.Name) - 5),
     1297      FormerGames.InsertObject(I, ExtractFileNameOnly(F.Name),
    12991298        TObject(F.Time));
    13001299    until FindNext(F) <> 0;
     
    13181317  Maps.Sort;
    13191318  Maps.Insert(0, Phrases.Lookup('RANMAP'));
    1320   ListIndex[tbMain] := Maps.IndexOf(Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt)));
     1319  ListIndex[tbMain] := Maps.IndexOf(ExtractFileNameOnly(MapFileName));
    13211320  if ListIndex[tbMain] < 0 then
    13221321    ListIndex[tbMain] := 0;
     
    16611660    InputDlg.ShowModal;
    16621661    NewName := InputDlg.EditInput.Text;
    1663     while (NewName <> '') and (NewName[1] = '~') do
     1662    while IsAutoSaveFileName(NewName) do
    16641663      Delete(NewName, 1, 1);
    16651664    if (InputDlg.ModalResult = mrOK) and (NewName <> '') and
     
    19361935procedure TStartDlg.ReplayBtnClick(Sender: TObject);
    19371936begin
    1938   LoadGame(GetSavedDir + DirectorySeparator, List.Items[List.ItemIndex] + CevoExt,
     1937  LoadGame(GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt,
    19391938    LastTurn, True);
    19401939  SlotAvailable := -1;
Note: See TracChangeset for help on using the changeset viewer.