aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Movement/Spline/MoveSplineFlag.h
blob: 62b8bb1cab0b9f943bf1174fb48d0c444e207a4c (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TRINITYSERVER_MOVESPLINEFLAG_H
#define TRINITYSERVER_MOVESPLINEFLAG_H

#include "Define.h"
#include "EnumFlag.h"
#include <string>

namespace Movement
{
    // EnumUtils: DESCRIBE THIS
    enum class MoveSplineFlagEnum : uint32
    {
        None                = 0x00000000,
        Unknown_0x1         = 0x00000001,           // NOT VERIFIED
        Unknown_0x2         = 0x00000002,           // NOT VERIFIED
        Unknown_0x4         = 0x00000004,           // NOT VERIFIED
        JumpOrientationFixed= 0x00000008,           // Model orientation fixed (jump animation)
        FallingSlow         = 0x00000010,
        Done                = 0x00000020,
        Falling             = 0x00000040,           // Affects elevation computation, can't be combined with Parabolic flag
        No_Spline           = 0x00000080,
        Unknown_0x100       = 0x00000100,           // NOT VERIFIED
        Flying              = 0x00000200,           // Smooth movement(Catmullrom interpolation mode), flying animation
        OrientationFixed    = 0x00000400,           // Model orientation fixed (knockback animation)
        Catmullrom          = 0x00000800,           // Used Catmullrom interpolation mode
        Cyclic              = 0x00001000,           // Movement by cycled spline
        Enter_Cycle         = 0x00002000,           // Everytimes appears with cyclic flag in monster move packet, erases first spline vertex after first cycle done
        Turning             = 0x00004000,           // Turns in place
        TransportEnter      = 0x00008000,
        TransportExit       = 0x00010000,
        Unknown_0x20000     = 0x00020000,           // NOT VERIFIED
        Unknown_0x40000     = 0x00040000,           // NOT VERIFIED
        Backward            = 0x00080000,
        SmoothGroundPath    = 0x00100000,
        CanSwim             = 0x00200000,
        UncompressedPath    = 0x00400000,
        Unknown_0x800000    = 0x00800000,           // NOT VERIFIED
        FastSteering        = 0x01000000,           // Predicts spline only 500ms into the future for smoothing instead of 1s (making turns sharper) and turns off clientside obstacle detection
        Animation           = 0x02000000,           // Plays animation after some time passed
        Parabolic           = 0x04000000,           // Affects elevation computation, can't be combined with Falling flag
        FadeObject          = 0x08000000,
        Steering            = 0x10000000,
        UnlimitedSpeed      = 0x20000000,
        Unknown_0x40000000  = 0x40000000,           // NOT VERIFIED
        Unknown_0x80000000  = 0x80000000,           // NOT VERIFIED

        // Masks
        // flags that shouldn't be appended into SMSG_MONSTER_MOVE\SMSG_MONSTER_MOVE_TRANSPORT packet, should be more probably
        Mask_No_Monster_Move = Done, // SKIP
        // Unused, not suported flags
        Mask_Unused         = No_Spline | Unknown_0x100 | Unknown_0x20000 | Unknown_0x40000
                            | Unknown_0x800000 | FadeObject | UnlimitedSpeed | Unknown_0x40000000 | Unknown_0x80000000 // SKIP
    };

    DEFINE_ENUM_FLAG(MoveSplineFlagEnum);

    consteval MoveSplineFlagEnum GetDisallowedFlagsFor(MoveSplineFlagEnum flag)
    {
        switch (flag)
        {
            case MoveSplineFlagEnum::JumpOrientationFixed: return MoveSplineFlagEnum::OrientationFixed;
            case MoveSplineFlagEnum::Falling: return MoveSplineFlagEnum::Parabolic | MoveSplineFlagEnum::Animation | MoveSplineFlagEnum::Flying;
            case MoveSplineFlagEnum::Flying: return MoveSplineFlagEnum::FallingSlow | MoveSplineFlagEnum::Falling;
            case MoveSplineFlagEnum::OrientationFixed: return MoveSplineFlagEnum::JumpOrientationFixed;
            case MoveSplineFlagEnum::Catmullrom: return MoveSplineFlagEnum::SmoothGroundPath;
            case MoveSplineFlagEnum::TransportEnter: return MoveSplineFlagEnum::TransportExit;
            case MoveSplineFlagEnum::TransportExit: return MoveSplineFlagEnum::TransportEnter;
            case MoveSplineFlagEnum::SmoothGroundPath: return MoveSplineFlagEnum::Steering;
            case MoveSplineFlagEnum::Animation: return MoveSplineFlagEnum::Falling | MoveSplineFlagEnum::Parabolic | MoveSplineFlagEnum::FallingSlow | MoveSplineFlagEnum::FadeObject;
            case MoveSplineFlagEnum::Parabolic: return MoveSplineFlagEnum::Falling | MoveSplineFlagEnum::Animation | MoveSplineFlagEnum::FallingSlow | MoveSplineFlagEnum::FadeObject;
            case MoveSplineFlagEnum::FadeObject: return MoveSplineFlagEnum::Falling | MoveSplineFlagEnum::Parabolic | MoveSplineFlagEnum::FallingSlow | MoveSplineFlagEnum::Animation;
            case MoveSplineFlagEnum::Steering: return MoveSplineFlagEnum::SmoothGroundPath;
            default: break;
        }
        return MoveSplineFlagEnum::None;
    }

    union MoveSplineFlag
    {
        constexpr MoveSplineFlag() : Raw(MoveSplineFlagEnum::None) { }
        constexpr MoveSplineFlag(MoveSplineFlagEnum f) : Raw(f) { }

        // Constant interface

        constexpr bool isSmooth() const { return Raw.HasFlag(MoveSplineFlagEnum::Catmullrom); }
        constexpr bool isLinear() const { return !isSmooth(); }

        constexpr bool HasAllFlags(MoveSplineFlagEnum f) const { return Raw.HasAllFlags(f); }
        constexpr bool HasFlag(MoveSplineFlagEnum f) const { return Raw.HasFlag(f); }
        constexpr MoveSplineFlagEnum operator&(MoveSplineFlagEnum f) const { return (Raw & f); }
        constexpr MoveSplineFlagEnum operator|(MoveSplineFlagEnum f) const { return (Raw | f); }
        std::string ToString() const;

        // Not constant interface

        constexpr MoveSplineFlag& operator&=(MoveSplineFlagEnum f) { Raw &= f; return *this; }
        constexpr MoveSplineFlag& operator|=(MoveSplineFlagEnum f) { Raw |= f; return *this; }

        EnumFlag<MoveSplineFlagEnum> Raw;

        template <MoveSplineFlagEnum Flag>
        struct FlagAccessor
        {
            // force compile time evaluation - workaround for clang <= 14
            static constexpr MoveSplineFlagEnum DisallowedFlag = std::integral_constant<MoveSplineFlagEnum, GetDisallowedFlagsFor(Flag)>::value;

            constexpr operator bool() const { return (Raw & Flag) != MoveSplineFlagEnum::None; }
            constexpr FlagAccessor& operator=(bool val) { if (val) { Raw = Raw & ~DisallowedFlag | Flag; } else Raw &= ~Flag; return *this; }
            MoveSplineFlagEnum Raw;
        };

#define MAKE_FLAG_ACCESSOR_FIELD(flag) FlagAccessor<MoveSplineFlagEnum::flag> flag

        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x1);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x2);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x4);
        MAKE_FLAG_ACCESSOR_FIELD(JumpOrientationFixed);
        MAKE_FLAG_ACCESSOR_FIELD(FallingSlow);
        MAKE_FLAG_ACCESSOR_FIELD(Done);
        MAKE_FLAG_ACCESSOR_FIELD(Falling);
        MAKE_FLAG_ACCESSOR_FIELD(No_Spline);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x100);
        MAKE_FLAG_ACCESSOR_FIELD(Flying);
        MAKE_FLAG_ACCESSOR_FIELD(OrientationFixed);
        MAKE_FLAG_ACCESSOR_FIELD(Catmullrom);
        MAKE_FLAG_ACCESSOR_FIELD(Cyclic);
        MAKE_FLAG_ACCESSOR_FIELD(Enter_Cycle);
        MAKE_FLAG_ACCESSOR_FIELD(Turning);
        MAKE_FLAG_ACCESSOR_FIELD(TransportEnter);
        MAKE_FLAG_ACCESSOR_FIELD(TransportExit);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x20000);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x40000);
        MAKE_FLAG_ACCESSOR_FIELD(Backward);
        MAKE_FLAG_ACCESSOR_FIELD(SmoothGroundPath);
        MAKE_FLAG_ACCESSOR_FIELD(CanSwim);
        MAKE_FLAG_ACCESSOR_FIELD(UncompressedPath);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x800000);
        MAKE_FLAG_ACCESSOR_FIELD(FastSteering);
        MAKE_FLAG_ACCESSOR_FIELD(Animation);
        MAKE_FLAG_ACCESSOR_FIELD(Parabolic);
        MAKE_FLAG_ACCESSOR_FIELD(FadeObject);
        MAKE_FLAG_ACCESSOR_FIELD(Steering);
        MAKE_FLAG_ACCESSOR_FIELD(UnlimitedSpeed);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x40000000);
        MAKE_FLAG_ACCESSOR_FIELD(Unknown_0x80000000);

#undef MAKE_FLAG_ACCESSOR_FIELD
    };
}

#endif // TRINITYSERVER_MOVESPLINEFLAG_H