Introduce the shared function write_String_To_File that can be used by all the dump...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / config.qc
1 #include "config.qh"
2 // ==========================
3 //  Turret Config Generator
4 // ==========================
5
6 #ifdef SVQC
7
8 void T_Config_Queue_Swap(float root, float child, entity pass)
9 {
10         string oldroot = config_queue[root];
11         config_queue[root] = config_queue[child];
12         config_queue[child] = oldroot;
13 }
14
15 float T_Config_Queue_Compare(float root, float child, entity pass)
16 {
17         float i, r, c;
18
19         for(i = 1; i <= 100; ++i)
20         {
21                 r = str2chr(config_queue[root], i);
22                 c = str2chr(config_queue[child], i);
23                 if(r == c) { continue; }
24                 else if(c > r) { return -1; }
25                 else { return 1; }
26         }
27
28         return 0;
29 }
30
31 void Dump_Turret_Settings()
32 {
33         #define TUR_CONFIG_WRITETOFILE(str) write_String_To_File(tur_config_file, str, tur_config_alsoprint)
34         int totalsettings = 0;
35         FOREACH(Turrets, it != TUR_Null, {
36                 // step 1: clear the queue
37                 TUR_CONFIG_COUNT = 0;
38                 for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j)
39                         config_queue[j] = string_null;
40
41                 // step 2: build new queue
42                 it.tr_config(it);
43
44                 // step 3: sort queue
45                 heapsort(TUR_CONFIG_COUNT, T_Config_Queue_Swap, T_Config_Queue_Compare, NULL);
46
47                 // step 4: write queue
48                 TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name));
49                 for(int j = 0; j <= TUR_CONFIG_COUNT; ++j)
50                         TUR_CONFIG_WRITETOFILE(config_queue[j]);
51                 TUR_CONFIG_WRITETOFILE("// }}}\n");
52
53                 // step 5: debug info
54                 LOG_INFOF("#%d: %s: %d settings...", i, it.turret_name, TUR_CONFIG_COUNT);
55                 totalsettings += TUR_CONFIG_COUNT;
56         });
57         #undef TUR_CONFIG_WRITETOFILE
58
59         // clear queue now that we're finished
60         TUR_CONFIG_COUNT = 0;
61         for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j)
62                 config_queue[j] = string_null;
63
64         // extra information
65         LOG_INFOF("Totals: %d turrets, %d settings", (Turrets_COUNT - 1), totalsettings);
66 }
67
68 #endif