From cde5543f500e1595ce7a81d9d31427c1ca0d2b36 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Sun, 30 Jun 2013 17:41:23 -0400 Subject: [PATCH] Add sorting support to the weapon config dumping function --- qcsrc/common/weapons/config.qc | 42 ++++++++++++++++++++++++++++++++-- qcsrc/common/weapons/config.qh | 21 ++++++++++++----- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/qcsrc/common/weapons/config.qc b/qcsrc/common/weapons/config.qc index 424d9cdc2..47bfe2e21 100644 --- a/qcsrc/common/weapons/config.qc +++ b/qcsrc/common/weapons/config.qc @@ -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); } } diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 23d8d0a9a..3945ead23 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -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)) } -- 2.39.2