Changeset 344 for trunk/Game.pas


Ignore:
Timestamp:
Dec 23, 2024, 8:16:05 AM (10 hours ago)
Author:
chronos
Message:
  • Modified: Improved implementation of TItemList class to be generic class to avoid explicit typecasting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r342 r344  
    295295var
    296296  Cell: TCell;
    297   NewPower: Integer;
    298297begin
    299298  // Randomize map terrain
     
    317316    NewPower := Random(MaxNeutralUnits + 1);
    318317    if (NewPower > 0) and not Assigned(OneUnit) then begin
    319       OneUnit := Units.AddNew(TUnitKind(GameSystem.UnitKinds[0]), NewPower);
     318      OneUnit := Units.AddNew(GameSystem.UnitKinds[0], NewPower);
    320319    end;
    321320    Player := nil;
     
    330329  with Cell do begin
    331330    if (Terrain = ttNormal) and CityEnabled and (Random < CityPercentage / 100) then begin
    332       Building := TBuilding(Buildings.AddItem('City'));
    333       Building.Kind := TBuildingKind(GameSystem.BuildingKinds.FindBySpecialType(stCity));
     331      Building := Buildings.AddItem('City');
     332      Building.Kind := GameSystem.BuildingKinds.FindBySpecialType(stCity);
    334333    end;
    335334  end;
     
    344343
    345344  for I := 0 to Players.Count - 1 do begin
    346     TPlayer(Players[I]).Reset;
    347     TPlayer(Players[I]).StartCell := nil;
     345    Players[I].Reset;
     346    Players[I].StartCell := nil;
    348347  end;
    349348  for I := 0 to Players.Count - 1 do
    350   with TPlayer(Players[I]) do begin
    351     Player := TPlayer(Players[I]);
     349  with Players[I] do begin
     350    Player := Players[I];
    352351    PlayerMap.Update;
    353352    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
     
    355354      if Assigned(Player.StartCell) then begin
    356355        if SymetricMap and (I = 1) then
    357           StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(TPlayer(Players[0]).StartCell)];
     356          StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(Players[0].StartCell)];
    358357
    359358        if CityEnabled then begin
    360           StartCell.Building := TBuilding(Buildings.AddItem('City'));
    361           StartCell.Building.Kind := TBuildingKind(GameSystem.BuildingKinds.FindBySpecialType(stCity));
     359          StartCell.Building := Buildings.AddItem('City');
     360          StartCell.Building.Kind := GameSystem.BuildingKinds.FindBySpecialType(stCity);
    362361        end;
    363362        StartCell.Player := Player;
    364363        if GameSystem.UnitKinds.Count > 0 then begin
    365364          if not Assigned(StartCell.OneUnit) then
    366             StartCell.OneUnit := Self.Units.AddNew(TUnitKind(GameSystem.UnitKinds[0]), Player.StartUnits);
     365            StartCell.OneUnit := Self.Units.AddNew(GameSystem.UnitKinds[0], Player.StartUnits);
    367366          StartCell.OneUnit.Power := Player.StartUnits;
    368           StartCell.OneUnit.Kind := TUnitKind(GameSystem.UnitKinds[0]);
     367          StartCell.OneUnit.Kind := GameSystem.UnitKinds[0];
    369368          StartCell.OneUnit.Player := Player;
    370369        end;
     
    428427begin
    429428  for I := 0 to Players.Count - 1 do begin
    430     Player := TPlayer(Players[I]);
     429    Player := Players[I];
    431430    if Assigned(Player.StartCell) then begin
    432431      Player.StartCell.Weight := 1;
     
    633632      if Assigned(NewNode) then
    634633        Players.LoadFromNode(NewNode);
    635       if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     634      if Players.Count > 0 then CurrentPlayer := Players[0]
    636635        else CurrentPlayer := nil;
    637636
     
    644643
    645644      for I := 0 to Players.Count - 1 do begin
    646         TPlayer(Players[I]).PlayerMap.Update;
    647         TPlayer(Players[I]).PlayerMap.CheckVisibility;
     645        Players[I].PlayerMap.Update;
     646        Players[I].PlayerMap.CheckVisibility;
    648647      end;
    649648      ComputePlayerStats;
     
    742741begin
    743742  for I := 0 to Players.Count - 1 do
    744   with TPlayer(Players[I]) do begin
     743  with Players[I] do begin
    745744    TotalUnits := 0;
    746745    TotalCells := 0;
     
    763762begin
    764763  for I := 0 to Players.Count - 1 do
    765   with TPlayer(Players[I]) do begin
     764  with Players[I] do begin
    766765    NewStat := TGameTurnStat.Create;
    767766    NewStat.DiscoveredCells := TotalDiscovered;
     
    804803      NewPlayerIndex := NewPlayerIndex mod AlivePlayers.Count;
    805804    end;
    806     CurrentPlayer := TPlayer(AlivePlayers[NewPlayerIndex]);
     805    CurrentPlayer := AlivePlayers[NewPlayerIndex];
    807806  finally
    808807    AlivePlayers.Free;
     
    931930  I: Integer;
    932931begin
    933   for I := 0 to Players.Count - 1 do TPlayer(Players[I]).Clear;
     932  for I := 0 to Players.Count - 1 do Players[I].Clear;
    934933  Map.Clear;
    935934  Units.Clear;
     
    960959
    961960  InitPlayers;
    962   if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     961  if Players.Count > 0 then CurrentPlayer := Players[0]
    963962    else CurrentPlayer := nil;
    964963
Note: See TracChangeset for help on using the changeset viewer.