]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/deathtypes.qh
Fix compilation with gmqcc.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / deathtypes.qh
index 033779567df719559610436305b317e95977d045..cc7154d4b6a8713de9236413ecdb01adcf2d0db1 100644 (file)
@@ -1,32 +1,6 @@
-// Deathtypes (weapon deathtypes are the IT_* constants below)
-// NOTE: when adding death types, please add an explanation to Docs/spamlog.txt too.
-#define DT_FIRST 10000
-#define DT_MAX 1024 // limit of recursive functions with ACCUMULATE_FUNCTION
-float DT_COUNT;
-
-entity deathtypes[DT_MAX];
-.entity death_msgself;
-.entity death_msgmurder;
-
-#define DEATHTYPE(name,msg_death,msg_death_by,position) \
-       float name; \
-       float position; \
-       void RegisterDeathtype_##name() \
-       { \
-               SET_FIRST_OR_LAST(position, DT_FIRST, DT_COUNT) \
-               SET_FIELD_COUNT(name, DT_FIRST, DT_COUNT) \
-               CHECK_MAX_COUNT(name, DT_MAX, DT_COUNT, "deathtypes") \
-               \
-               entity deathent = spawn(); \
-               deathtypes[name - 1] = deathent; \
-               #if (msg_death != NO_MSG) \
-                       deathent.death_msgself = msg_multi_notifs[msg_death - 1]; \
-               #endif \
-               #if (msg_death_by != NO_MSG) \
-                       deathent.death_msgmurder = msg_multi_notifs[msg_death_by - 1]; \
-               #endif \
-       } \
-       ACCUMULATE_FUNCTION(RegisterDeathtypes, RegisterDeathtype_##name)
+// ================================
+//  Deathtypes, reworked by Samual
+// ================================
 
 #define DEATHTYPES \
        DEATHTYPE(DEATH_AUTOTEAMCHANGE,         DEATH_SELF_AUTOTEAMCHANGE,          NO_MSG,                        DEATH_SPECIAL_START) \
@@ -41,6 +15,7 @@ entity deathtypes[DT_MAX];
        DEATHTYPE(DEATH_KILL,                   DEATH_SELF_SUICIDE,                 NO_MSG,                        NORMAL_POS) \
        DEATHTYPE(DEATH_LAVA,                   DEATH_SELF_LAVA,                    DEATH_MURDER_LAVA,             NORMAL_POS) \
        DEATHTYPE(DEATH_MIRRORDAMAGE,           DEATH_SELF_BETRAYAL,                NO_MSG,                        NORMAL_POS) \
+       DEATHTYPE(DEATH_NADE,                                   DEATH_SELF_NADE,                                        DEATH_MURDER_NADE,                         NORMAL_POS) \
        DEATHTYPE(DEATH_NOAMMO,                 DEATH_SELF_NOAMMO,                  NO_MSG,                        NORMAL_POS) \
        DEATHTYPE(DEATH_ROT,                    DEATH_SELF_ROT,                     NO_MSG,                        NORMAL_POS) \
        DEATHTYPE(DEATH_SHOOTING_STAR,          DEATH_SELF_SHOOTING_STAR,           DEATH_MURDER_SHOOTING_STAR,    NORMAL_POS) \
@@ -77,6 +52,34 @@ entity deathtypes[DT_MAX];
        DEATHTYPE(DEATH_VH_WAKI_ROCKET,         DEATH_SELF_VH_WAKI_ROCKET,          DEATH_MURDER_VH_WAKI_ROCKET,   DEATH_VHLAST) \
        DEATHTYPE(DEATH_WEAPON,                 NO_MSG,                             NO_MSG,                        NORMAL_POS)
 
+#define DT_FIRST 10000
+#define DT_MAX 128 // limit of recursive functions with ACCUMULATE_FUNCTION
+float DT_COUNT;
+
+entity deathtypes[DT_MAX];
+.entity death_msgself;
+.entity death_msgmurder;
+
+#define DEATHTYPE(name,msg_death,msg_death_by,position) \
+       float name; \
+       float position; \
+       void RegisterDeathtype_##name() \
+       { \
+               SET_FIRST_OR_LAST(position, DT_FIRST, DT_COUNT) \
+               SET_FIELD_COUNT(name, DT_FIRST, DT_COUNT) \
+               CHECK_MAX_COUNT(name, DT_MAX, DT_COUNT, "deathtypes") \
+               \
+               entity deathent = spawn(); \
+               deathtypes[(name - DT_FIRST)] = deathent; \
+               deathent.classname = "deathtype"; \
+               deathent.nent_name = #name; \
+               if (msg_death != NO_MSG) \
+                       deathent.death_msgself = msg_multi_notifs[msg_death - 1]; \
+               if (msg_death_by != NO_MSG) \
+                       deathent.death_msgmurder = msg_multi_notifs[msg_death_by - 1]; \
+       } \
+       ACCUMULATE_FUNCTION(RegisterDeathtypes, RegisterDeathtype_##name);
+
 DEATHTYPES
 #undef DEATHTYPE
 
@@ -92,19 +95,17 @@ string Deathtype_Name(float deathtype)
 {
        if(DEATH_ISSPECIAL(deathtype))
        {
-               #define DEATHTYPE(name,msg_death,msg_death_by,position) \
-                       { if(deathtype == max(0, name)) return VAR_TO_TEXT(name); }
-
-               DEATHTYPES
-               #undef DEATHTYPE
+               entity deathent = deathtypes[(deathtype - DT_FIRST)];
+               if not(deathent) { backtrace("Deathtype_Name: Could not find deathtype entity!\n"); return ""; }
+               return deathent.nent_name;
        }
-       return "foobar";
+       else { return ftos(deathtype); }
 }
 
-float DEATH_WEAPONMASK = 0xFF;
-float DEATH_HITTYPEMASK = 0x1F00; // which is WAY below 10000 used for normal deaths
-float HITTYPE_SECONDARY = 0x100;
-float HITTYPE_SPLASH = 0x200; // automatically set by RadiusDamage
-float HITTYPE_BOUNCE = 0x400;
-float HITTYPE_RESERVED2 = 0x800;
-float HITTYPE_RESERVED = 0x1000; // unused yet
+const float DEATH_WEAPONMASK = 0xFF;
+const float DEATH_HITTYPEMASK = 0x1F00; // which is WAY below 10000 used for normal deaths
+const float HITTYPE_SECONDARY = 0x100;
+const float HITTYPE_SPLASH = 0x200; // automatically set by RadiusDamage
+const float HITTYPE_BOUNCE = 0x400;
+const float HITTYPE_RESERVED2 = 0x800;
+const float HITTYPE_RESERVED = 0x1000; // unused yet