Changeset 292 for trunk


Ignore:
Timestamp:
Mar 28, 2019, 5:34:35 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Load game systems from files in Systems subdirectory on application start. Do not initialize game systems statically from code.
Location:
trunk
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r291 r292  
    99  UGame, UApplicationInfo, UPersistentForm, UScaleDPI, UCoolTranslator,
    1010  URegistry, ULastOpenedList, UTheme, Registry, Menus, UFormClient, UPlayer,
    11   UGameServer, UGameClient, fgl, UServerList, UGameSystem, UUnit, Graphics;
     11  UGameServer, UGameClient, fgl, UServerList, UGameSystem, Graphics;
    1212
    1313type
     
    8787    procedure UpdateOtherForms;
    8888    procedure FormClientActions;
    89     procedure InitGameSystems;
     89    procedure LoadGameSystems;
    9090  public
    9191    Game: TGame;
     
    129129uses
    130130  UFormMain, UFormNew, UFormSettings, UFormAbout, UClientAI, UFormKeyShortcuts,
    131   UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats, UClientGUI, UMapType,
    132   UNation;
     131  UFormHelp, UFormCharts, UFormUnitMoves, UFormPlayersStats, UClientGUI;
    133132
    134133const
     
    481480begin
    482481  GameSystems := TGameSystems.Create;
    483   InitGameSystems;
    484482  Server := TServer.Create;
    485483  LocalClients := TClients.Create;
    486484  GameSettings := TGame.Create;
    487   GameSettings.GameSystem := GameSystems.First;
    488485  Game := TGame.Create;
    489486  Game.OnMoveUpdated := DoMoveUpdated;
     
    491488  Game.OnNewTurn := GameNewTurnExecute;
    492489  Game.OnPlayerChange := DoPlayerChange;
    493   Game.GameSystem := GameSystems.First;
    494490  Server.Game := Game;
    495491  LocalClients.Game := Game;
     
    526522begin
    527523  LastOpenedList1.LoadToMenuItem(FormMain.MenuItemLoadRecent, LoadRecentExecute);
    528 end;
    529 
    530 procedure TCore.InitGameSystems;
    531 begin
    532   with GameSystems.AddNew('Custom') do begin
    533     PreferedMapType := mtNone;
    534     MaxPlayerCount := 3;
    535     with TNation(Nations.AddItem('Nation 1')) do begin
    536       Color := clBlue;
    537     end;
    538     with TNation(Nations.AddItem('Nation 2')) do begin
    539       Color := clRed;
    540     end;
    541     with TNation(Nations.AddItem('Nation 3')) do begin
    542       Color := clGreen;
    543     end;
    544     with TNation(Nations.AddItem('Nation 4')) do begin
    545       Color := clOrange;
    546     end;
    547     with TNation(Nations.AddItem('Nation 5')) do begin
    548       Color := clPurple;
    549     end;
    550     with TNation(Nations.AddItem('Nation 6')) do begin
    551       Color := clMaroon;
    552     end;
    553     with TNation(Nations.AddItem('Nation 7')) do begin
    554       Color := clAqua;
    555     end;
    556     with TNation(Nations.AddItem('Nation 8')) do begin
    557       Color := clFuchsia;
    558     end;
    559     with TUnitKind(UnitKinds.AddItem('Unit')) do begin
    560       Moves := 1;
    561       Power := 99;
    562     end;
    563   end;
    564 
    565   with GameSystems.AddNew('HexWars') do begin
    566     PreferedMapType := mtHexagonVertical;
    567     UnitsMoveImmediately := False;
    568     MaxPlayerCount := 8;
    569     with TNation(Nations.AddItem('Nation 1')) do begin
    570       Color := clBlue;
    571     end;
    572     with TNation(Nations.AddItem('Nation 2')) do begin
    573       Color := clRed;
    574     end;
    575     with TNation(Nations.AddItem('Nation 3')) do begin
    576       Color := clGreen;
    577     end;
    578     with TNation(Nations.AddItem('Nation 4')) do begin
    579       Color := clOrange;
    580     end;
    581     with TNation(Nations.AddItem('Nation 5')) do begin
    582       Color := clPurple;
    583     end;
    584     with TNation(Nations.AddItem('Nation 6')) do begin
    585       Color := clMaroon;
    586     end;
    587     with TNation(Nations.AddItem('Nation 7')) do begin
    588       Color := clAqua;
    589     end;
    590     with TNation(Nations.AddItem('Nation 8')) do begin
    591       Color := clFuchsia;
    592     end;
    593     with TUnitKind(UnitKinds.AddItem('Unit')) do begin
    594       Moves := 1;
    595       Power := 99;
    596     end;
    597   end;
    598 
    599   with GameSystems.AddNew('Civilization I') do begin
    600     PreferedMapType := mtSquare;
    601     UnitsMoveImmediately := True;
    602     MaxPlayerCount := 3;
    603     with TNation(Nations.AddItem('Americans')) do begin
    604       Color := clFuchsia;
    605     end;
    606     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    607       Moves := 1;
    608       Power := 1;
    609     end;
    610     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    611       Moves := 1;
    612       Power := 1;
    613     end;
    614   end;
    615 
    616   with GameSystems.AddNew('Civilization II') do begin
    617     PreferedMapType := mtIsometric;
    618     UnitsMoveImmediately := True;
    619     MaxPlayerCount := 3;
    620     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    621       Moves := 1;
    622       Power := 1;
    623     end;
    624     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    625       Moves := 1;
    626       Power := 1;
    627     end;
    628   end;
    629 
    630   with GameSystems.AddNew('Civilization III') do begin
    631     PreferedMapType := mtIsometric;
    632     UnitsMoveImmediately := True;
    633     MaxPlayerCount := 3;
    634     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    635       Moves := 1;
    636       Power := 1;
    637     end;
    638     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    639       Moves := 1;
    640       Power := 1;
    641     end;
    642   end;
    643 
    644   with GameSystems.AddNew('Civilization IV') do begin
    645     PreferedMapType := mtIsometric;
    646     UnitsMoveImmediately := True;
    647     MaxPlayerCount := 3;
    648     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    649       Moves := 1;
    650       Power := 1;
    651     end;
    652     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    653       Moves := 1;
    654       Power := 1;
    655     end;
    656   end;
    657 
    658   with GameSystems.AddNew('Civilization V') do begin
    659     PreferedMapType := mtHexagonHorizontal;
    660     UnitsMoveImmediately := True;
    661     MaxPlayerCount := 3;
    662     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    663       Moves := 1;
    664       Power := 1;
    665     end;
    666     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    667       Moves := 1;
    668       Power := 1;
    669     end;
    670   end;
    671 
    672   with GameSystems.AddNew('Civilization VI') do begin
    673     PreferedMapType := mtHexagonHorizontal;
    674     UnitsMoveImmediately := True;
    675     MaxPlayerCount := 3;
    676     with TUnitKind(UnitKinds.AddItem('Scout')) do begin
    677       Moves := 1;
    678       Power := 1;
    679     end;
    680     with TUnitKind(UnitKinds.AddItem('Settler')) do begin
    681       Moves := 1;
    682       Power := 1;
    683     end;
    684   end;
    685 
    686   with GameSystems.AddNew('Dune 2') do begin
    687     PreferedMapType := mtSquare;
    688     UnitsMoveImmediately := True;
    689     MaxPlayerCount := 3;
    690     with TNation(Nations.AddItem('Attreides')) do begin
    691       Color := clBlue;
    692     end;
    693     with TNation(Nations.AddItem('Harkonen')) do begin
    694       Color := clRed;
    695     end;
    696     with TNation(Nations.AddItem('Ordos')) do begin
    697       Color := clGreen;
    698     end;
    699     with TNation(Nations.AddItem('Fremens')) do begin
    700       Color := clBrown;
    701     end;
    702     with TNation(Nations.AddItem('Sardaukers')) do begin
    703       Color := clPurple;
    704     end;
    705     with TNation(Nations.AddItem('Merceneries')) do begin
    706       Color := clOrange;
    707     end;
    708     with TUnitKind(UnitKinds.AddItem('Light Infantry')) do begin
    709       Moves := 1;
    710     end;
    711     with TUnitKind(UnitKinds.AddItem('Heavy Troopers')) do begin
    712       Moves := 1;
    713     end;
    714     with TUnitKind(UnitKinds.AddItem('Trike')) do begin
    715       Moves := 1;
    716     end;
    717     with TUnitKind(UnitKinds.AddItem('Quad')) do begin
    718       Moves := 1;
    719     end;
    720   end;
    721 
    722   with GameSystems.AddNew('Battle Isle 2') do begin
    723     PreferedMapType := mtHexagonHorizontal;
    724     UnitsMoveImmediately := True;
    725     MaxPlayerCount := 8;
    726     with TUnitKind(UnitKinds.AddItem('Demon 132')) do begin
    727       Moves := 4;
    728       Power := 10;
    729     end;
    730     with TUnitKind(UnitKinds.AddItem('Troll 142')) do begin
    731       Moves := 3;
    732       Power := 10;
    733     end;
    734     with TUnitKind(UnitKinds.AddItem('Ranger 132')) do begin
    735       Moves := 10;
    736       Power := 10;
    737     end;
    738     with TUnitKind(UnitKinds.AddItem('Buggy')) do begin
    739       Moves := 10;
    740       Power := 10;
    741     end;
    742   end;
    743 
    744   with GameSystems.AddNew('Panzer General') do begin
    745     PreferedMapType := mtHexagonHorizontal;
    746     UnitsMoveImmediately := True;
    747     MaxPlayerCount := 2;
    748     with TNation(Nations.AddItem('Germany')) do begin
    749       Color := clBlue;
    750     end;
    751     with TNation(Nations.AddItem('Russia')) do begin
    752       Color := clRed;
    753     end;
    754     with TNation(Nations.AddItem('Alliance')) do begin
    755       Color := clGreen;
    756     end;
    757     with TUnitKind(UnitKinds.AddItem('Rifle Team')) do begin
    758       Moves := 1;
    759     end;
    760     with TUnitKind(UnitKinds.AddItem('Machine Gun')) do begin
    761       Moves := 1;
    762     end;
    763     with TUnitKind(UnitKinds.AddItem('Heavy Infantry')) do begin
    764       Moves := 1;
    765     end;
    766     with TUnitKind(UnitKinds.AddItem('Granadiers')) do begin
    767       Moves := 1;
    768     end;
    769   end;
    770524end;
    771525
     
    845599end;
    846600
     601procedure TCore.LoadGameSystems;
     602var
     603  NewItem: TGameSystem;
     604begin
     605  if DirectoryExists('Systems') then begin
     606    GameSystems.LoadFromDir('Systems');
     607  end else begin
     608    NewItem := TGameSystem.Create;
     609    NewItem.FileName := 'Custom';
     610    GameSystems.Add(NewItem);
     611  end;
     612  if GameSystems.Count > 0 then begin
     613    GameSettings.GameSystem := GameSystems.First;
     614    Game.GameSystem := GameSystems.First;
     615  end;
     616end;
     617
    847618procedure TCore.ReopenGameOnInit;
    848619begin
     
    953724  if not Core.Initialized then begin
    954725    FInitialized := True;
     726    LoadGameSystems;
    955727
    956728    // Update translated default player names
  • trunk/UGameSystem.pas

    r289 r292  
    77uses
    88  Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf,
    9   FileUtil, UMapType, UNation, UBuilding;
     9  FileUtil, LazFileUtils, UMapType, UNation, UBuilding;
    1010
    1111type
     
    4242    function AddNew(Name: string): TGameSystem;
    4343    function SearchByName(Name: string): TGameSystem;
     44    procedure LoadFromDir(Dir: string);
    4445  end;
    4546
     
    7374  if I < Count then Result := Items[I]
    7475    else Result := nil;
     76end;
     77
     78procedure TGameSystems.LoadFromDir(Dir: string);
     79var
     80  Files: TStringList;
     81  I: Integer;
     82  NewItem: TGameSystem;
     83begin
     84  Files := TStringList.Create;
     85  FindAllFiles(Files, Dir, '*' + GameSystemExt, True, faAnyFile);
     86  for I := 0 to Files.Count - 1 do begin
     87    NewItem := TGameSystem.Create;
     88    NewItem.LoadFromFile(Files[I]);
     89    Add(NewItem);
     90  end;
     91  Files.Free;
    7592end;
    7693
Note: See TracChangeset for help on using the changeset viewer.