Fix compilation with gmqcc.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / deathtypes.qh
1 // ================================
2 //  Deathtypes, reworked by Samual
3 // ================================
4
5 #define DEATHTYPES \
6         DEATHTYPE(DEATH_AUTOTEAMCHANGE,         DEATH_SELF_AUTOTEAMCHANGE,          NO_MSG,                        DEATH_SPECIAL_START) \
7         DEATHTYPE(DEATH_CAMP,                   DEATH_SELF_CAMP,                    NO_MSG,                        NORMAL_POS) \
8         DEATHTYPE(DEATH_CHEAT,                  DEATH_SELF_CHEAT,                   DEATH_MURDER_CHEAT,            NORMAL_POS) \
9         DEATHTYPE(DEATH_CUSTOM,                 DEATH_SELF_CUSTOM,                  NO_MSG,                        NORMAL_POS) \
10         DEATHTYPE(DEATH_DROWN,                  DEATH_SELF_DROWN,                   DEATH_MURDER_DROWN,            NORMAL_POS) \
11         DEATHTYPE(DEATH_FALL,                   DEATH_SELF_FALL,                    DEATH_MURDER_FALL,             NORMAL_POS) \
12         DEATHTYPE(DEATH_FIRE,                   DEATH_SELF_FIRE,                    DEATH_MURDER_FIRE,             NORMAL_POS) \
13         DEATHTYPE(DEATH_GENERIC,                DEATH_SELF_GENERIC,                 NO_MSG,                        NORMAL_POS) \
14         DEATHTYPE(DEATH_HURTTRIGGER,            DEATH_SELF_VOID,                    DEATH_MURDER_VOID,             NORMAL_POS) \
15         DEATHTYPE(DEATH_KILL,                   DEATH_SELF_SUICIDE,                 NO_MSG,                        NORMAL_POS) \
16         DEATHTYPE(DEATH_LAVA,                   DEATH_SELF_LAVA,                    DEATH_MURDER_LAVA,             NORMAL_POS) \
17         DEATHTYPE(DEATH_MIRRORDAMAGE,           DEATH_SELF_BETRAYAL,                NO_MSG,                        NORMAL_POS) \
18         DEATHTYPE(DEATH_NADE,                                   DEATH_SELF_NADE,                                        DEATH_MURDER_NADE,                         NORMAL_POS) \
19         DEATHTYPE(DEATH_NOAMMO,                 DEATH_SELF_NOAMMO,                  NO_MSG,                        NORMAL_POS) \
20         DEATHTYPE(DEATH_ROT,                    DEATH_SELF_ROT,                     NO_MSG,                        NORMAL_POS) \
21         DEATHTYPE(DEATH_SHOOTING_STAR,          DEATH_SELF_SHOOTING_STAR,           DEATH_MURDER_SHOOTING_STAR,    NORMAL_POS) \
22         DEATHTYPE(DEATH_SLIME,                  DEATH_SELF_SLIME,                   DEATH_MURDER_SLIME,            NORMAL_POS) \
23         DEATHTYPE(DEATH_SWAMP,                  DEATH_SELF_SWAMP,                   DEATH_MURDER_SWAMP,            NORMAL_POS) \
24         DEATHTYPE(DEATH_TEAMCHANGE,             DEATH_SELF_TEAMCHANGE,              NO_MSG,                        NORMAL_POS) \
25         DEATHTYPE(DEATH_TELEFRAG,               NO_MSG,                             DEATH_MURDER_TELEFRAG,         NORMAL_POS) \
26         DEATHTYPE(DEATH_TOUCHEXPLODE,           DEATH_SELF_TOUCHEXPLODE,            DEATH_MURDER_TOUCHEXPLODE,     NORMAL_POS) \
27         DEATHTYPE(DEATH_TURRET,                 DEATH_SELF_TURRET,                  NO_MSG,                        DEATH_TURRET_FIRST) \
28         DEATHTYPE(DEATH_TURRET_EWHEEL,          DEATH_SELF_TURRET_EWHEEL,           NO_MSG,                        NORMAL_POS) \
29         DEATHTYPE(DEATH_TURRET_FLAC,            DEATH_SELF_TURRET_FLAC,             NO_MSG,                        NORMAL_POS) \
30         DEATHTYPE(DEATH_TURRET_HELLION,         DEATH_SELF_TURRET_HELLION,          NO_MSG,                        NORMAL_POS) \
31         DEATHTYPE(DEATH_TURRET_HK,              DEATH_SELF_TURRET_HK,               NO_MSG,                        NORMAL_POS) \
32         DEATHTYPE(DEATH_TURRET_MACHINEGUN,      DEATH_SELF_TURRET_MACHINEGUN,       NO_MSG,                        NORMAL_POS) \
33         DEATHTYPE(DEATH_TURRET_MLRS,            DEATH_SELF_TURRET_MLRS,             NO_MSG,                        NORMAL_POS) \
34         DEATHTYPE(DEATH_TURRET_PHASER,          DEATH_SELF_TURRET_PHASER,           NO_MSG,                        NORMAL_POS) \
35         DEATHTYPE(DEATH_TURRET_PLASMA,          DEATH_SELF_TURRET_PLASMA,           NO_MSG,                        NORMAL_POS) \
36         DEATHTYPE(DEATH_TURRET_TESLA,           DEATH_SELF_TURRET_TESLA,            NO_MSG,                        NORMAL_POS) \
37         DEATHTYPE(DEATH_TURRET_WALK_GUN,        DEATH_SELF_TURRET_WALK_GUN,         NO_MSG,                        NORMAL_POS) \
38         DEATHTYPE(DEATH_TURRET_WALK_MEELE,      DEATH_SELF_TURRET_WALK_MEELE,       NO_MSG,                        NORMAL_POS) \
39         DEATHTYPE(DEATH_TURRET_WALK_ROCKET,     DEATH_SELF_TURRET_WALK_ROCKET,      NO_MSG,                        DEATH_TURRET_LAST) \
40         DEATHTYPE(DEATH_VH_BUMB_DEATH,          DEATH_SELF_VH_BUMB_DEATH,           DEATH_MURDER_VH_BUMB_DEATH,    DEATH_VHFIRST) \
41         DEATHTYPE(DEATH_VH_BUMB_GUN,            NO_MSG,                             DEATH_MURDER_VH_BUMB_GUN,      NORMAL_POS) \
42         DEATHTYPE(DEATH_VH_CRUSH,               DEATH_SELF_VH_CRUSH,                DEATH_MURDER_VH_CRUSH,         NORMAL_POS) \
43         DEATHTYPE(DEATH_VH_RAPT_BOMB,           DEATH_SELF_VH_RAPT_BOMB,            DEATH_MURDER_VH_RAPT_BOMB,     NORMAL_POS) \
44         DEATHTYPE(DEATH_VH_RAPT_CANNON,         NO_MSG,                             DEATH_MURDER_VH_RAPT_CANNON,   NORMAL_POS) \
45         DEATHTYPE(DEATH_VH_RAPT_DEATH,          DEATH_SELF_VH_RAPT_DEATH,           DEATH_MURDER_VH_RAPT_DEATH,    NORMAL_POS) \
46         DEATHTYPE(DEATH_VH_RAPT_FRAGMENT,       DEATH_SELF_VH_RAPT_BOMB,            DEATH_MURDER_VH_RAPT_BOMB,     NORMAL_POS) \
47         DEATHTYPE(DEATH_VH_SPID_DEATH,          DEATH_SELF_VH_SPID_DEATH,           DEATH_MURDER_VH_SPID_DEATH,    NORMAL_POS) \
48         DEATHTYPE(DEATH_VH_SPID_MINIGUN,        NO_MSG,                             DEATH_MURDER_VH_SPID_MINIGUN,  NORMAL_POS) \
49         DEATHTYPE(DEATH_VH_SPID_ROCKET,         DEATH_SELF_VH_SPID_ROCKET,          DEATH_MURDER_VH_SPID_ROCKET,   NORMAL_POS) \
50         DEATHTYPE(DEATH_VH_WAKI_DEATH,          DEATH_SELF_VH_WAKI_DEATH,           DEATH_MURDER_VH_WAKI_DEATH,    NORMAL_POS) \
51         DEATHTYPE(DEATH_VH_WAKI_GUN,            NO_MSG,                             DEATH_MURDER_VH_WAKI_GUN,      NORMAL_POS) \
52         DEATHTYPE(DEATH_VH_WAKI_ROCKET,         DEATH_SELF_VH_WAKI_ROCKET,          DEATH_MURDER_VH_WAKI_ROCKET,   DEATH_VHLAST) \
53         DEATHTYPE(DEATH_WEAPON,                 NO_MSG,                             NO_MSG,                        NORMAL_POS)
54
55 #define DT_FIRST 10000
56 #define DT_MAX 128 // limit of recursive functions with ACCUMULATE_FUNCTION
57 float DT_COUNT;
58
59 entity deathtypes[DT_MAX];
60 .entity death_msgself;
61 .entity death_msgmurder;
62
63 #define DEATHTYPE(name,msg_death,msg_death_by,position) \
64         float name; \
65         float position; \
66         void RegisterDeathtype_##name() \
67         { \
68                 SET_FIRST_OR_LAST(position, DT_FIRST, DT_COUNT) \
69                 SET_FIELD_COUNT(name, DT_FIRST, DT_COUNT) \
70                 CHECK_MAX_COUNT(name, DT_MAX, DT_COUNT, "deathtypes") \
71                 \
72                 entity deathent = spawn(); \
73                 deathtypes[(name - DT_FIRST)] = deathent; \
74                 deathent.classname = "deathtype"; \
75                 deathent.nent_name = #name; \
76                 if (msg_death != NO_MSG) \
77                         deathent.death_msgself = msg_multi_notifs[msg_death - 1]; \
78                 if (msg_death_by != NO_MSG) \
79                         deathent.death_msgmurder = msg_multi_notifs[msg_death_by - 1]; \
80         } \
81         ACCUMULATE_FUNCTION(RegisterDeathtypes, RegisterDeathtype_##name);
82
83 DEATHTYPES
84 #undef DEATHTYPE
85
86 #define DEATH_ISSPECIAL(t)            ((t) >= DEATH_SPECIAL_START)
87 #define DEATH_ISVEHICLE(t)            ((t) >= DEATH_VHFIRST && (t) <= DEATH_VHLAST)
88 #define DEATH_ISTURRET(t)             ((t) >= DEATH_TURRET_FIRST && (t) <= DEATH_TURRET_LAST)
89 #define DEATH_WEAPONOFWEAPONDEATH(t)  ((t) & DEATH_WEAPONMASK)
90 #define DEATH_ISWEAPON(t,w)           (!DEATH_ISSPECIAL(t) && DEATH_WEAPONOFWEAPONDEATH(t) == (w))
91 #define DEATH_WEAPONOF(t)             (DEATH_ISSPECIAL(t) ? 0 : DEATH_WEAPONOFWEAPONDEATH(t))
92 #define WEP_VALID(w)                  ((w) >= WEP_FIRST && (w) <= WEP_LAST)
93
94 string Deathtype_Name(float deathtype)
95 {
96         if(DEATH_ISSPECIAL(deathtype))
97         {
98                 entity deathent = deathtypes[(deathtype - DT_FIRST)];
99                 if not(deathent) { backtrace("Deathtype_Name: Could not find deathtype entity!\n"); return ""; }
100                 return deathent.nent_name;
101         }
102         else { return ftos(deathtype); }
103 }
104
105 const float DEATH_WEAPONMASK = 0xFF;
106 const float DEATH_HITTYPEMASK = 0x1F00; // which is WAY below 10000 used for normal deaths
107 const float HITTYPE_SECONDARY = 0x100;
108 const float HITTYPE_SPLASH = 0x200; // automatically set by RadiusDamage
109 const float HITTYPE_BOUNCE = 0x400;
110 const float HITTYPE_RESERVED2 = 0x800;
111 const float HITTYPE_RESERVED = 0x1000; // unused yet