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
|
#pragma once
#include <libultraship.h>
#include <vector>
#include "engine/registry/RegisterContent.h"
#include "engine/SpawnParams.h"
#include "engine/CoreMath.h"
#include "engine/World.h"
#include "engine/Actor.h"
extern "C" {
#include "main.h"
#include "vehicles.h"
}
/**
* Note that you can only remove the tender if there are no carriages
* @arg waypoint initial waypoint to spawn at.
*/
class ATrain : public AActor {
public:
enum SpawnMode : uint16_t {
POINT, // Spawn train at a specific path point
AUTO, // Automatically distribute trains based on a specific path point
};
enum TenderStatus {
NO_TENDER,
HAS_TENDER,
};
TrainCarStuff Locomotive;
TrainCarStuff Tender;
std::vector<TrainCarStuff> PassengerCars;
size_t PassengerCarsCount = 0;
ATrain::SpawnMode SpawnType = ATrain::SpawnMode::AUTO;
uint32_t PathIndex = 0;
uint32_t PathPoint = 0;
TenderStatus HasTender = TenderStatus::NO_TENDER;
s32 SomeFlags;
f32 SomeMultiplier;
size_t Index; // Spawns the train in halves of the train path
int32_t SmokeParticles[128];
int32_t NextParticlePtr = 0;
int16_t AnotherSmokeTimer = 0;
int16_t SmokeTimer = 0;
explicit ATrain(const SpawnParams& params);
~ATrain() {
_count--;
}
static size_t GetCount() {
return _count;
}
// This is simply a helper function to keep Spawning code clean
static inline ATrain* Spawn(ATrain::TenderStatus tender, size_t numCarriages, f32 speed, uint32_t pathIndex, uint32_t pathPoint, ATrain::SpawnMode spawnMode) {
SpawnParams params = {
.Name = "mk:train",
.Type = static_cast<int16_t>(spawnMode),
.Count = numCarriages,
.PathIndex = pathIndex,
.PathPoint = pathPoint,
.Bool = tender,
.Speed = speed, // 120.0f is about the maximum usable value
};
return static_cast<ATrain*>(AddActorToWorld<ATrain>(params));
}
virtual void SetSpawnParams(SpawnParams& params);
virtual void Tick() override;
virtual void Draw(Camera* camera) override;
virtual void VehicleCollision(s32 playerId, Player* player) override;
virtual bool IsMod() override;
s32 AddSmoke(s32 trainIndex, Vec3f pos, f32 velocity);
void SyncComponents(TrainCarStuff* trainCar, s16 orientationY);
virtual void DrawEditorProperties() override;
private:
static size_t _count; // Total number of spawned trains
// pathIndex, array of spawn points
static std::map<uint32_t, std::vector<uint32_t>> TrainCounts;
};
|