Changeset 59


Ignore:
Timestamp:
Nov 25, 2020, 11:59:46 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Code cleanup. Removed explicit class typecasts.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BigMetro.lpi

    r55 r59  
    5858          <Other>
    5959            <CompilerMessages>
    60               <IgnoredMessages idx5024="True"/>
     60              <IgnoredMessages idx6058="True" idx5024="True" idx3124="True"/>
    6161            </CompilerMessages>
    6262          </Other>
     
    151151    <Other>
    152152      <CompilerMessages>
    153         <IgnoredMessages idx5024="True"/>
     153        <IgnoredMessages idx6058="True" idx5024="True" idx3124="True"/>
    154154      </CompilerMessages>
    155155      <CustomOptions Value="-dDEBUG"/>
  • trunk/UEngine.pas

    r52 r59  
    188188  public
    189189    Passengers: TMetroPassengers;
    190 
    191190    BaseTrackPoint: TTrackPoint;
    192191    RelPos: Double;
     
    371370  I := 0;
    372371  while (I < 0) and
    373   ((TTrackLink(Items[I]).Points.First <> Point1) or (TTrackLink(Items[I]).Points.Last <> Point2))
    374   and ((TTrackLink(Items[I]).Points.First <> Point2) or (TTrackLink(Items[I]).Points.Last <> Point1)) do
     372  ((Items[I].Points.First <> Point1) or (Items[I].Points.Last <> Point2))
     373  and ((Items[I].Points.First <> Point2) or (Items[I].Points.Last <> Point1)) do
    375374  Inc(I);
    376   if I < 0 then Result := TTrackLink(Items[I])
     375  if I < 0 then Result := Items[I]
    377376    else Result := nil;
    378377end;
     
    406405  Points.Free;
    407406  Links.Free;
    408   inherited Destroy;
     407  inherited;
    409408end;
    410409
     
    420419begin
    421420  Points.Free;
    422   inherited Destroy;
     421  inherited;
    423422end;
    424423
     
    442441begin
    443442  Rivers.Free;
    444   inherited Destroy;
     443  inherited;
    445444end;
    446445
     
    510509begin
    511510  I := 0;
    512   while (I < Count) and (TTrackLink(Items[I]).Points[1] <> TrackPoint) and (TTrackLink(Items[I]) <> Skip) do Inc(I);
    513   if I < Count then Result := TTrackLink(Items[I])
     511  while (I < Count) and (Items[I].Points[1] <> TrackPoint) and (Items[I] <> Skip) do Inc(I);
     512  if I < Count then Result := Items[I]
    514513    else Result := nil;
    515514end;
     
    520519begin
    521520  I := 0;
    522   while (I < Count) and (TTrackLink(Items[I]).Points[0] <> TrackPoint) and (TTrackLink(Items[I]) <> Skip) do Inc(I);
    523   if I < Count then Result := TTrackLink(Items[I])
     521  while (I < Count) and (Items[I].Points[0] <> TrackPoint) and (Items[I] <> Skip) do Inc(I);
     522  if I < Count then Result := Items[I]
    524523    else Result := nil;
    525524end;
     
    532531begin
    533532  I := 0;
    534   while (I < Count) and (TTrackPointsAngle(Items[I]).Angle <> Angle) do Inc(I);
    535   if I < Count then Result := TTrackPointsAngle(Items[I])
     533  while (I < Count) and (Items[I].Angle <> Angle) do Inc(I);
     534  if I < Count then Result := Items[I]
    536535    else Result := nil;
    537536end;
     
    548547begin
    549548  TrackLinks.Free;
    550   inherited Destroy;
     549  inherited;
    551550end;
    552551
     
    594593begin
    595594  I := Track.Points.IndexOf(Self) - 1;
    596   while (I >= 0) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do
     595  while (I >= 0) and not Assigned(Track.Points[I].LineStation) do
    597596    Dec(I);
    598   if I >= 0 then Result := TTrackPoint(Track.Points[I])
     597  if I >= 0 then Result := Track.Points[I]
    599598    else Result := nil;
    600599end;
     
    605604begin
    606605  I := Track.Points.IndexOf(Self) + 1;
    607   while (I < Track.Points.Count) and not Assigned(TTrackPoint(Track.Points[I]).LineStation) do
     606  while (I < Track.Points.Count) and not Assigned(Track.Points[I].LineStation) do
    608607    Inc(I);
    609   if I < Track.Points.Count then Result := TTrackPoint(Track.Points[I])
     608  if I < Track.Points.Count then Result := Track.Points[I]
    610609    else Result := nil;
    611610end;
     
    617616  Result := nil;
    618617  NewIndex := Track.Points.IndexOf(Self) - 1;
    619   if NewIndex >= 0 then Result := TTrackPoint(Track.Points[NewIndex]);
     618  if NewIndex >= 0 then Result := Track.Points[NewIndex];
    620619end;
    621620
     
    627626  if Assigned(Track) then begin
    628627    NewIndex := Track.Points.IndexOf(Self) + 1;
    629     if NewIndex < Track.Points.Count then Result := TTrackPoint(Track.Points[NewIndex]);
     628    if NewIndex < Track.Points.Count then Result := Track.Points[NewIndex];
    630629  end;
    631630end;
     
    660659begin
    661660  Index := Track.Points.IndexOf(Self);
    662   Result := Distance(TTrackPoint(Track.Points[Index + 1]).Position,
    663     TTrackPoint(Track.Points[Index]).Position);
     661  Result := Distance(Track.Points[Index + 1].Position, Track.Points[Index].Position);
    664662end;
    665663
     
    676674  NeighLinks.Free;
    677675  NeighPoints.Free;
    678   inherited Destroy;
     676  inherited;
    679677end;
    680678
     
    686684begin
    687685  I := 0;
    688   while (I < Count) and (TLineStation(Items[I]).MapStation <> Station) do Inc(I);
    689   if I < Count then Result := TLineStation(Items[I])
     686  while (I < Count) and (Items[I].MapStation <> Station) do Inc(I);
     687  if I < Count then Result := Items[I]
    690688    else Result := nil;
    691689end;
     
    708706begin
    709707  I := 0;
    710   while (I < Count) and (Assigned(TMetroTrain(Items[I]).Line)) do Inc(I);
    711   if I < Count then Result := TMetroTrain(Items[I])
     708  while (I < Count) and (Assigned(Items[I].Line)) do Inc(I);
     709  if I < Count then Result := Items[I]
    712710    else Result := nil;
    713711end;
     
    719717  Result := 0;
    720718  for I := 0 to Count - 1 do
    721     if not Assigned(TMetroTrain(Items[I]).Line) then Inc(Result);
     719    if not Assigned(Items[I].Line) then Inc(Result);
    722720end;
    723721
     
    735733begin
    736734  if Count > 0 then begin
    737     with TMapStation(Items[0]) do
     735    with Items[0] do
    738736      Result := Rect(Position.X, Position.Y, Position.X, Position.Y);
    739737    for I := 1 to Count - 1 do
    740     with TMapStation(Items[I]) do begin
     738    with Items[I] do begin
    741739      if Position.X < Result.Left then Result.Left := Position.X;
    742740      if Position.X > Result.Right then Result.Right := Position.X;
     
    769767    MinD := High(Integer);
    770768    for I := 0 to Engine.Stations.Count - 1 do begin
    771       D := Distance(TMapStation(Engine.Stations[I]).Position, Result.Position);
     769      D := Distance(Engine.Stations[I].Position, Result.Position);
    772770      if D < MinD then MinD := D;
    773771    end;
     
    797795begin
    798796  I := 0;
    799   while (I < Count) and (TMetroLine(Items[I]).Color <> Color) do Inc(I);
    800   if I < Count then Result := TMetroLine(Items[I])
     797  while (I < Count) and (Items[I].Color <> Color) do Inc(I);
     798  if I < Count then Result := Items[I]
    801799    else Result := nil;
    802800end;
     
    812810begin
    813811  if LineStations.Count >= 2 then begin
    814     Index := Track.Points.IndexOf(TLineStation(LineStations.First).TrackPoint);
     812    Index := Track.Points.IndexOf(LineStations.First.TrackPoint);
    815813    if Index = 0 then begin
    816814      NewTrackPoint := Track.Points.AddNew;
    817815      Track.Points.Insert(0, NewTrackPoint);
    818816    end;
    819     Index := Track.Points.IndexOf(TLineStation(LineStations.Last).TrackPoint);
     817    Index := Track.Points.IndexOf(LineStations.Last.TrackPoint);
    820818    if Index = Track.Points.Count - 1 then begin
    821819      NewTrackPoint := Track.Points.AddNew;
     
    823821    end;
    824822
    825     Angle := ArcTan2((TTrackPoint(Track.Points[2]).PositionDesigned.Y - TTrackPoint(Track.Points[1]).PositionDesigned.Y),
    826       (TTrackPoint(Track.Points[2]).PositionDesigned.X - TTrackPoint(Track.Points[1]).PositionDesigned.X));
    827     EndPoint := Point(Round(TTrackPoint(Track.Points[1]).PositionDesigned.X - EndStationLength * Cos(Angle)),
    828       Round(TTrackPoint(Track.Points[1]).PositionDesigned.Y - EndStationLength * Sin(Angle)));
    829     TTrackPoint(Track.Points.First).PositionDesigned := EndPoint;
    830     TTrackPoint(Track.Points.First).Position := EndPoint;
    831 
    832     Angle := ArcTan2((TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.Y),
    833       (TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X - TTrackPoint(Track.Points[Track.Points.Count - 3]).PositionDesigned.X));
    834     EndPoint := Point(Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.X + EndStationLength * Cos(Angle)),
    835       Round(TTrackPoint(Track.Points[Track.Points.Count - 2]).PositionDesigned.Y + EndStationLength * Sin(Angle)));
    836     TTrackPoint(Track.Points.Last).PositionDesigned := EndPoint;
    837     TTrackPoint(Track.Points.Last).Position := EndPoint;
     823    Angle := ArcTan2((Track.Points[2].PositionDesigned.Y - Track.Points[1].PositionDesigned.Y),
     824      (Track.Points[2].PositionDesigned.X - Track.Points[1].PositionDesigned.X));
     825    EndPoint := Point(Round(Track.Points[1].PositionDesigned.X - EndStationLength * Cos(Angle)),
     826      Round(Track.Points[1].PositionDesigned.Y - EndStationLength * Sin(Angle)));
     827    Track.Points.First.PositionDesigned := EndPoint;
     828    Track.Points.First.Position := EndPoint;
     829
     830    Angle := ArcTan2((Track.Points[Track.Points.Count - 2].PositionDesigned.Y - Track.Points[Track.Points.Count - 3].PositionDesigned.Y),
     831      (Track.Points[Track.Points.Count - 2].PositionDesigned.X - Track.Points[Track.Points.Count - 3].PositionDesigned.X));
     832    EndPoint := Point(Round(Track.Points[Track.Points.Count - 2].PositionDesigned.X + EndStationLength * Cos(Angle)),
     833      Round(Track.Points[Track.Points.Count - 2].PositionDesigned.Y + EndStationLength * Sin(Angle)));
     834    Track.Points.Last.PositionDesigned := EndPoint;
     835    Track.Points.Last.Position := EndPoint;
    838836  end;
    839837end;
     
    879877    if Assigned(Train) then begin
    880878      Train.Line := Self;
    881       Train.TargetStation := TLineStation(LineStations[0]);
    882       Train.BaseTrackPoint := TTrackPoint(Track.Points.First);
     879      Train.TargetStation := LineStations[0];
     880      Train.BaseTrackPoint := Track.Points.First;
    883881      Trains.Add(Train);
    884882    end;
     
    899897  // Determine track point range to be removed
    900898  TP1 := ALineStation.TrackPoint.GetDown;
    901   if not Assigned(TP1) then TP1 := TTrackPoint(Track.Points.First);
     899  if not Assigned(TP1) then TP1 := Track.Points.First;
    902900  TP2 := ALineStation.TrackPoint.GetUp;
    903   if not Assigned(TP2) then TP2 := TTrackPoint(Track.Points.Last);
     901  if not Assigned(TP2) then TP2 := Track.Points.Last;
    904902
    905903  // Remove track points from trains
    906904  for I := 0 to Trains.Count - 1 do
    907   with TMetroTrain(Trains[I]) do begin
     905  with Trains[I] do begin
    908906    IsOnTrack := False;
    909907    for J := Track.Points.IndexOf(TP1) to Track.Points.IndexOf(TP2) do
    910     if TTrackPoint(Track.Points[J]) = BaseTrackPoint then begin
     908    if Track.Points[J] = BaseTrackPoint then begin
    911909      IsOnTrack := True;
    912910      Break;
     
    924922  // Delete old trackpoints
    925923  Index := Track.Points.IndexOf(ALineStation.TrackPoint) - 1;
    926   while (Index >= 0) and (not Assigned(TTrackPoint(Track.Points[Index]).LineStation)) do begin
     924  while (Index >= 0) and (not Assigned(Track.Points[Index].LineStation)) do begin
    927925    Track.Points.Delete(Index);
    928926    Dec(Index);
     
    930928  Index := Index + 1;
    931929  Track.Points.Delete(Index);
    932   while (Index < Track.Points.Count) and (not Assigned(TTrackPoint(Track.Points[Index]).LineStation)) do
     930  while (Index < Track.Points.Count) and (not Assigned(Track.Points[Index].LineStation)) do
    933931    Track.Points.Delete(Index);
    934932
    935933  if ((Index - 1) >= 0) and (Index < Track.Points.Count) then
    936     Track.RouteTrack(TTrackPoint(Track.Points[Index - 1]), TTrackPoint(Track.Points[Index]));
     934    Track.RouteTrack(Track.Points[Index - 1], Track.Points[Index]);
    937935
    938936  ALineStation.MapStation.Lines.Remove(Self);
     
    940938
    941939  for I := 0 to Trains.Count - 1 do
    942   with TMetroTrain(Trains[I]) do begin
     940  with Trains[I] do begin
    943941    if TargetStation = ALineStation then
    944       TargetStation := TLineStation(LineStations[(Index + 1) mod LineStations.Count]);
     942      TargetStation := LineStations[(Index + 1) mod LineStations.Count];
    945943  end;
    946944
     
    950948  if LineStations.Count < 2 then
    951949  for I := Trains.Count - 1 downto 0 do begin
    952     TMetroTrain(Trains[I]).Line := nil;
     950    Trains[I].Line := nil;
    953951    Trains.Delete(I);
    954952  end;
     
    968966  Index1 := Points.IndexOf(TP1);
    969967  Index2 := Points.IndexOf(TP2);
    970   P1 := TTrackPoint(Points[Index1]).PositionDesigned;
    971   P2 := TTrackPoint(Points[Index2]).PositionDesigned;
     968  P1 := Points[Index1].PositionDesigned;
     969  P2 := Points[Index2].PositionDesigned;
    972970  NewTrackPoint := Points.AddNew;
    973971  Delta := Point(P2.X - P1.X, P2.Y - P1.Y);
     
    10101008  for I := 0 to Track.Points.Count - 1 do
    10111009  if I > 0 then
    1012     Result := Result + Distance(TTrackPoint(Track.Points[I]).Position, TTrackPoint(Track.Points[I - 1]).Position);
     1010    Result := Result + Distance(Track.Points[I].Position, Track.Points[I - 1].Position);
    10131011end;
    10141012
     
    10281026  LineStations.Free;
    10291027  Track.Free;
    1030   inherited Destroy;
     1028  inherited;
    10311029end;
    10321030
     
    10351033  Result := False;
    10361034  if LineStations.Count >= 2 then
    1037     Result := (TLineStation(LineStations.Last).MapStation = TLineStation(LineStations.First).MapStation);
     1035    Result := (LineStations.Last.MapStation = LineStations.First.MapStation);
    10381036end;
    10391037
     
    10631061  if Current < Target then begin
    10641062    for I := Current to Target - 1 do
    1065       Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;
     1063      Result := Result + Line.Track.Points[I].GetDistance;
    10661064    Result := Result - Trunc(RelPos);
    10671065  end else
    10681066  if Current > Target then begin
    10691067    for I := Current - 1 downto Target do
    1070       Result := Result + TTrackPoint(Line.Track.Points[I]).GetDistance;
     1068      Result := Result + Line.Track.Points[I].GetDistance;
    10711069    Result := Result + Trunc(RelPos);
    10721070  end else Result := Trunc(RelPos);
     
    11211119begin
    11221120  Passengers.Free;
    1123   inherited Destroy;
     1121  inherited;
    11241122end;
    11251123
     
    11491147  SortLines;
    11501148  for I := 0 to Lines.Count - 1 do begin
    1151     Line := TMetroLine(Lines[I]);
     1149    Line := Lines[I];
    11521150    LS := Line.LineStations.SearchMapStation(Self);
    11531151    TP := LS.TrackPoint;
    11541152    Index := Line.Track.Points.IndexOf(TP);
    11551153    if Index > 0 then begin
    1156       NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown;
     1154      NewTrackLink := Line.Track.Points[Index].GetLinkDown;
    11571155      TrackLinks.Add(NewTrackLink);
    11581156    end;
    11591157    if Index < (Line.Track.Points.Count - 1) then begin
    1160       NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp;
     1158      NewTrackLink := Line.Track.Points[Index].GetLinkUp;
    11611159      TrackLinks.Add(NewTrackLink);
    11621160    end;
    1163     if Line.IsCircular and (Self = TLineStation(Line.LineStations.First).MapStation) and
    1164     (Self = TLineStation(Line.LineStations.Last).MapStation) then begin
    1165       LS := TLineStation(Line.LineStations.Last);
     1161    if Line.IsCircular and (Self = Line.LineStations.First.MapStation) and
     1162    (Self = Line.LineStations.Last.MapStation) then begin
     1163      LS := Line.LineStations.Last;
    11661164      TP := LS.TrackPoint;
    11671165      Index := Line.Track.Points.IndexOf(TP);
    11681166      if Index > 0 then begin
    1169         NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkDown;
     1167        NewTrackLink := Line.Track.Points[Index].GetLinkDown;
    11701168        TrackLinks.Add(NewTrackLink);
    11711169      end;
    11721170      if Index < (Line.Track.Points.Count - 1) then begin
    1173         NewTrackLink := TTrackPoint(Line.Track.Points[Index]).GetLinkUp;
     1171        NewTrackLink := Line.Track.Points[Index].GetLinkUp;
    11741172        TrackLinks.Add(NewTrackLink);
    11751173      end;
     
    11801178  TPAngleGroup := TTrackPointsAngleGroup.Create;
    11811179  for I := 0 to TrackLinks.Count - 1 do begin
    1182     P1 := TTrackPoint(TTrackLink(TrackLinks[I]).Points[0]).PositionDesigned;
    1183     P2 := TTrackPoint(TTrackLink(TrackLinks[I]).Points[1]).PositionDesigned;
     1180    P1 := TrackLinks[I].Points[0].PositionDesigned;
     1181    P2 := TrackLinks[I].Points[1].PositionDesigned;
    11841182    if ComparePoint(P1, Position) and not ComparePoint(P2, Position) then begin
    11851183      Angle := ArcTan2(P2.Y - Position.Y, P2.X - Position.X);
     
    11951193      TPAngleGroup.Add(GroupItem);
    11961194    end;
    1197     GroupItem.TrackLinks.Add(TTrackLink(TrackLinks[I]))
     1195    GroupItem.TrackLinks.Add(TrackLinks[I])
    11981196  end;
    11991197
    12001198  // Shift TrackLinks according number of lines in group
    12011199  for I := 0 to TPAngleGroup.Count - 1 do
    1202   with TTrackPointsAngle(TPAngleGroup[I]) do begin
     1200  with TPAngleGroup[I] do begin
    12031201    for J := 0 to TrackLinks.Count - 1 do
    1204       with TTrackLink(TrackLinks[J]) do begin
     1202      with TrackLinks[J] do begin
    12051203        // Get orthogonal angle
    12061204        HAngle := Angle + Pi / 2;
     
    12441242  Distance := High(Integer);
    12451243  for I := 0 to Lines.Count - 1 do
    1246   with TMetroLine(Lines[I]) do begin
     1244  with Lines[I] do begin
    12471245    CurrentLineStation := LineStations.SearchMapStation(Current.MapStation);
    12481246    StationIndex := LineStations.IndexOf(CurrentLineStation);
     
    12511249      DirectionDown := False;
    12521250      for T := 0 to Trains.Count - 1 do begin
    1253         if TMetroTrain(Trains[T]).Direction = 1 then DirectionUp := True;
    1254         if TMetroTrain(Trains[T]).Direction = -1 then DirectionDown := True;
     1251        if Trains[T].Direction = 1 then DirectionUp := True;
     1252        if Trains[T].Direction = -1 then DirectionDown := True;
    12551253      end;
    12561254      if StationIndex = 0 then
    1257         NextStationDown := TLineStation(LineStations[LineStations.Count - 2])
     1255        NextStationDown := LineStations[LineStations.Count - 2]
    12581256      else
    12591257      if StationIndex > 0 then
    1260         NextStationDown := TLineStation(LineStations[StationIndex - 1]);
     1258        NextStationDown := LineStations[StationIndex - 1];
    12611259
    12621260      if (StationIndex >= 0) and (StationIndex = LineStations.Count - 1) then
    1263         NextStationUp := TLineStation(LineStations[1])
     1261        NextStationUp := LineStations[1]
    12641262      else
    12651263      if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then
    1266         NextStationUp := TLineStation(LineStations[StationIndex + 1]);
     1264        NextStationUp := LineStations[StationIndex + 1];
    12671265    end else begin
    12681266      if StationIndex > 0 then begin
    12691267        DirectionDown := True;
    1270         NextStationDown := TLineStation(LineStations[StationIndex - 1])
     1268        NextStationDown := LineStations[StationIndex - 1]
    12711269      end else DirectionDown := False;
    12721270      if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then begin
    12731271        DirectionUp := True;
    1274         NextStationUp := TLineStation(LineStations[StationIndex + 1]);
     1272        NextStationUp := LineStations[StationIndex + 1];
    12751273      end else DirectionUp := False;
    12761274    end;
     
    12841282    end;
    12851283  end;
    1286   Result := (Check.MapStation.ShapeDistance[Shape] <> -1) and (Check.MapStation.ShapeDistance[Shape] <= Distance);
     1284  Result := (Check.MapStation.ShapeDistance[Shape] <> -1) and
     1285    (Check.MapStation.ShapeDistance[Shape] <= Distance);
    12871286end;
    12881287
     
    12991298  FreeAndNil(Lines);
    13001299  FreeAndNil(Passengers);
    1301   inherited Destroy;
     1300  inherited;
    13021301end;
    13031302
     
    13361335begin
    13371336  I := 0;
    1338   while (I < Stations.Count) and (Distance(TMapStation(Stations[I]).Position, Pos) > ClickDistance) do Inc(I);
    1339   if I < Stations.Count then Result := TMapStation(Stations[I])
     1337  while (I < Stations.Count) and (Distance(Stations[I].Position, Pos) > ClickDistance) do Inc(I);
     1338  if I < Stations.Count then Result := Stations[I]
    13401339    else Result := nil;
    13411340end;
     
    13551354  MinD := High(Integer);
    13561355  while (I < Lines.Count) do
    1357   with TMetroLine(Lines[I]) do begin
     1356  with Lines[I] do begin
    13581357    for T := 1 to Track.Points.Count - 1 do begin
    1359       D := PointToLineDistance(Pos, TTrackPoint(Track.Points[T - 1]).Position, TTrackPoint(Track.Points[T]).Position);
     1358      D := PointToLineDistance(Pos, Track.Points[T - 1].Position, Track.Points[T].Position);
    13601359      if (D < MinD) and (D < TrackClickDistance) then begin
    13611360        MinD := D;
    1362         Result.Points[0] := TTrackPoint(Track.Points[T - 1]);
    1363         Result.Points[1] := TTrackPoint(Track.Points[T]);
     1361        Result.Points[0] := Track.Points[T - 1];
     1362        Result.Points[1] := Track.Points[T];
    13641363      end;
    13651364    end;
     
    13771376  MinDistance := High(Integer);
    13781377  for I := 0 to Trains.Count - 1 do
    1379   with TMetroTrain(Trains[I]) do begin
     1378  with Trains[I] do begin
    13801379    D := Distance(GetPosition, Pos);
    13811380    if (D < (TrainSize div 2)) and (D < MinDistance) then begin
    1382       Result := TMetroTrain(Trains[I]);
     1381      Result := Trains[I];
    13831382      MinDistance := D;
    13841383    end;
     
    15611560      // Do for all lines connected to station
    15621561      for I := 0 to Lines.Count - 1 do
    1563       with TMetroLine(Lines[I]) do
     1562      with Lines[I] do
    15641563        for StationIndex := 0 to LineStations.Count - 1 do
    1565         if TLineStation(LineStations[StationIndex]).MapStation = Station then begin
     1564        if LineStations[StationIndex].MapStation = Station then begin
    15661565        if not IsCircular then begin
    15671566          // Update for all adjecent stations
    15681567          if StationIndex > 0 then
    1569             ComputeShapeDistanceStation(TLineStation(LineStations[StationIndex - 1]).MapStation,
     1568            ComputeShapeDistanceStation(LineStations[StationIndex - 1].MapStation,
    15701569            UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15711570          if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then
    1572             ComputeShapeDistanceStation(TLineStation(LineStations[StationIndex + 1]).MapStation,
     1571            ComputeShapeDistanceStation(LineStations[StationIndex + 1].MapStation,
    15731572            UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15741573        end else begin
     
    15781577          DirectionDown := False;
    15791578          for T := 0 to Trains.Count - 1 do begin
    1580             if TMetroTrain(Trains[T]).Direction = 1 then DirectionUp := True;
    1581             if TMetroTrain(Trains[T]).Direction = -1 then DirectionDown := True;
     1579            if Trains[T].Direction = 1 then DirectionUp := True;
     1580            if Trains[T].Direction = -1 then DirectionDown := True;
    15821581          end;
    15831582          // Update for all adjecent stations
    15841583          if DirectionUp then begin
    15851584            if StationIndex = 0 then
    1586               ComputeShapeDistanceStation(TLineStation(LineStations[LineStations.Count - 2]).MapStation,
     1585              ComputeShapeDistanceStation(LineStations[LineStations.Count - 2].MapStation,
    15871586              UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15881587            if StationIndex > 0 then
    1589               ComputeShapeDistanceStation(TLineStation(LineStations[StationIndex - 1]).MapStation,
     1588              ComputeShapeDistanceStation(LineStations[StationIndex - 1].MapStation,
    15901589              UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15911590          end;
    15921591          if DirectionDown then begin
    15931592            if (StationIndex >= 0) and (StationIndex = LineStations.Count - 1) then
    1594               ComputeShapeDistanceStation(TLineStation(LineStations[1]).MapStation,
     1593              ComputeShapeDistanceStation(LineStations[1].MapStation,
    15951594              UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15961595            if (StationIndex >= 0) and (StationIndex < LineStations.Count - 1) then
    1597               ComputeShapeDistanceStation(TLineStation(LineStations[StationIndex + 1]).MapStation,
     1596              ComputeShapeDistanceStation(LineStations[StationIndex + 1].MapStation,
    15981597              UpdatedShape, Station.ShapeDistance[UpdatedShape] + 1);
    15991598          end;
     
    16171616  // Move trains
    16181617  for I := 0 to Trains.Count - 1 do
    1619   with TMetroTrain(Trains[I]) do begin
     1618  with Trains[I] do begin
    16201619    if not Assigned(TargetStation) and Assigned(BaseTrackPoint) then begin
    16211620      if (Direction <> 1) and (Direction <> -1) then Direction := 1
     
    16381637            if Line.IsCircular then begin
    16391638              TargetStationIndex := Line.LineStations.Count - 2;
    1640               BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;
     1639              BaseTrackPoint := Line.LineStations.Last.TrackPoint;
    16411640              RelPos := 0;
    16421641            end else begin
     
    16481647            if Line.IsCircular then begin
    16491648              TargetStationIndex := 1;
    1650               BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;
     1649              BaseTrackPoint := Line.LineStations.First.TrackPoint;
    16511650              RelPos := 0;
    16521651            end else begin
     
    16551654            end;
    16561655          end;
    1657           TargetStation := TLineStation(Line.LineStations[TargetStationIndex]);
     1656          TargetStation := Line.LineStations[TargetStationIndex];
    16581657
    16591658          // Unload passengers in target station
    16601659          if Assigned(CurrentStation) then
    16611660          for P := Passengers.Count - 1 downto 0 do begin
    1662             if TMetroPassenger(Passengers[P]).Shape = CurrentStation.MapStation.Shape then begin
    1663               Passenger := TMetroPassenger(Passengers[P]);
     1661            if Passengers[P].Shape = CurrentStation.MapStation.Shape then begin
     1662              Passenger := Passengers[P];
    16641663              Passengers.Delete(P);
    16651664              Self.Passengers.Remove(Passenger);
     
    16701669          if Assigned(CurrentStation)  then
    16711670          for P := Passengers.Count - 1 downto 0 do begin
    1672             if not CurrentStation.MapStation.IsBestStationForShape(TMetroPassenger(Passengers[P]).Shape,
     1671            if not CurrentStation.MapStation.IsBestStationForShape(Passengers[P].Shape,
    16731672            TargetStation, CurrentStation) then begin
    1674               Passenger := TMetroPassenger(Passengers[P]);
     1673              Passenger := Passengers[P];
    16751674              Passengers.Delete(P);
    16761675              CurrentStation.MapStation.Passengers.Add(Passenger);
     
    16851684          for P := CurrentStation.MapStation.Passengers.Count - 1 downto 0 do begin
    16861685            if (Passengers.Count < TrainPassengerCount) then begin
    1687               Passenger := TMetroPassenger(CurrentStation.MapStation.Passengers[P]);
     1686              Passenger := CurrentStation.MapStation.Passengers[P];
    16881687              if CurrentStation.MapStation.IsBestStationForShape(Passenger.Shape,
    16891688            TargetStation, CurrentStation) then begin
     
    16911690                CurrentStation.MapStation.Passengers.Delete(P);
    16921691                Passengers.Add(Passenger);
    1693                 Passenger.Train := TMetroTrain(Trains[I]);
     1692                Passenger.Train := Trains[I];
    16941693              end;
    16951694            end else Break; // No more space
     
    17071706        if Assigned(BaseTrackPoint) then
    17081707        while (Direction = -1) and (RelPos < 0) do begin
    1709           if BaseTrackPoint <> TLineStation(Line.LineStations.First).TrackPoint then begin
     1708          if BaseTrackPoint <> Line.LineStations.First.TrackPoint then begin
    17101709            BaseTrackPoint := BaseTrackPoint.GetNeighDown;
    17111710            if Assigned(BaseTrackPoint) then
    17121711              RelPos := RelPos + BaseTrackPoint.GetDistance
    17131712            else begin
    1714               BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;
     1713              BaseTrackPoint := Line.LineStations.First.TrackPoint;
    17151714              RelPos := 0;
    17161715            end;
    17171716          end else
    17181717          if Line.IsCircular then begin
    1719             BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;
     1718            BaseTrackPoint := Line.LineStations.Last.TrackPoint;
    17201719            RelPos := RelPos + BaseTrackPoint.GetDistance;
    17211720          end else begin
     
    17261725        if Assigned(BaseTrackPoint) then
    17271726        while (Direction = 1) and (RelPos > BaseTrackPoint.GetDistance) do begin
    1728           if BaseTrackPoint <> TLineStation(Line.LineStations.Last).TrackPoint then begin
     1727          if BaseTrackPoint <> Line.LineStations.Last.TrackPoint then begin
    17291728            RelPos := RelPos - BaseTrackPoint.GetDistance;
    17301729            BaseTrackPoint := BaseTrackPoint.GetNeighUp;
    17311730            if not Assigned(BaseTrackPoint) then begin
    1732               BaseTrackPoint := TLineStation(Line.LineStations.Last).TrackPoint;
     1731              BaseTrackPoint := Line.LineStations.Last.TrackPoint;
    17331732              RelPos := 0;
    17341733            end;
     
    17361735          if Line.IsCircular then begin
    17371736            RelPos := RelPos - BaseTrackPoint.GetDistance;
    1738             BaseTrackPoint := TLineStation(Line.LineStations.First).TrackPoint;
     1737            BaseTrackPoint := Line.LineStations.First.TrackPoint;
    17391738          end else begin
    17401739            RelPos := BaseTrackPoint.GetDistance;
     
    17621761begin
    17631762  I := 0;
    1764   while (I < Lines.Count) and (TMetroLine(Lines[I]).Track.Points.Count > 0) do Inc(I);
    1765   if I < Lines.Count then Result := TMetroLine(Lines[I])
     1763  while (I < Lines.Count) and (Lines[I].Track.Points.Count > 0) do Inc(I);
     1764  if I < Lines.Count then Result := Lines[I]
    17661765    else Result := nil;
    17671766end;
     
    20252024        ((Line.LineStations.SearchMapStation(FocusedStation) = nil) or
    20262025        ((Line.LineStations.Count > 0) and
    2027         ((TLineStation(Line.LineStations.First).MapStation = FocusedStation) or
    2028         (TLineStation(Line.LineStations.Last).MapStation = FocusedStation)) and
     2026        ((Line.LineStations.First.MapStation = FocusedStation) or
     2027        (Line.LineStations.Last.MapStation = FocusedStation)) and
    20292028        ((TrackStationDown = nil) or (TrackStationUp = nil)) and
    20302029        (not Line.IsCircular))) then begin
     
    20582057      FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position));
    20592058      if Assigned(FocusedTrack.Points[0]) then begin
    2060         SelectedTrain.Line := TTrackPoint(FocusedTrack.Points[0]).Track.Line;
     2059        SelectedTrain.Line := FocusedTrack.Points[0].Track.Line;
    20612060        SelectedTrain.Line.Trains.Add(SelectedTrain);
    2062         SelectedTrain.BaseTrackPoint := TTrackPoint(FocusedTrack.Points[0]);
     2061        SelectedTrain.BaseTrackPoint := FocusedTrack.Points[0];
    20632062      end else
    20642063      if Assigned(FocusedTrack.Points[1]) then begin
    2065         SelectedTrain.Line := TTrackPoint(FocusedTrack.Points[1]).Track.Line;
     2064        SelectedTrain.Line := FocusedTrack.Points[1].Track.Line;
    20662065        SelectedTrain.Line.Trains.Add(SelectedTrain);
    2067         SelectedTrain.BaseTrackPoint := TTrackPoint(FocusedTrack.Points[1]);
     2066        SelectedTrain.BaseTrackPoint := FocusedTrack.Points[1];
    20682067      end;
    20692068      FocusedTrack.Free;
     
    20742073      if Distance(Point(View.DestRect.Right div 2 - Length(LineColors) div 2 * LineColorsDist + I * LineColorsDist,
    20752074        View.DestRect.Bottom - LineColorsDist), Position) < 20 then begin
    2076           SelectedLine := TMetroLine(Lines[I]);
     2075          SelectedLine := Lines[I];
    20772076          Exit;
    20782077        end;
     
    20802079    // Remove single line station on line
    20812080    if Assigned(TrackStationDown) and (TrackStationDown.Track.Line.LineStations.Count = 1) then begin
    2082       TrackStationDown.Track.Line.DisconnectStation(TLineStation(TrackStationDown.Track.Line.LineStations.First));
     2081      TrackStationDown.Track.Line.DisconnectStation(TrackStationDown.Track.Line.LineStations.First);
    20832082    end;
    20842083    if Assigned(TrackStationUp) and (TrackStationUp.Track.Line.LineStations.Count = 1) then begin
    2085       TrackStationUp.Track.Line.DisconnectStation(TLineStation(TrackStationUp.Track.Line.LineStations.First));
     2084      TrackStationUp.Track.Line.DisconnectStation(TrackStationUp.Track.Line.LineStations.First);
    20862085    end;
    20872086  end else
     
    21232122    Track := GetTrackOnPos(View.PointDestToSrc(Position));
    21242123    if Assigned(Track) and Assigned(Track.Points[0]) and Assigned(Track.Points[1]) then begin
    2125       SelectedLine := TTrackPoint(Track.Points[0]).Track.Line;
    2126 
    2127       TrackStationDown := TTrackPoint(Track.Points[0]);
     2124      SelectedLine := Track.Points[0].Track.Line;
     2125
     2126      TrackStationDown := Track.Points[0];
    21282127      NewIndex := TrackStationDown.Track.Points.IndexOf(TrackStationDown);
    21292128      while Assigned(TrackStationDown) and (not Assigned(TrackStationDown.LineStation)) do begin
    21302129        NewIndex := NewIndex - 1;
    2131         if NewIndex >= 0 then TrackStationDown := TTrackPoint(TrackStationDown.Track.Points[NewIndex])
     2130        if NewIndex >= 0 then TrackStationDown := TrackStationDown.Track.Points[NewIndex]
    21322131          else TrackStationDown := nil;
    21332132      end;
    2134       TrackStationUp := TTrackPoint(Track.Points[1]);
     2133      TrackStationUp := Track.Points[1];
    21352134      NewIndex := TrackStationUp.Track.Points.IndexOf(TrackStationDown);
    21362135      while Assigned(TrackStationUp) and (not Assigned(TrackStationUp.LineStation)) do begin
    21372136        NewIndex := NewIndex + 1;
    21382137        if NewIndex < TrackStationUp.Track.Points.Count then
    2139           TrackStationUp := TTrackPoint(TrackStationUp.Track.Points[NewIndex])
     2138          TrackStationUp := TrackStationUp.Track.Points[NewIndex]
    21402139          else TrackStationUp := nil;
    21412140      end;
     
    21522151      if Assigned(NewLine) then begin
    21532152        NewLine.ConnectStation(Station, nil, nil);
    2154         TrackStationDown := TTrackPoint(NewLine.Track.Points.Last);
     2153        TrackStationDown := NewLine.Track.Points.Last;
    21552154        TrackStationUp := nil;
    21562155        LastFocusedStation := Station;
     
    22392238  FreeAndNil(Stations);
    22402239  FreeAndNil(Lines);
    2241   inherited Destroy;
     2240  inherited;
    22422241end;
    22432242
     
    22932292{      if (S = TrackPoints.Count - 1) then begin
    22942293        Canvas.Pen.EndCap := pecSquare;
    2295         Angle := arctan2((TTrackPoint(TrackPoints[S]).Position.Y - TTrackPoint(TrackPoints[S - 1]).Position.Y),
    2296           (TTrackPoint(TrackPoints[S]).Position.X - TTrackPoint(TrackPoints[S - 1]).Position.X));
    2297         EndPoint := Point(Round(TTrackPoint(TrackPoints[S]).Position.X + EndStationLength * Cos(Angle)),
    2298           Round(TTrackPoint(TrackPoints[S]).Position.Y + EndStationLength * Sin(Angle)));
     2294        Angle := arctan2(((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
     2295          (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
     2296        EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
     2297          Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
    22992298        Canvas.LineTo(EndPoint);
    23002299        Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
     
    23082307    Canvas.Pen.Style := psSolid;
    23092308    Canvas.Pen.Width := MetroLineThickness div 2;
    2310     if Track.Points.Count > 0 then Canvas.MoveTo(TTrackPoint(Track.Points[0]).PositionDesigned);
     2309    if Track.Points.Count > 0 then Canvas.MoveTo(Track.Points[0].PositionDesigned);
    23112310    for S := 1 to Track.Points.Count - 1 do begin
    2312       Canvas.LineTo(TTrackPoint(Track.Points[S]).PositionDesigned);
     2311      Canvas.LineTo(Track.Points[S].PositionDesigned);
    23132312{      if (S = TrackPoints.Count - 1) then begin
    23142313        Canvas.Pen.EndCap := pecSquare;
    2315         Angle := arctan2((TTrackPoint(TrackPoints[S]).Position.Y - TTrackPoint(TrackPoints[S - 1]).Position.Y),
    2316           (TTrackPoint(TrackPoints[S]).Position.X - TTrackPoint(TrackPoints[S - 1]).Position.X));
    2317         EndPoint := Point(Round(TTrackPoint(TrackPoints[S]).Position.X + EndStationLength * Cos(Angle)),
    2318           Round(TTrackPoint(TrackPoints[S]).Position.Y + EndStationLength * Sin(Angle)));
     2314        Angle := arctan2((TrackPoints[S].Position.Y - TrackPoints[S - 1].Position.Y),
     2315          (TrackPoints[S].Position.X - TrackPoints[S - 1].Position.X));
     2316        EndPoint := Point(Round(TrackPoints[S].Position.X + EndStationLength * Cos(Angle)),
     2317          Round(TrackPoints[S].Position.Y + EndStationLength * Sin(Angle)));
    23192318        Canvas.LineTo(EndPoint);
    23202319        Canvas.MoveTo(Point(Round(EndPoint.X + Cos(Angle + Pi / 2) * EndStationLength / 3),
     
    23282327    if (TrackPoints.Count > 1) then begin
    23292328      Canvas.Pen.EndCap := pecSquare;
    2330       Angle := arctan2((TTrackPoint(TrackPoints[1]).Position.Y - TTrackPoint(TrackPoints[0]).Position.Y),
    2331         (TTrackPoint(TrackPoints[1]).Position.X - TTrackPoint(TrackPoints[0]).Position.X));
    2332       Canvas.MoveTo(TTrackPoint(TrackPoints[0]).Position);
    2333       EndPoint := Point(Round(TTrackPoint(TrackPoints[0]).Position.X - EndStationLength * Cos(Angle)),
    2334         Round(TTrackPoint(TrackPoints[0]).Position.Y - EndStationLength * Sin(Angle)));
     2329      Angle := arctan2((TrackPoints[1].Position.Y - TrackPoints[0].Position.Y),
     2330        (TrackPoints[1].Position.X - TrackPoints[0].Position.X));
     2331      Canvas.MoveTo(TrackPoints[0].Position);
     2332      EndPoint := Point(Round(TrackPoints[0].Position.X - EndStationLength * Cos(Angle)),
     2333        Round(TrackPoints[0].Position.Y - EndStationLength * Sin(Angle)));
    23352334      Canvas.LineTo(EndPoint);
    23362335      Canvas.MoveTo(Point(Round(EndPoint.X - Cos(Angle + Pi / 2) * EndStationLength / 3),
  • trunk/UTrack.pas

    r29 r59  
    66
    77uses
    8   Classes, SysUtils, Contnrs;
     8  Classes, SysUtils, fgl;
    99
    1010type
     
    2828  { TTrackPoints }
    2929
    30   TTrackPoints = class(TObjectList)
     30  TTrackPoints = class(TFPGObjectList<TTrackPoint>)
    3131  end;
    3232
     
    4242  { TTrackLinks }
    4343
    44   TTrackLinks = class(TObjectList)
     44  TTrackLinks = class(TFPGObjectList<TTrackLink>)
    4545    function SearchPoints(Point1, Point2: TTrackPoint): TTrackLink;
    4646  end;
     
    5858  end;
    5959
     60
    6061implementation
    6162
     
    6869  I := 0;
    6970  while (I < 0) and
    70   ((TTrackLink(Items[I]).Points.First <> Point1) or (TTrackLink(Items[I]).Points.Last <> Point2))
    71   and ((TTrackLink(Items[I]).Points.First <> Point2) or (TTrackLink(Items[I]).Points.Last <> Point1)) do
     71  ((Items[I].Points.First <> Point1) or (Items[I].Points.Last <> Point2))
     72  and ((Items[I].Points.First <> Point2) or (Items[I].Points.Last <> Point1)) do
    7273  Inc(I);
    73   if I < 0 then Result := TTrackLink(Items[I])
     74  if I < 0 then Result := Items[I]
    7475    else Result := nil;
    7576end;
     
    8687begin
    8788  Points.Free;
    88   inherited Destroy;
     89  inherited;
    8990end;
    9091
     
    146147  // Disconnect from all before destruction
    147148  for I := NeighPoints.Count - 1 downto 0 do
    148     TTrackPoint(NeighPoints[I]).Disconnect(Self);
     149    NeighPoints[I].Disconnect(Self);
    149150  if Assigned(Track) then Track.Points.Remove(Self);
    150151  NeighPoints.Free;
    151   inherited Destroy;
     152  inherited;
    152153end;
    153154
     
    162163begin
    163164  Points.Free;
    164   inherited Destroy;
     165  inherited;
    165166end;
    166167
Note: See TracChangeset for help on using the changeset viewer.