- Timestamp:
- Oct 4, 2022, 11:25:28 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Install/snap/local/build.sh
r85 r105 4 4 5 5 pushd ../../.. 6 snapcraft --debug --use-lxd $@6 snapcraft --debug --use-lxd -v $@ 7 7 popd 8 8 -
trunk/Install/snap/snapcraft.yaml
r85 r105 36 36 install -s -m 755 BigMetro $SNAPCRAFT_PART_INSTALL/usr/bin 37 37 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/BigMetro/languages 38 install -m 755 Languages/ BigMetro.po$SNAPCRAFT_PART_INSTALL/usr/share/BigMetro/languages39 install -m 755 Languages/ BigMetro.cs.po $SNAPCRAFT_PART_INSTALL/usr/share/BigMetro/languages38 install -m 755 Languages/*.pot $SNAPCRAFT_PART_INSTALL/usr/share/BigMetro/languages 39 install -m 755 Languages/*.po $SNAPCRAFT_PART_INSTALL/usr/share/BigMetro/languages 40 40 install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications 41 41 install -m 755 Install/snap/local/BigMetro.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications -
trunk/Packages/Common/UGeometric.pas
r93 r105 22 22 function AddPoint(const P1, P2: TPoint): TPoint; 23 23 function SubPoint(const P1, P2: TPoint): TPoint; 24 function PointToLineDistance(const P, V, W: TPoint ): Integer;24 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 25 25 function ComparePoint(P1, P2: TPoint): Boolean; 26 26 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; … … 59 59 end; 60 60 61 function PointToLineDistance(const P, V, W: TPoint ): Integer;61 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 62 62 var 63 63 l2, t: Double; … … 77 77 if T < 0 then begin 78 78 Result := Distance(P, V); // Beyond the 'v' end of the segment 79 exit; 79 Intersect := V; 80 Exit; 80 81 end 81 82 else if T > 1 then begin 82 83 Result := Distance(P, W); // Beyond the 'w' end of the segment 84 Intersect := W; 83 85 Exit; 84 86 end; … … 86 88 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 87 89 Result := Distance(P, TT); 90 Intersect := TT; 88 91 end; 89 92 -
trunk/UEngine.pas
r103 r105 126 126 TargetStation: TLineStation; 127 127 Carriages: TMetroCarriages; 128 procedure FindTargetStation; 128 129 function GetTargetStationDistance: Integer; 129 130 function GetPosition: TPoint; … … 193 194 function GetExistStationShapes: TStationShapeSet; 194 195 function GetStationOnPos(Pos: TPoint): TMapStation; 195 function GetTrackOnPos(Pos: TPoint ): TTrackLink;196 function GetTrackOnPos(Pos: TPoint; out Intersect: TPoint): TTrackLink; 196 197 function GetTrainOnPos(Pos: TPoint): TMetroTrain; 197 198 function GetCarriageOnPos(Pos: TPoint): TMetroCarriage; … … 217 218 procedure SetDarkMode(AValue: Boolean); 218 219 procedure SetState(AValue: TGameState); 219 procedure TrainMovement; 220 procedure TrainsMovement; 221 procedure TrainMovement(Train: TMetroTrain); 220 222 function GetUnusedLine: TMetroLine; 221 223 procedure ShiftTrackPoints; … … 781 783 end; 782 784 785 procedure TMetroTrain.FindTargetStation; 786 var 787 TP: TTrackPoint; 788 begin 789 if Direction > 0 then begin 790 TP := TrackPosition.BaseTrackPoint.GetUp; 791 if Assigned(TP) then begin 792 TargetStation := TLineStation(TP.OwnerPoint); 793 end else begin 794 TP := TrackPosition.BaseTrackPoint.GetDown; 795 if Assigned(TP) then 796 TargetStation := TLineStation(TP.OwnerPoint); 797 end; 798 end else 799 if Direction < 0 then begin 800 if Assigned(TrackPosition.BaseTrackPoint.OwnerPoint) then 801 TargetStation := TLineStation(TrackPosition.BaseTrackPoint.OwnerPoint) 802 else begin 803 TP := TrackPosition.BaseTrackPoint.GetUp; 804 if Assigned(TP) then 805 TargetStation := TLineStation(TP.OwnerPoint); 806 end; 807 end; 808 LastPosDelta := Abs(GetTargetStationDistance); 809 end; 810 783 811 function TMetroTrain.GetTargetStationDistance: Integer; 784 812 var … … 789 817 Result := 0; 790 818 if Assigned(TrackPosition.BaseTrackPoint) and Assigned(TargetStation) then begin 791 Current := Line.Track.Points.IndexOf(TrackPosition.BaseTrackPoint);792 Target := Line.Track.Points.IndexOf(TargetStation.TrackPoint);793 if Current < Target then begin794 for I := Current to Target - 1 do795 Result := Result + Line.Track.Points[I].GetDistance;796 Result := Result - Trunc(TrackPosition.RelPos);797 end else798 if Current > Target then begin799 for I := Current - 1 downto Target do800 Result := Result + Line.Track.Points[I].GetDistance;801 Result := Result + Trunc(TrackPosition.RelPos);802 end else Result := Trunc(TrackPosition.RelPos);819 Current := Line.Track.Points.IndexOf(TrackPosition.BaseTrackPoint); 820 Target := Line.Track.Points.IndexOf(TargetStation.TrackPoint); 821 if Current < Target then begin 822 for I := Current to Target - 1 do 823 Result := Result + Line.Track.Points[I].GetDistance; 824 Result := Result - Trunc(TrackPosition.RelPos); 825 end else 826 if Current > Target then begin 827 for I := Current - 1 downto Target do 828 Result := Result + Line.Track.Points[I].GetDistance; 829 Result := Result + Trunc(TrackPosition.RelPos); 830 end else Result := Trunc(TrackPosition.RelPos); 803 831 end; 804 832 end; … … 1116 1144 end; 1117 1145 1118 function TEngine.GetTrackOnPos(Pos: TPoint ): TTrackLink;1146 function TEngine.GetTrackOnPos(Pos: TPoint; out Intersect: TPoint): TTrackLink; 1119 1147 var 1120 1148 I: Integer; … … 1122 1150 D: Integer; 1123 1151 MinD: Integer; 1152 TempIntersect: TPoint; 1124 1153 begin 1125 1154 Result := TTrackLink.Create; … … 1130 1159 MinD := High(Integer); 1131 1160 while (I < Lines.Count) do 1132 with Lines[I]do begin1161 with TMetroLine(Lines[I]) do begin 1133 1162 for T := 1 to Track.Points.Count - 1 do begin 1134 D := PointToLineDistance(Pos, Track.Points[T - 1].Position, Track.Points[T].Position); 1163 D := PointToLineDistance(Pos, Track.Points[T - 1].Position, Track.Points[T].Position, 1164 TempIntersect); 1135 1165 if (D < MinD) and (D < TrackClickDistance) then begin 1136 1166 MinD := D; 1137 1167 Result.Points[0] := Track.Points[T - 1]; 1138 1168 Result.Points[1] := Track.Points[T]; 1169 Intersect := TempIntersect; 1139 1170 end; 1140 1171 end; … … 1429 1460 end; 1430 1461 1431 procedure TEngine.Train Movement;1462 procedure TEngine.TrainsMovement; 1432 1463 var 1433 1464 I: Integer; 1465 begin 1466 for I := 0 to Trains.Count - 1 do 1467 TrainMovement(Trains[I]); 1468 end; 1469 1470 procedure TEngine.TrainMovement(Train: TMetroTrain); 1471 var 1434 1472 J: Integer; 1435 1473 CurrentStation: TLineStation; … … 1439 1477 TargetStationIndex: Integer; 1440 1478 PosChange: Double; 1441 TP: TTrackPoint;1442 1479 Done: Boolean; 1443 1480 begin 1444 // Move trains 1445 for I := 0 to Trains.Count - 1 do 1446 with TMetroTrain(Trains[I]) do begin 1447 if not Assigned(TargetStation) and Assigned(TrackPosition.BaseTrackPoint) then begin 1448 if (Direction <> 1) and (Direction <> -1) then Direction := 1 1449 else Direction := -Direction; 1450 TP := TrackPosition.BaseTrackPoint.GetUp; 1451 if Assigned(TP) then TargetStation := TLineStation(TP.OwnerPoint) 1452 else begin 1453 TP := TrackPosition.BaseTrackPoint.GetDown; 1454 if Assigned(TP) then TargetStation := TLineStation(TP.OwnerPoint); 1455 end; 1456 end; 1481 with Train do begin 1457 1482 if Assigned(Line) then begin 1458 1483 if InStation then begin … … 1567 1592 end else begin 1568 1593 PosChange := Direction + Trunc(Direction * TrainSpeed * (Time - LastTrainMoveTime)); 1569 TrackPosition.RelPos := TrackPosition.RelPos + PosChange;1570 1594 LastTrainMoveTime := Time; 1571 1595 Redraw; 1572 if Assigned(TrackPosition.BaseTrackPoint) then 1573 while (Direction = -1) and (TrackPosition.RelPos < 0) do begin 1574 if TrackPosition.BaseTrackPoint <> Line.LineStations.First.TrackPoint then begin 1575 TrackPosition.BaseTrackPoint := TrackPosition.BaseTrackPoint.GetNeighDown; 1576 if Assigned(TrackPosition.BaseTrackPoint) then 1577 TrackPosition.RelPos := TrackPosition.RelPos + TrackPosition.BaseTrackPoint.GetDistance 1578 else begin 1579 TrackPosition.BaseTrackPoint := Line.LineStations.First.TrackPoint; 1580 TrackPosition.RelPos := 0; 1581 end; 1582 end else 1583 if Line.IsCircular then begin 1584 TrackPosition.BaseTrackPoint := Line.LineStations.Last.TrackPoint; 1585 TrackPosition.RelPos := TrackPosition.RelPos + TrackPosition.BaseTrackPoint.GetDistance; 1586 end else begin 1596 TrackPosition.Move(PosChange); 1597 1598 if Assigned(TargetStation) then begin 1599 PosDelta := Abs(GetTargetStationDistance); 1600 if PosDelta >= LastPosDelta then begin 1601 // We are getting far from station, stop at station 1602 TrackPosition.BaseTrackPoint := TargetStation.TrackPoint; 1587 1603 TrackPosition.RelPos := 0; 1588 Break; 1604 InStation := True; 1605 StationStopTime := Time; 1606 Redraw; 1589 1607 end; 1590 end;1591 if Assigned(TrackPosition.BaseTrackPoint) then1592 while (Direction = 1) and (TrackPosition.RelPos > TrackPosition.BaseTrackPoint.GetDistance) do begin1593 if TrackPosition.BaseTrackPoint <> Line.LineStations.Last.TrackPoint then begin1594 TrackPosition.RelPos := TrackPosition.RelPos - TrackPosition.BaseTrackPoint.GetDistance;1595 TrackPosition.BaseTrackPoint := TrackPosition.BaseTrackPoint.GetNeighUp;1596 if not Assigned(TrackPosition.BaseTrackPoint) then begin1597 TrackPosition.BaseTrackPoint := Line.LineStations.Last.TrackPoint;1598 TrackPosition.RelPos := 0;1599 end;1600 end else1601 if Line.IsCircular then begin1602 TrackPosition.RelPos := TrackPosition.RelPos - TrackPosition.BaseTrackPoint.GetDistance;1603 TrackPosition.BaseTrackPoint := Line.LineStations.First.TrackPoint;1604 end else begin1605 TrackPosition.RelPos := TrackPosition.BaseTrackPoint.GetDistance;1606 Break;1607 end;1608 end;1609 PosDelta := Abs(GetTargetStationDistance);1610 if PosDelta >= LastPosDelta then begin1611 // We are getting far from station, stop at station1612 TrackPosition.BaseTrackPoint := TargetStation.TrackPoint;1613 TrackPosition.RelPos := 0;1614 InStation := True;1615 StationStopTime := Time;1616 Redraw;1617 1608 end; 1618 1609 LastPosDelta := PosDelta; … … 2253 2244 end; 2254 2245 end; 2246 2247 { // Target station links 2248 if Assigned(TargetStation) then begin 2249 Canvas.Pen.Width := 1; 2250 Canvas.Pen.Style := psSolid; 2251 Canvas.Pen.Color := Colors.MenuItemText; 2252 Canvas.MoveTo(Pos); 2253 Canvas.LineTo(TargetStation.TrackPoint.Position); 2254 end; 2255 } 2255 2256 end; 2256 2257 end; … … 2894 2895 end; 2895 2896 2896 Train Movement;2897 TrainsMovement; 2897 2898 2898 2899 // Game over … … 2982 2983 FocusedTrain: TMetroTrain; 2983 2984 FocusedStation: TMapStation; 2985 Intersect: TPoint; 2984 2986 begin 2985 2987 if Button = mbLeft then begin … … 3020 3022 end; 3021 3023 end; 3022 FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position) );3024 FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position), Intersect); 3023 3025 if Assigned(FocusedTrack.Points[0]) then begin 3024 3026 SelectedTrain.Line := TMetroLine(FocusedTrack.Points[0].Track.Owner); 3025 3027 SelectedTrain.Line.Trains.Add(SelectedTrain); 3026 3028 SelectedTrain.TrackPosition.BaseTrackPoint := FocusedTrack.Points[0]; 3027 end else 3028 if Assigned(FocusedTrack.Points[1]) then begin 3029 SelectedTrain.Line := TMetroLine(FocusedTrack.Points[1].Track.Owner); 3030 SelectedTrain.Line.Trains.Add(SelectedTrain); 3031 SelectedTrain.TrackPosition.BaseTrackPoint := FocusedTrack.Points[1]; 3029 SelectedTrain.TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position, 3030 Intersect); 3031 if (SelectedTrain.Direction <> 1) and (SelectedTrain.Direction <> -1) then 3032 SelectedTrain.Direction := 1 3033 else SelectedTrain.Direction := -SelectedTrain.Direction; 3034 SelectedTrain.FindTargetStation; 3035 SelectedTrain.LastTrainMoveTime := Time; 3032 3036 end; 3033 3037 FocusedTrack.Free; … … 3093 3097 Track: TTrackLink; 3094 3098 NewIndex: Integer; 3099 Intersection: TPoint; 3095 3100 begin 3096 3101 if (Button = mbLeft) then begin … … 3149 3154 3150 3155 // Line selection 3151 Track := GetTrackOnPos(View.PointDestToSrc(Position) );3156 Track := GetTrackOnPos(View.PointDestToSrc(Position), Intersection); 3152 3157 if Assigned(Track) and Assigned(Track.Points[0]) and Assigned(Track.Points[1]) then begin 3153 3158 SelectedLine := TMetroLine(Track.Points[0].Track.Owner); … … 3179 3184 const 3180 3185 KeyEsc = 27; 3186 {$IFDEF DEBUG} 3181 3187 KeyF2 = 113; 3182 3188 KeyF3 = 114; … … 3186 3192 KeyF7 = 118; 3187 3193 KeyF8 = 119; 3194 {$ENDIF} 3188 3195 KeyT = 84; 3189 3196 KeyC = 67;
Note:
See TracChangeset
for help on using the changeset viewer.