Changeset 101


Ignore:
Timestamp:
Sep 28, 2022, 9:38:10 PM (2 years ago)
Author:
chronos
Message:
  • Added: Terminals as selectable user improvement on every week.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r100 r101  
    3333    ShapeDistance: array[TStationShape] of Integer;
    3434    OverloadDuration: TDateTime;
     35    IsTerminal: Boolean;
     36    function GetMaxPassengers: Integer;
    3537    function IsBestStationForShape(Shape: TStationShape; Check, Current: TLineStation): Boolean;
    3638    constructor Create;
     
    185187    IconSize: Integer;
    186188    LineColors: array of TColor;
     189    CarriageCountVisible: Boolean;
     190    TerminalCountVisible: Boolean;
    187191    function GetServedDaysCount: Integer;
    188192    procedure ResizeView;
     
    207211    procedure DrawStations(Canvas: TCanvas);
    208212    procedure DrawGameControls(Canvas: TCanvas; CanvasSize: TPoint);
     213    procedure DrawGrabbed(Canvas: TCanvas; CanvasSize: TPoint);
    209214    procedure ComputeShapeDistance;
    210215    procedure ComputeShapeDistanceStation(Station: TMapStation;
     
    239244    procedure EvaluateImprovement(Improvement: TMetroImprovement);
    240245  public
     246    AvailableTerminals: Integer;
    241247    Week: Integer;
    242248    Colors: TColors;
     
    254260    SelectedTrain: TMetroTrain;
    255261    SelectedCarriage: TMetroCarriage;
     262    SelectedTerminal: Boolean;
    256263    TrackStationDown: TTrackPoint;
    257264    TrackStationUp: TTrackPoint;
     
    314321  StationMaxDistance = 300;
    315322  MaxWaitingPassengers = 10;
     323  MaxWaitingPassengersTerminal = 16;
    316324  MaxPassengersOveloadTime = 2;
    317325  MetroLineThickness = 13;
     
    968976begin
    969977  Lines.Sort(TComparer<TMetroLine>.Construct(MapStationCompareLine));
     978end;
     979
     980function TMapStation.GetMaxPassengers: Integer;
     981begin
     982  if IsTerminal then Result := MaxWaitingPassengersTerminal
     983    else Result := MaxWaitingPassengers;
    970984end;
    971985
     
    19972011    miCarriage: Carriages.AddNew;
    19982012    //miTunnel: Tunnels.AddNew;
    1999     //miTerminal: Terminals.AddNew;
     2013    miTerminal: Inc(AvailableTerminals);
    20002014  end;
    20012015end;
     
    25552569  PassengerPos: TPoint;
    25562570  Direction: Integer;
     2571  UsedStationSize: Integer;
    25572572begin
    25582573  Canvas.Pen.Width := 5;
     
    25602575  with MapStation do begin
    25612576    Canvas.Pen.Style := psSolid;
     2577    if IsTerminal then UsedStationSize := Round(StationSize * 1.5)
     2578      else UsedStationSize := StationSize;
     2579
    25622580    if Assigned(SelectedLine) and (Lines.IndexOf(SelectedLine) <> -1) then begin
    25632581      Canvas.Brush.Style := bsClear;
    25642582      Canvas.Pen.Color := SelectedLine.Color;
    2565       DrawShape(Canvas, Position, Shape, StationSize + Canvas.Pen.Width + 4, 0);
     2583      DrawShape(Canvas, Position, Shape, UsedStationSize + Canvas.Pen.Width + 4, 0);
    25662584    end;
    25672585
     
    25692587    Canvas.Brush.Style := bsSolid;
    25702588    Canvas.Pen.Color := Colors.Text;
    2571     DrawShape(Canvas, Position, Shape, StationSize, 0);
     2589    DrawShape(Canvas, Position, Shape, UsedStationSize, 0);
    25722590
    25732591    // Draw passengers
     
    26582676
    26592677  // Draw unused carriages
    2660   Text := IntToStr(Carriages.GetUnusedCount);
    2661   ImageCarriage.Bounds := Bounds(X - IconSize, Y - IconSize div 2,
    2662     IconSize, IconSize);
    2663   ImageCarriage.Canvas := Canvas;
    2664   ImageCarriage.Paint;
    2665   X := X - IconSize - SeparatorSize div 3;
    2666 
    2667   Canvas.Brush.Style := bsClear;
    2668   Canvas.Font.Size := 14;
    2669   Canvas.Font.Color := Colors.Text;
    2670   Canvas.TextOut(X - Canvas.TextWidth(Text),
    2671     Y - Canvas.TextHeight(Text) div 2, Text);
     2678  if Carriages.GetUnusedCount > 0 then CarriageCountVisible := True;
     2679  if CarriageCountVisible then begin
     2680    Text := IntToStr(Carriages.GetUnusedCount);
     2681    ImageCarriage.Bounds := Bounds(X - IconSize, Y - IconSize div 2,
     2682      IconSize, IconSize);
     2683    ImageCarriage.Canvas := Canvas;
     2684    ImageCarriage.Paint;
     2685    X := X - IconSize - SeparatorSize div 3;
     2686
     2687    Canvas.Brush.Style := bsClear;
     2688    Canvas.Font.Size := 14;
     2689    Canvas.Font.Color := Colors.Text;
     2690    Canvas.TextOut(X - Canvas.TextWidth(Text),
     2691      Y - Canvas.TextHeight(Text) div 2, Text);
     2692    X := X - Canvas.TextWidth(Text) - SeparatorSize;
     2693  end;
     2694
     2695  // Draw unused terminals
     2696  if AvailableTerminals > 0 then TerminalCountVisible := True;
     2697  if TerminalCountVisible then begin
     2698    Text := IntToStr(AvailableTerminals);
     2699    ImageTerminal.Bounds := Bounds(X - IconSize, Y - IconSize div 2,
     2700      IconSize, IconSize);
     2701    ImageTerminal.Canvas := Canvas;
     2702    ImageTerminal.Paint;
     2703    X := X - IconSize - SeparatorSize div 3;
     2704
     2705    Canvas.Brush.Style := bsClear;
     2706    Canvas.Font.Size := 14;
     2707    Canvas.Font.Color := Colors.Text;
     2708    Canvas.TextOut(X - Canvas.TextWidth(Text),
     2709      Y - Canvas.TextHeight(Text) div 2, Text);
     2710  end;
    26722711
    26732712  // Passenger count
     
    27202759      Y - Round(1.5 * IconSize) - Canvas.TextHeight(Text) div 2, Text);
    27212760  end;
    2722 
     2761end;
     2762
     2763procedure TEngine.DrawGrabbed(Canvas: TCanvas; CanvasSize: TPoint);
     2764var
     2765  Pos: TPoint;
     2766  Angle: Double;
     2767begin
    27232768  // Show train grabbed by mouse
    27242769  if Assigned(SelectedTrain) then begin
     
    27512796      RotatePoint(Pos, Point(Pos.X - TrainSize div 2, Pos.Y + TrainSize div 3), Angle)
    27522797    ]);
     2798  end;
     2799
     2800  // Show grabbed terminal by mouse
     2801  if SelectedTerminal then begin
     2802    Canvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color;
     2803    Canvas.Brush.Style := bsSolid;
     2804    Canvas.Pen.Style := psClear;
     2805    Pos := LastMousePos;
     2806    Angle := 0;
     2807
     2808    Canvas.Ellipse(Pos.X - TrainSize div 2, Pos.Y - TrainSize div 2,
     2809      Pos.X + TrainSize div 2, Pos.Y + TrainSize div 2);
    27532810  end;
    27542811end;
     
    28072864    for MapStation in Stations do
    28082865    with MapStation do begin
    2809       if Passengers.Count > MaxWaitingPassengers then begin
     2866      if Passengers.Count > GetMaxPassengers then begin
    28102867        OverloadDuration := OverloadDuration + (FTime - FLastTime);
    28112868        if OverloadDuration > MaxPassengersOveloadTime then
     
    28132870        if OverloadDuration < MaxPassengersOveloadTime then Redraw;
    28142871      end;
    2815       if Passengers.Count <= MaxWaitingPassengers then begin
     2872      if Passengers.Count <= GetMaxPassengers then begin
    28162873        if OverloadDuration > 0 then Redraw;
    28172874        OverloadDuration := OverloadDuration - (FTime - FLastTime);
     
    28552912  end;
    28562913
    2857   if Assigned(SelectedTrain) or Assigned(SelectedCarriage) then Redraw;
     2914  if Assigned(SelectedTrain) or Assigned(SelectedCarriage) or
     2915    SelectedTerminal then Redraw;
    28582916
    28592917  LastMousePos := Position;
     
    29082966  FocusedTrack: TTrackLink;
    29092967  FocusedTrain: TMetroTrain;
     2968  FocusedStation: TMapStation;
    29102969begin
    29112970  if Button = mbLeft then begin
     
    29733032      end;
    29743033
     3034      if SelectedTerminal then begin
     3035        FocusedStation := GetStationOnPos(View.PointDestToSrc(Position));
     3036        if Assigned(FocusedStation) and not FocusedStation.IsTerminal then begin
     3037          FocusedStation.IsTerminal := True;
     3038          Dec(AvailableTerminals);
     3039          Redraw;
     3040        end;
     3041        SelectedTerminal := False;
     3042      end;
     3043
    29753044      // Line color selection
    29763045      for I := 0 to Lines.Count - 1 do
     
    30363105
    30373106      // Select unused carriage
    3038       if (Distance(Position, ImageCarriage.Bounds.CenterPoint) < 30) and
     3107      if CarriageCountVisible and (Distance(Position, ImageCarriage.Bounds.CenterPoint) < 30) and
    30393108      (Carriages.GetUnusedCount > 0) then begin
    30403109        SelectedCarriage := Carriages.GetUnused;
     3110        Exit;
     3111      end;
     3112
     3113      // Select unused carriage
     3114      if TerminalCountVisible and (Distance(Position, ImageTerminal.Bounds.CenterPoint) < 30) and
     3115      (AvailableTerminals > 0) then begin
     3116        SelectedTerminal := True;
    30413117        Exit;
    30423118      end;
     
    30943170  KeyF6 = 117;
    30953171  KeyF7 = 118;
     3172  KeyF8 = 119;
    30963173  KeyT = 84;
    30973174  KeyC = 67;
     
    31533230      State := gsSuccess;
    31543231      Redraw;
     3232    end else
     3233    if Key = KeyF8 then begin
     3234      Inc(AvailableTerminals);
     3235      Redraw;
    31553236    end;
    31563237  end;
     
    31663247procedure TEngine.Clear;
    31673248begin
     3249  CarriageCountVisible := False;
     3250  TerminalCountVisible := False;
     3251  AvailableTerminals := 0;
    31683252  ServedPassengerCount := 0;
    31693253  Week := 1;
     
    31883272    InitialLineCount := City.InitialLineCount;
    31893273  end else begin
    3190     LineColors := [clBlue, clRed, clDarkYellow, clGreen,
    3191        clPurple, clGray, clOrange, clBrown, clCyan];
     3274    LineColors := [clBlue, clRed, clDarkYellow, clGreen, clPurple, clGray,
     3275      clOrange, clBrown, clCyan];
    31923276    InitialLineCount := 3;
    31933277  end;
    3194   AvailableImprovements := [miCarriage, miLine];
     3278  AvailableImprovements := [miCarriage, miLine, miTerminal];
    31953279  ShapeCount := 3;
    31963280
     
    33803464  if State in [gsRunning, gsPaused] then begin
    33813465    DrawGameControls(Canvas, CanvasSize);
     3466    DrawGrabbed(Canvas, CanvasSize);
    33823467  end;
    33833468
Note: See TracChangeset for help on using the changeset viewer.