Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
devapromix committed Jul 9, 2022
1 parent aee516b commit 359096c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
16 changes: 9 additions & 7 deletions Sources/Game/TransportTycoon.Aircraft.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ TAircraftBase = record
);

type

{ TAircraft }

TAircraft = class(TVehicle)
private
FT: Integer;
Expand All @@ -58,7 +61,6 @@ TAircraft = class(TVehicle)
FMaxPassengers: Integer;
FMail: Integer;
FMaxMail: Integer;
FLastAirportId: Integer;
public
Order: array of TOrder;
constructor Create(const AName: string; const AX, AY, ID: Integer);
Expand All @@ -68,10 +70,9 @@ TAircraft = class(TVehicle)
property Mail: Integer read FMail write FMail;
property MaxMail: Integer read FMaxMail;
property State: string read FState;
property LastAirportId: Integer write FLastAirportId;
procedure Step; override;
procedure Load;
procedure UnLoad;
procedure Load; override;
procedure UnLoad; override;
procedure AddOrder(const AIndex: Integer); overload;
end;

Expand All @@ -86,6 +87,8 @@ implementation
TransportTycoon.Industries,
TransportTycoon.Cargo;

{ TAircraft }

function IsPath(X, Y: Integer): Boolean; stdcall;
begin
Result := True;
Expand All @@ -106,7 +109,6 @@ constructor TAircraft.Create(const AName: string; const AX, AY, ID: Integer);
FPassengers := 0;
FMaxMail := AircraftBase[ID].Mail;
FMail := 0;
LastAirportId := 0;
end;

procedure TAircraft.Load;
Expand Down Expand Up @@ -148,7 +150,7 @@ procedure TAircraft.Step;
if not Move(Order[OrderIndex].X, Order[OrderIndex].Y) then
begin
Inc(FT);
if Order[OrderIndex].ID <> FLastAirportId then
if Order[OrderIndex].ID <> LastStationId then
UnLoad;
FState := 'Service';
if FT > (15 - (TTownIndustry(Game.Map.Industry[Order[OrderIndex].ID])
Expand All @@ -168,8 +170,8 @@ procedure TAircraft.UnLoad;
var
M: Integer;
begin
SetLastStation;
FState := 'Unload';
LastAirportId := Order[OrderIndex].ID;
if Passengers > 0 then
begin
M := (Passengers * (Distance div 10)) * 7;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Game/TransportTycoon.Industries.pas
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class function TTownIndustry.GenName: string;
S[I] := TStringList.Create;
S[0].DelimitedText :=
'"Eding","Graning","Vorg","Tra","Nording","Agring","Gran","Funt","Grufing",'
+ '"Trening","Chend","Drinning","Long","Tor","Mar"';
+ '"Trening","Chend","Drinning","Long","Tor","Mar","Fin"';
S[1].DelimitedText :=
'"ville","burg","ley","ly","field","town","well","bell","bridge","ton",' +
'"stone","hattan"';
Expand Down
16 changes: 9 additions & 7 deletions Sources/Game/TransportTycoon.Ship.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ TShipBase = record
);

type

{ TShip }

TShip = class(TVehicle)
private
FT: Integer;
FState: string;
FLastAirportId: Integer;
FCargoAmount: Integer;
FCargoMaxAmount: Integer;
FCargo: TCargoSet;
Expand All @@ -42,14 +44,13 @@ TShip = class(TVehicle)
constructor Create(const AName: string; const AX, AY, ID: Integer);
function Move(const AX, AY: Integer): Boolean; override;
property State: string read FState;
property LastDockId: Integer write FLastAirportId;
property Cargo: TCargoSet read FCargo;
property CargoAmount: Integer read FCargoAmount;
property CargoMaxAmount: Integer read FCargoMaxAmount;
property CargoType: TCargo read FCargoType;
procedure Step; override;
procedure Load;
procedure UnLoad;
procedure Load; override;
procedure UnLoad; override;
procedure AddOrder(const AIndex: Integer); overload;
end;

Expand All @@ -63,6 +64,8 @@ implementation
TransportTycoon.PathFind,
TransportTycoon.Industries;

{ TShip }

function IsPath(X, Y: Integer): Boolean; stdcall;
begin
Result := Game.Map.Cell[X][Y] in [tlTownIndustry, tlWater, tlCanal] +
Expand All @@ -80,7 +83,6 @@ constructor TShip.Create(const AName: string; const AX, AY, ID: Integer);
inherited Create(AName, AX, AY);
FT := 0;
FState := 'Wait';
LastDockId := 0;
FCargoAmount := 0;
FCargoMaxAmount := ShipBase[ID].Amount;
FCargo := ShipBase[ID].Cargo;
Expand Down Expand Up @@ -129,7 +131,7 @@ procedure TShip.Step;
if not Move(Order[OrderIndex].X, Order[OrderIndex].Y) then
begin
Inc(FT);
if Order[OrderIndex].ID <> FLastAirportId then
if Order[OrderIndex].ID <> LastStationId then
UnLoad;
FState := 'Service';
if FT > (15 - (Game.Map.Industry[Order[OrderIndex].ID].Dock.Level * 2))
Expand All @@ -149,8 +151,8 @@ procedure TShip.UnLoad;
var
Money: Integer;
begin
SetLastStation;
FState := 'Unload';
LastDockId := Order[OrderIndex].ID;
if (CargoType in Game.Map.Industry[Order[OrderIndex].ID].Accepts) and
(CargoType <> cgNone) and (CargoAmount > 0) then
begin
Expand Down
11 changes: 11 additions & 0 deletions Sources/Game/TransportTycoon.Vehicle.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ interface
TVehicle = class(TMapObject)
private
FDistance: Integer;
FLastStationId: Integer;
FOrderIndex: Integer;
FVehicleID: Integer;
public
Order: array of TOrder;
constructor Create(const AName: string; const AX, AY: Integer);
procedure Draw;
procedure Step; virtual; abstract;
procedure Load; virtual; abstract;
procedure UnLoad; virtual; abstract;
function Move(const AX, AY: Integer): Boolean; virtual; abstract;
property VehicleID: Integer read FVehicleID write FVehicleID;
property OrderIndex: Integer read FOrderIndex write FOrderIndex;
property Distance: Integer read FDistance write FDistance;
property LastStationId: Integer read FLastStationId;
procedure AddOrder(const TownIndex: Integer; const AName: string;
const AX, AY: Integer); overload;
procedure DelOrder(const AIndex: Integer);
function IsOrder(const AIndex: Integer): Boolean;
procedure IncOrder;
procedure IncDistance;
procedure SetLastStation;
end;

implementation
Expand All @@ -48,6 +53,7 @@ constructor TVehicle.Create(const AName: string; const AX, AY: Integer);
inherited Create(AName, AX, AY);
FOrderIndex := 0;
FDistance := 0;
FLastStationId := 0;
end;

procedure TVehicle.Draw;
Expand Down Expand Up @@ -108,4 +114,9 @@ procedure TVehicle.IncDistance;
Inc(FDistance);
end;

procedure TVehicle.SetLastStation;
begin
FLastStationId := Order[FOrderIndex].ID;
end;

end.

0 comments on commit 359096c

Please sign in to comment.