]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add sorting support to the weapon config dumping function
authorSamual Lenks <samual@xonotic.org>
Sun, 30 Jun 2013 21:41:23 +0000 (17:41 -0400)
committerSamual Lenks <samual@xonotic.org>
Sun, 30 Jun 2013 21:41:23 +0000 (17:41 -0400)
qcsrc/common/weapons/config.qc
qcsrc/common/weapons/config.qh

index 424d9cdc249d1120a6370307b5bc68e32c8d01c5..47bfe2e21896d5ce96540ec7fd249a663c7d55a6 100644 (file)
@@ -2,17 +2,55 @@
 //  Balance Config Generator
 // ==========================
 
+void W_Config_Queue_Swap(float root, float child, entity pass)
+{
+       string oldroot = wep_config_queue[root];
+       wep_config_queue[root] = wep_config_queue[child];
+       wep_config_queue[child] = oldroot;
+}
+
+float W_Config_Queue_Compare(float root, float child, entity pass)
+{
+       float i, r, c;
+
+       for(i = 1; i <= 100; ++i)
+       {
+               r = str2chr(wep_config_queue[root], i);
+               c = str2chr(wep_config_queue[child], i);
+               if(r == c) { continue; }
+               else if(c > r) { return -1; }
+               else { return 1; }
+       }
+       
+       return 0;
+}
+
 void Dump_Weapon_Settings(void)
 {
-       float i;
+       float i, x;
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
-               WEP_CONFIG_WRITE(sprintf("// {{{ #%d: %s\n", i, W_Name(i)))
+               // step 1: clear the queue
+               WEP_CONFIG_COUNT = 0;
+               for(x = 0; x <= MAX_WEP_CONFIG; ++x)
+                       { wep_config_queue[x] = string_null; }
+
+               // step 2: build new queue
                WEP_ACTION(i, WR_CONFIG);
+
+               // step 3: sort queue
+               heapsort(WEP_CONFIG_COUNT, W_Config_Queue_Swap, W_Config_Queue_Compare, world);
+               
+               // step 4: write queue
+               WEP_CONFIG_WRITE(sprintf("// {{{ #%d: %s\n// %d settings\n", i, W_Name(i), WEP_CONFIG_COUNT))
+               for(x = 0; x <= WEP_CONFIG_COUNT; ++x)
+                       { WEP_CONFIG_WRITE(wep_config_queue[x]) }
                WEP_CONFIG_WRITE("// }}}\n")
        }
 }
        /*
+        * float WEP_CONFIG_COUNT;
+string wep_config_queue[MAX_WEP_CONFIG];
        #define WEP_BAL_WRITE(a) { \
                fputs(fh, a); \
                if(alsoprint) { print(a); } }
index 23d8d0a9a23dfbf3f25bebbcf99bca9576b19620..3945ead2397e8523dd553dd332bd4c836d9a1de3 100644 (file)
@@ -6,43 +6,52 @@ void Dump_Weapon_Settings(void);
 float wep_config_file;
 float wep_config_alsoprint;
 
+#define MAX_WEP_CONFIG 256
+float WEP_CONFIG_COUNT;
+string wep_config_queue[MAX_WEP_CONFIG];
+
+#define WEP_CONFIG_QUEUE(a) { \
+       print(sprintf("foobar: %g: %s\n", WEP_CONFIG_COUNT, a)); \
+       wep_config_queue[WEP_CONFIG_COUNT] = a; \
+       ++WEP_CONFIG_COUNT; }
+
 #define WEP_CONFIG_WRITE(a) { \
        fputs(wep_config_file, a); \
        if(wep_config_alsoprint) { print(a); } }
 
 #define WEP_CONFIG_WRITE_CVARS(weapon,mode,name) \
        #if mode == MO_PRI \
-               { WEP_CONFIG_WRITE(sprintf( \
+               { WEP_CONFIG_QUEUE(sprintf( \
                        "set g_balance_%s_primary_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_primary_##name)) } \
        #endif \
        #if mode == MO_SEC \
-               { WEP_CONFIG_WRITE(sprintf("set g_balance_%s_secondary_%s %g\n", \
+               { WEP_CONFIG_QUEUE(sprintf("set g_balance_%s_secondary_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_secondary_##name)) } \
        #endif \
        #if mode == MO_BOTH \
-               { WEP_CONFIG_WRITE(sprintf("set g_balance_%s_primary_%s %g\n", \
+               { WEP_CONFIG_QUEUE(sprintf("set g_balance_%s_primary_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_primary_##name)) } \
-               { WEP_CONFIG_WRITE(sprintf("set g_balance_%s_secondary_%s %g\n", \
+               { WEP_CONFIG_QUEUE(sprintf("set g_balance_%s_secondary_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_secondary_##name)) } \
        #endif \
        #if mode == MO_NONE \
-               { WEP_CONFIG_WRITE(sprintf("set g_balance_%s_%s %g\n", \
+               { WEP_CONFIG_QUEUE(sprintf("set g_balance_%s_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_##name)) } \
        #endif
        
 #define WEP_CONFIG_WRITE_PROPS(weapon,prop,name) \
-       { WEP_CONFIG_WRITE(sprintf("set g_balance_%s_%s %g\n", \
+       { WEP_CONFIG_QUEUE(sprintf("set g_balance_%s_%s %g\n", \
                        #weapon, \
                        #name, \
                        autocvar_g_balance_##weapon##_##name)) }