- Timestamp:
- May 1, 2023, 4:54:56 PM (19 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UEngine.pas
r130 r131 112 112 113 113 TMetroCarriage = class(TItem) 114 Engine: TEngine; 114 115 Train: TMetroTrain; 115 116 Passengers: TMetroPassengers; … … 126 127 127 128 TMetroCarriages = class(TItems<TMetroCarriage>) 129 Engine: TEngine; 130 function CreateItem: TMetroCarriage; override; 128 131 function GetUnused: TMetroCarriage; 129 132 function GetUnusedCount: Integer; … … 598 601 Node2 := Node.FindNode(DOMString(TMetroPassengers.GetClassSysName)); 599 602 if Assigned(Node2) then 600 Passengers.LoadFromXmlNodeRef(Node2, Train.Engine.Passengers);603 Passengers.LoadFromXmlNodeRef(Node2, Engine.Passengers); 601 604 end; 602 605 … … 613 616 614 617 { TMetroCarriages } 618 619 function TMetroCarriages.CreateItem: TMetroCarriage; 620 begin 621 Result := inherited; 622 Result.Engine := Engine; 623 end; 615 624 616 625 function TMetroCarriages.GetUnused: TMetroCarriage; … … 1059 1068 var 1060 1069 Node2: TDOMNode; 1070 I: Integer; 1061 1071 begin 1062 1072 inherited; … … 1076 1086 if Assigned(Node2) then 1077 1087 Carriages.LoadFromXmlNodeRef(Node2, Engine.Carriages); 1088 for I := 0 to Carriages.Count - 1 do 1089 Carriages[I].Train := Self; 1078 1090 end; 1079 1091 … … 2460 2472 if Save then Action := MenuItemGameSlotSave 2461 2473 else Action := MenuItemGameSlotLoad; 2462 for I := 0 to GameSlotCount - 1do begin2474 for I := 1 to GameSlotCount do begin 2463 2475 FileName := GetGameSlotFileName(Integer(I)); 2464 2476 ControlName := SSlot + ' ' + IntToStr(I); … … 3389 3401 if Assigned(SelectedTrain) then begin 3390 3402 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; 3412 3426 3413 3427 if GrabbedTrainDirection = -1 then Angle := Angle + Pi; … … 3653 3667 end; 3654 3668 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); 3664 3681 end; 3665 FocusedTrack.Free;3666 3682 3667 3683 LastGrabbedTrain := nil; … … 4013 4029 NewNode: TDOMNode; 4014 4030 Node2: TDOMNode; 4031 Improvement: TMetroImprovement; 4015 4032 begin 4016 4033 Clear; … … 4021 4038 FLastTime := FTime; 4022 4039 City := Cities.SearchBySysName(ReadString(Node, 'CityName', '')); 4040 AvailableTerminals := ReadInteger(Node, 'AvailableTerminals', AvailableTerminals); 4023 4041 4024 4042 NewNode := Node.FindNode(DOMString(TView.GetClassSysName)); … … 4037 4055 end; 4038 4056 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 4039 4068 NewNode := Node.FindNode(DOMString(TMetroPassengers.GetClassSysName)); 4040 4069 if Assigned(NewNode) then … … 4049 4078 Lines.LoadFromXmlNode(NewNode); 4050 4079 4080 NewNode := Node.FindNode(DOMString(TMetroCarriages.GetClassSysName)); 4081 if Assigned(NewNode) then 4082 Carriages.LoadFromXmlNode(NewNode); 4083 4051 4084 NewNode := Node.FindNode(DOMString(TMetroTrains.GetClassSysName)); 4052 4085 if Assigned(NewNode) then 4053 4086 Trains.LoadFromXmlNode(NewNode); 4054 4055 NewNode := Node.FindNode(DOMString(TMetroCarriages.GetClassSysName));4056 if Assigned(NewNode) then4057 Carriages.LoadFromXmlNode(NewNode);4058 4087 end; 4059 4088 … … 4062 4091 I: Integer; 4063 4092 NewNode: TDOMNode; 4093 Improvement: TMetroImprovement; 4064 4094 begin 4065 4095 Lines.RebuildItemsId; 4066 4096 Stations.RebuildItemsId; 4067 4097 Passengers.RebuildItemsId; 4098 Trains.RebuildItemsId; 4099 Carriages.RebuildItemsId; 4068 4100 4069 4101 WriteInteger(Node, 'ServedPassengerCount', ServedPassengerCount); … … 4072 4104 WriteDateTime(Node, 'Time', FTime); 4073 4105 if Assigned(City) then WriteString(Node, 'CityName', City.SysName); 4106 WriteInteger(Node, 'AvailableTerminals', AvailableTerminals); 4074 4107 4075 4108 NewNode := Node.OwnerDocument.CreateElement(DOMString(TView.GetClassSysName)); … … 4083 4116 end; 4084 4117 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 4085 4125 NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroPassengers.GetClassSysName)); 4086 4126 Node.AppendChild(NewNode); … … 4095 4135 Lines.SaveToXmlNode(NewNode); 4096 4136 4137 NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroCarriages.GetClassSysName)); 4138 Node.AppendChild(NewNode); 4139 Carriages.SaveToXmlNode(NewNode); 4140 4097 4141 NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroTrains.GetClassSysName)); 4098 4142 Node.AppendChild(NewNode); 4099 4143 Trains.SaveToXmlNode(NewNode); 4100 4101 NewNode := Node.OwnerDocument.CreateElement(DOMString(TMetroCarriages.GetClassSysName));4102 Node.AppendChild(NewNode);4103 Carriages.SaveToXmlNode(NewNode);4104 4144 end; 4105 4145 … … 4172 4212 Trains.Engine := Self; 4173 4213 Carriages := TMetroCarriages.Create; 4214 Carriages.Engine := Self; 4174 4215 ImageTunnel := TImage.Create; 4175 4216 ImageLine := TImage.Create; -
trunk/UItems.pas
r128 r131 118 118 begin 119 119 Node2 := Node.FirstChild; 120 while Assigned(Node2) and (Node2.NodeName = DOMString(T Item.GetClassSysName)) do begin120 while Assigned(Node2) and (Node2.NodeName = DOMString(T.GetClassSysName)) do begin 121 121 RefId := StrToInt(string(Node.TextContent)); 122 122 NewItem := Target.FindById(RefId);
Note:
See TracChangeset
for help on using the changeset viewer.