Xonotic
config.qc
Go to the documentation of this file.
1 #include "config.qh"
2 
3 #if defined(CSQC)
4 #elif defined(MENUQC)
5 #elif defined(SVQC)
6  #include <common/turrets/all.qh>
7  #include <common/util.qh>
8 #endif
9 
10 // ==========================
11 // Turret Config Generator
12 // ==========================
13 
14 #ifdef SVQC
15 
16 void T_Config_Queue(string setting)
17 {
18  if (TUR_CONFIG_COUNT <= MAX_CONFIG_SETTINGS - 1)
19  config_queue[TUR_CONFIG_COUNT++] = setting;
20 }
21 
22 void T_Config_Queue_Swap(float root, float child, entity pass)
23 {
24  string oldroot = config_queue[root];
25  config_queue[root] = config_queue[child];
26  config_queue[child] = oldroot;
27 }
28 
29 float T_Config_Queue_Compare(float root, float child, entity pass)
30 {
31  float i, r, c;
32 
33  for(i = 1; i <= 100; ++i)
34  {
35  r = str2chr(config_queue[root], i);
36  c = str2chr(config_queue[child], i);
37  if(r == c) { continue; }
38  else if(c > r) { return -1; }
39  else { return 1; }
40  }
41 
42  return 0;
43 }
44 
45 void Dump_Turret_Settings()
46 {
47  #define TUR_CONFIG_WRITETOFILE(str) write_String_To_File(tur_config_file, str, tur_config_alsoprint)
48  int totalsettings = 0;
49  FOREACH(Turrets, it != TUR_Null, {
50  // step 1: clear the queue
51  TUR_CONFIG_COUNT = 0;
52  for (int j = 0; j < MAX_CONFIG_SETTINGS; ++j)
53  config_queue[j] = string_null;
54 
55  // step 2: build new queue
56  it.tr_config(it);
57 
58  if (TUR_CONFIG_COUNT > MAX_CONFIG_SETTINGS - 1)
59  {
60  LOG_INFOF("\n^1Dumping aborted^7: hit MAX_CONFIG_SETTINGS (%d) limit\n\n", MAX_CONFIG_SETTINGS);
61  break;
62  }
63 
64  // step 3: sort queue
65  heapsort(TUR_CONFIG_COUNT, T_Config_Queue_Swap, T_Config_Queue_Compare, NULL);
66 
67  // step 4: write queue
68  TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name));
69  for (int j = 0; j < TUR_CONFIG_COUNT; ++j)
70  TUR_CONFIG_WRITETOFILE(config_queue[j]);
71  TUR_CONFIG_WRITETOFILE("// }}}\n");
72 
73  // step 5: debug info
74  LOG_INFOF("#%d: %s: %d settings...", i, it.turret_name, TUR_CONFIG_COUNT);
75  totalsettings += TUR_CONFIG_COUNT;
76  });
77  #undef TUR_CONFIG_WRITETOFILE
78 
79  // extra information
80  if (TUR_CONFIG_COUNT <= MAX_CONFIG_SETTINGS - 1)
81  LOG_INFOF("Totals: %d turrets, %d settings", (REGISTRY_COUNT(Turrets) - 1), totalsettings);
82 
83  // clear queue now that we're finished
84  TUR_CONFIG_COUNT = 0;
85  for (int j = 0; j < MAX_CONFIG_SETTINGS; ++j)
86  config_queue[j] = string_null;
87 }
88 
89 #endif
string string_null
Definition: nil.qh:9
#define str2chr
Definition: dpextensions.qh:45
entity() spawn
ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass)
Definition: sort.qh:9
#define REGISTRY_COUNT(id)
Definition: registry.qh:18
#define LOG_INFOF(...)
Definition: log.qh:71
#define NULL
Definition: post.qh:17
#define pass(name, colormin, colormax)
#define FOREACH(list, cond, body)
Definition: iter.qh:19