summaryrefslogtreecommitdiff
path: root/game/vehicles/railloco.h
blob: 1bc0a517ae90195d73b990f0ae156d97b626d4d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "game/network/link.h"
#include "game/vehicles/vehicle.h"
#include "game/worldobject.h"
#include "gfx/models/mesh.h"
#include <array>
#include <location.hpp>
#include <memory>
#include <string>
#include <utility>
#include <vector>

class Shader;
class Texture;
class ObjParser;

class RailVehicleClass {
public:
	explicit RailVehicleClass(const std::string & name);

	void render(const Shader &, const Location &, const std::array<Location, 2> &) const;

	std::array<MeshPtr, 2> bogies;
	MeshPtr bodyMesh;
	std::shared_ptr<Texture> texture;
	float wheelBase;
	float length;

private:
	RailVehicleClass(std::unique_ptr<ObjParser> obj, std::shared_ptr<Texture>);
	static float bogieOffset(ObjParser & o);
	static float objectLength(ObjParser & o);
};
using RailVehicleClassPtr = std::shared_ptr<RailVehicleClass>;

class RailVehicle : public Vehicle {
public:
	explicit RailVehicle(RailVehicleClassPtr rvc, const LinkPtr & link, float linkDist = 0) :
		Vehicle {link, linkDist}, rvClass {std::move(rvc)}
	{
	}
	void render(const Shader & shader) const override;

	RailVehicleClassPtr rvClass;
	std::array<Location, 2> bogies;

	friend class RailLoco;
};

class RailWagon : public RailVehicle {
public:
	using RailVehicle::RailVehicle;
	void tick(TickDuration elapsed) override;
};
using RailWagonPtr = std::weak_ptr<RailWagon>;

class RailLoco : public RailVehicle {
public:
	using RailVehicle::RailVehicle;
	void tick(TickDuration elapsed) override;

	std::vector<RailWagonPtr> wagons;

private:
	void move(TickDuration dur);
	[[nodiscard]] Location getBogiePosition(float linkDist, float dist) const;
	void updateRailVehiclePosition(RailVehicle *, float trailBy) const;
	void updateWagons() const;
};

class Brush47 : public RailLoco {
public:
	explicit Brush47(const LinkPtr & p);
};

class Brush47Wagon : public RailWagon {
public:
	explicit Brush47Wagon(const LinkPtr & p);
};