summaryrefslogtreecommitdiffstats
path: root/src/vehicles/Train.h
blob: e20a08fd56f329a42c87d50ac86fc39295d49de0 (plain) (blame)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once

#include "Vehicle.h"
#include "Door.h"

enum
{
	TRACK_ELTRAIN,
	TRACK_SUBWAY
};

enum
{
	TRAIN_DOOR_CLOSED,
	TRAIN_DOOR_OPENING,
	TRAIN_DOOR_OPEN,
	TRAIN_DOOR_CLOSING
};

enum eTrainNodes
{
	TRAIN_DOOR_LHS = 1,
	TRAIN_DOOR_RHS,
	NUM_TRAIN_NODES
};

enum eTrainPositions
{
	TRAIN_POS_LIGHT_FRONT,
	TRAIN_POS_LIGHT_REAR,
	TRAIN_POS_LEFT_ENTRY,
	TRAIN_POS_MID_ENTRY,
	TRAIN_POS_RIGHT_ENTRY
};

struct CTrainNode
{
	CVector p;	// position
	float t;	// xy-distance from start on track
};

struct CTrainInterpolationLine
{
	uint8 type;
	float time;	// when does this keyframe start
	// initial values at start of frame
	float position;
	float speed;
	float acceleration;
};

class CTrain : public CVehicle
{
public:
	// 0x288
	float m_fWagonPosition;
	int16 m_nWagonId;
	int16 m_isFarAway;	// don't update so often?
	int16 m_nCurTrackNode;
	int16 m_nWagonGroup;
	float m_fSpeed;
	bool m_bProcessDoor;
	bool m_bTrainStopping;
	bool m_bIsFirstWagon;
	bool m_bIsLastWagon;
	uint8 m_nTrackId;	// or m_bUsesSubwayTracks?
	uint32 m_nDoorTimer;
	int16 m_nDoorState;
	CTrainDoor Doors[2];
	RwFrame *m_aTrainNodes[NUM_TRAIN_NODES];

	// unused
	static CVector aStationCoors[3];
	static CVector aStationCoors_S[4];

	CTrain(int32 id, uint8 CreatedBy);

	// from CEntity
	void SetModelIndex(uint32 id);
	void ProcessControl(void);
	void PreRender(void);
	void Render(void);

	void AddPassenger(CPed *ped);
	void OpenTrainDoor(float ratio);
	void TrainHitStuff(CPtrList &list);

	static void InitTrains(void);
	static void Shutdown(void);
	static void ReadAndInterpretTrackFile(char *filename, CTrainNode **nodes, int16 *numNodes, int32 numStations, float *stationDists,
		float *totalLength, float *totalDuration, CTrainInterpolationLine *interpLines, bool rightRail);
	static void UpdateTrains(void);
};