summaryrefslogtreecommitdiff
path: root/src/engine/vehicles/Truck.h
blob: 0529a87e87a29a80200f11d881a3c295facef2f0 (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
#pragma once

#include <libultraship.h>
#include "engine/Actor.h"
#include <vector>
#include "engine/registry/RegisterContent.h"
#include "engine/SpawnParams.h"

extern "C" {
#include "sounds.h"
}

class ATruck : public AActor {
  public:
    enum SpawnMode : uint16_t {
        POINT, // Spawn car at a specific path point
        AUTO,  // Automatically distribute cars based on a specific path point
    };

    const char* Type;
    size_t Index;
    f32 Speed;
    s16 ActorIndex;
    Vec3f Position;
    Vec3f Velocity;
    Vec3s Rotation;
    f32 SomeMultiplierTheSequel;
    s8 SomeFlagsTheSequel = 0;
    u16 WaypointIndex;
    s8 SomeFlags = 0;
    s16 SomeType;

    f32 SomeArg3 = 55.0f;
    f32 SomeArg4 = 12.5f;
    u32 SoundBits = SOUND_ARG_LOAD(0x51, 0x01, 0x80, 0x03);

    float SpeedB = 0.0f;
    ATruck::SpawnMode SpawnType = ATruck::SpawnMode::AUTO;
    uint32_t PathIndex = 0;
    uint32_t PathPoint = 0;

    // This is simply a helper function to keep Spawning code clean
    static ATruck* Spawn(f32 speedA, f32 speedB, uint32_t pathIndex, uint32_t pathPoint, ATruck::SpawnMode spawnMode) {
        SpawnParams params = {
            .Name = "mk:truck",
            .Type = static_cast<uint16_t>(spawnMode),
            .PathIndex = pathIndex,
            .PathPoint = pathPoint,
            .Speed = speedA,
            .SpeedB = speedB
        };
        return dynamic_cast<ATruck*>(AddActorToWorld<ATruck>(params));
    }

    explicit ATruck(const SpawnParams& params);

    ~ATruck() {
        _count--;
    }

    static size_t GetCount() {
        return _count;
    }

    virtual void SetSpawnParams(SpawnParams& params) override;
    virtual void Tick() override;
    virtual void Draw(Camera* camera) override;
    virtual void VehicleCollision(s32 playerId, Player* player) override;
    virtual bool IsMod() override;
    virtual void DrawEditorProperties() override;

  private:
    static size_t _count;
    static std::map<uint32_t, std::vector<uint32_t>> TruckCounts;
};