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