]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move deathtypes to entities entirely
authorSamual Lenks <samual@xonotic.org>
Mon, 4 Mar 2013 01:04:28 +0000 (20:04 -0500)
committerSamual Lenks <samual@xonotic.org>
Mon, 4 Mar 2013 01:04:28 +0000 (20:04 -0500)
qcsrc/common/deathtypes.qh
qcsrc/server/g_damage.qc

index 033779567df719559610436305b317e95977d045..ca13f15a063e2fc674465312ebe1b600a1e88bd3 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) \
@@ -77,6 +51,36 @@ 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) - 1] = deathent; \
+               deathent.classname = "deathtype"; \
+               deathent.nent_name = #name; \
+               #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
 #undef DEATHTYPE
 
@@ -92,13 +96,11 @@ 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) - 1];
+               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;
index ec818cfcf46b3ae050389e3d650b7f46c89717b0..73882c08584d495e7273faf086f44e7aa355ad48 100644 (file)
@@ -263,7 +263,7 @@ void Obituary_SpecialDeath(entity notif_target, float murder, float deathtype, s
 {
        if(DEATH_ISSPECIAL(deathtype))
        {
-               entity deathent = deathtypes[deathtype - 1];
+               entity deathent = deathtypes[(deathtype - DT_FIRST) - 1];
                if not(deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; }
 
                if(murder)