Changeset 131


Ignore:
Timestamp:
May 1, 2023, 4:54:56 PM (19 months ago)
Author:
chronos
Message:
  • Fixed: More game properties correctly saved and loaded.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UEngine.pas

    r130 r131  
    112112
    113113  TMetroCarriage = class(TItem)
     114    Engine: TEngine;
    114115    Train: TMetroTrain;
    115116    Passengers: TMetroPassengers;
     
    126127
    127128  TMetroCarriages = class(TItems<TMetroCarriage>)
     129    Engine: TEngine;
     130    function CreateItem: TMetroCarriage; override;
    128131    function GetUnused: TMetroCarriage;
    129132    function GetUnusedCount: Integer;
     
    598601  Node2 := Node.FindNode(DOMString(TMetroPassengers.GetClassSysName));
    599602  if Assigned(Node2) then
    600     Passengers.LoadFromXmlNodeRef(Node2, Train.Engine.Passengers);
     603    Passengers.LoadFromXmlNodeRef(Node2, Engine.Passengers);
    601604end;
    602605
     
    613616
    614617{ TMetroCarriages }
     618
     619function TMetroCarriages.CreateItem: TMetroCarriage;
     620begin
     621  Result := inherited;
     622  Result.Engine := Engine;
     623end;
    615624
    616625function TMetroCarriages.GetUnused: TMetroCarriage;
     
    10591068var
    10601069  Node2: TDOMNode;
     1070  I: Integer;
    10611071begin
    10621072  inherited;
     
    10761086  if Assigned(Node2) then
    10771087    Carriages.LoadFromXmlNodeRef(Node2, Engine.Carriages);
     1088  for I := 0 to Carriages.Count - 1 do
     1089    Carriages[I].Train := Self;
    10781090end;
    10791091
     
    24602472    if Save then Action := MenuItemGameSlotSave
    24612473      else Action := MenuItemGameSlotLoad;
    2462     for I := 0 to GameSlotCount - 1 do begin
     2474    for I := 1 to GameSlotCount do begin
    24632475      FileName := GetGameSlotFileName(Integer(I));
    24642476      ControlName := SSlot + ' ' + IntToStr(I);
     
    33893401  if Assigned(SelectedTrain) then begin
    33903402    FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Pos), Intersect);
    3391     if Assigned(FocusedTrack.Points[0]) then begin
    3392       TrackPosition.BaseTrackPoint := FocusedTrack.Points[0];
    3393       TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position,
    3394         Intersect);
    3395       Vector := TrackPosition.GetVector;
    3396       Angle := Vector.GetAngle;
    3397 
    3398       if Assigned(LastGrabbedTrain) then begin
    3399         if TrackPosition.GetTrackPosition >
    3400           LastGrabbedTrainTrackPosition.GetTrackPosition then
    3401             GrabbedTrainDirection := 1
    3402         else
    3403         if TrackPosition.GetTrackPosition <
    3404           LastGrabbedTrainTrackPosition.GetTrackPosition then
    3405           GrabbedTrainDirection := -1;
    3406       end else GrabbedTrainDirection := 1;
    3407 
    3408       LastGrabbedTrain := SelectedTrain;
    3409       LastGrabbedTrainTrackPosition := TrackPosition;
    3410     end;
    3411     FocusedTrack.Free;
     3403    if Assigned(FocusedTrack) then begin
     3404      if Assigned(FocusedTrack.Points[0]) then begin
     3405        TrackPosition.BaseTrackPoint := FocusedTrack.Points[0];
     3406        TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position,
     3407          Intersect);
     3408        Vector := TrackPosition.GetVector;
     3409        Angle := Vector.GetAngle;
     3410
     3411        if Assigned(LastGrabbedTrain) then begin
     3412          if TrackPosition.GetTrackPosition >
     3413            LastGrabbedTrainTrackPosition.GetTrackPosition then
     3414              GrabbedTrainDirection := 1
     3415          else
     3416          if TrackPosition.GetTrackPosition <
     3417            LastGrabbedTrainTrackPosition.GetTrackPosition then
     3418            GrabbedTrainDirection := -1;
     3419        end else GrabbedTrainDirection := 1;
     3420
     3421        LastGrabbedTrain := SelectedTrain;
     3422        LastGrabbedTrainTrackPosition := TrackPosition;
     3423      end;
     3424      FreeAndNil(FocusedTrack);
     3425    end;
    34123426
    34133427    if GrabbedTrainDirection = -1 then Angle := Angle + Pi;
     
    36533667        end;
    36543668        FocusedTrack := GetTrackOnPos(View.PointDestToSrc(Position), Intersect);
    3655         if Assigned(FocusedTrack.Points[0]) then begin
    3656           SelectedTrain.Line := TMetroLine(FocusedTrack.Points[0].Track.Owner);
    3657           SelectedTrain.Line.Trains.Add(SelectedTrain);
    3658           SelectedTrain.TrackPosition.BaseTrackPoint := FocusedTrack.Points[0];
    3659           SelectedTrain.TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position,
    3660             Intersect);
    3661           SelectedTrain.Direction := GrabbedTrainDirection;
    3662           SelectedTrain.FindTargetStation;
    3663           SelectedTrain.LastTrainMoveTime := Time;
     3669        if Assigned(FocusedTrack) then begin
     3670          if Assigned(FocusedTrack.Points[0]) then begin
     3671            SelectedTrain.Line := TMetroLine(FocusedTrack.Points[0].Track.Owner);
     3672            SelectedTrain.Line.Trains.Add(SelectedTrain);
     3673            SelectedTrain.TrackPosition.BaseTrackPoint := FocusedTrack.Points[0];
     3674            SelectedTrain.TrackPosition.RelPos := Distance(FocusedTrack.Points[0].Position,
     3675              Intersect);
     3676            SelectedTrain.Direction := GrabbedTrainDirection;
     3677            SelectedTrain.FindTargetStation;
     3678            SelectedTrain.LastTrainMoveTime := Time;
     3679          end;
     3680          FreeAndNil(FocusedTrack);
    36643681        end;
    3665         FocusedTrack.Free;
    36663682
    36673683        LastGrabbedTrain := nil;
     
    40134029  NewNode: TDOMNode;
    40144030  Node2: TDOMNode;
     4031  Improvement: TMetroImprovement;
    40154032begin
    40164033  Clear;
     
    40214038  FLastTime := FTime;
    40224039  City := Cities.SearchBySysName(ReadString(Node, 'CityName', ''));
     4040  AvailableTerminals := ReadInteger(Node, 'AvailableTerminals', AvailableTerminals);
    40234041
    40244042  NewNode := Node.FindNode(DOMString(TView.GetClassSysName));
     
    40374055  end;
    40384056
     4057  AvailableImprovements := [];
     4058  NewNode := Node.FindNode('Improvements');
     4059  if Assigned(NewNode) then begin
     4060    Node2 := NewNode.FirstChild;
     4061    while Assigned(Node2) and (Node2.NodeName = 'Improvement') do begin
     4062      Improvement := TMetroImprovement(StrToInt(string(Node2.TextContent)));
     4063      AvailableImprovements := AvailableImprovements + [Improvement];
     4064      Node2 := Node2.NextSibling;
     4065    end;
     4066  end;
     4067
    40394068  NewNode := Node.FindNode(DOMString(TMetroPassengers.GetClassSysName));
    40404069  if Assigned(NewNode) then
     
    40494078    Lines.LoadFromXmlNode(NewNode);
    40504079
     4080  NewNode := Node.FindNode(DOMString(TMetroCarriages.GetClassSysName));
     4081  if Assigned(NewNode) then
     4082    Carriages.LoadFromXmlNode(NewNode);
     4083
    40514084  NewNode := Node.FindNode(DOMString(TMetroTrains.GetClassSysName));
    40524085  if Assigned(NewNode) then
    40534086    Trains.LoadFromXmlNode(NewNode);
    4054 
    4055   NewNode := Node.FindNode(DOMString(TMetroCarriages.GetClassSysName));
    4056   if Assigned(NewNode) then
    4057     Carriages.LoadFromXmlNode(NewNode);
    40584087end;
    40594088
     
    40624091  I: Integer;
    40634092  NewNode: TDOMNode;
     4093  Improvement: TMetroImprovement;
    40644094begin
    40654095  Lines.RebuildItemsId;
    40664096  Stations.RebuildItemsId;
    40674097  Passengers.RebuildItemsId;
     4098  Trains.RebuildItemsId;
     4099  Carriages.RebuildItemsId;
    40684100
    40694101  WriteInteger(Node, 'ServedPassengerCount', ServedPassengerCount);
     
    40724104  WriteDateTime(Node, 'Time', FTime);
    40734105  if Assigned(City) then WriteString(Node, 'CityName', City.SysName);
     4106  WriteInteger(Node, 'AvailableTerminals', AvailableTerminals);
    40744107
    40754108  NewNode := Node.OwnerDocument.CreateElement(DOMString(TView.GetClassSysName));
     
    40834116  end;
    40844117
     4118  NewNode := Node.OwnerDocument.CreateElement('Improvements');
     4119  Node.AppendChild(NewNode);
     4120  for Improvement := Low(TMetroImprovement) to High(TMetroImprovement) do begin
     4121    if Improvement in AvailableImprovements then
     4122      WriteInteger(NewNode, 'Improvement', Integer(Improvement));
     4123  end;
     4124
    40854125  NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroPassengers.GetClassSysName));
    40864126  Node.AppendChild(NewNode);
     
    40954135  Lines.SaveToXmlNode(NewNode);
    40964136
     4137  NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroCarriages.GetClassSysName));
     4138  Node.AppendChild(NewNode);
     4139  Carriages.SaveToXmlNode(NewNode);
     4140
    40974141  NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroTrains.GetClassSysName));
    40984142  Node.AppendChild(NewNode);
    40994143  Trains.SaveToXmlNode(NewNode);
    4100 
    4101   NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroCarriages.GetClassSysName));
    4102   Node.AppendChild(NewNode);
    4103   Carriages.SaveToXmlNode(NewNode);
    41044144end;
    41054145
     
    41724212  Trains.Engine := Self;
    41734213  Carriages := TMetroCarriages.Create;
     4214  Carriages.Engine := Self;
    41744215  ImageTunnel := TImage.Create;
    41754216  ImageLine := TImage.Create;
  • trunk/UItems.pas

    r128 r131  
    118118begin
    119119  Node2 := Node.FirstChild;
    120   while Assigned(Node2) and (Node2.NodeName = DOMString(TItem.GetClassSysName)) do begin
     120  while Assigned(Node2) and (Node2.NodeName = DOMString(T.GetClassSysName)) do begin
    121121    RefId := StrToInt(string(Node.TextContent));
    122122    NewItem := Target.FindById(RefId);
Note: See TracChangeset for help on using the changeset viewer.