]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/config.qc
Add sorting support to the weapon config dumping function
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / config.qc
1 // ==========================
2 //  Balance Config Generator
3 // ==========================
4
5 void W_Config_Queue_Swap(float root, float child, entity pass)
6 {
7         string oldroot = wep_config_queue[root];
8         wep_config_queue[root] = wep_config_queue[child];
9         wep_config_queue[child] = oldroot;
10 }
11
12 float W_Config_Queue_Compare(float root, float child, entity pass)
13 {
14         float i, r, c;
15
16         for(i = 1; i <= 100; ++i)
17         {
18                 r = str2chr(wep_config_queue[root], i);
19                 c = str2chr(wep_config_queue[child], i);
20                 if(r == c) { continue; }
21                 else if(c > r) { return -1; }
22                 else { return 1; }
23         }
24         
25         return 0;
26 }
27
28 void Dump_Weapon_Settings(void)
29 {
30         float i, x;
31         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
32         {
33                 // step 1: clear the queue
34                 WEP_CONFIG_COUNT = 0;
35                 for(x = 0; x <= MAX_WEP_CONFIG; ++x)
36                         { wep_config_queue[x] = string_null; }
37
38                 // step 2: build new queue
39                 WEP_ACTION(i, WR_CONFIG);
40
41                 // step 3: sort queue
42                 heapsort(WEP_CONFIG_COUNT, W_Config_Queue_Swap, W_Config_Queue_Compare, world);
43                 
44                 // step 4: write queue
45                 WEP_CONFIG_WRITE(sprintf("// {{{ #%d: %s\n// %d settings\n", i, W_Name(i), WEP_CONFIG_COUNT))
46                 for(x = 0; x <= WEP_CONFIG_COUNT; ++x)
47                         { WEP_CONFIG_WRITE(wep_config_queue[x]) }
48                 WEP_CONFIG_WRITE("// }}}\n")
49         }
50 }
51         /*
52          * float WEP_CONFIG_COUNT;
53 string wep_config_queue[MAX_WEP_CONFIG];
54         #define WEP_BAL_WRITE(a) { \
55                 fputs(fh, a); \
56                 if(alsoprint) { print(a); } }
57         #define WEP_BAL_WRITE_ENTITY(description) { \
58                 notif_msg = \
59                         sprintf( \
60                                 "seta notification_%s \"%d\" \"%s\"\n", \
61                                 e.nent_name, e.nent_default, description \
62                         ); \
63                 WEP_BAL_WRITE(notif_msg) }
64         #define WEP_BAL_WRITE_HARDCODED(cvar,default,description) { \
65                 notif_msg = \
66                         sprintf( \
67                                 "seta notification_%s \"%s\" \"%s\"\n", \
68                                 cvar, default, description \
69                         ); \
70                 WEP_BAL_WRITE(notif_msg) }
71
72         string notif_msg;
73         float i;
74         entity e;
75
76         NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
77         for(i = 1; i <= NOTIF_ANNCE_COUNT; ++i)
78         {
79                 e = Get_Notif_Ent(MSG_ANNCE, i);
80                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
81                 
82                 NOTIF_WRITE_ENTITY(
83                         "Notification control cvar: 0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled)"
84                 );
85         }
86
87         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
88         for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
89         {
90                 e = Get_Notif_Ent(MSG_INFO, i);
91                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
92                 
93                 NOTIF_WRITE_ENTITY(
94                         "Notification control cvar: 0 = off, 1 = print to console, "
95                         "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)"
96                 );
97         }
98
99         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
100         for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
101         {
102                 e = Get_Notif_Ent(MSG_CENTER, i);
103                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
104                 
105                 NOTIF_WRITE_ENTITY(
106                         "Notification control cvar: 0 = off, 1 = centerprint"
107                 );
108         }
109
110         NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
111         for(i = 1; i <= NOTIF_MULTI_COUNT; ++i)
112         {
113                 e = Get_Notif_Ent(MSG_MULTI, i);
114                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
115                 
116                 NOTIF_WRITE_ENTITY(
117                         "Notification control cvar: 0 = off, 1 = trigger subcalls"
118                 );
119         }
120
121         // edit these to match whichever cvars are used for specific notification options
122         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
123         
124         NOTIF_WRITE_HARDCODED(
125                 "allow_chatboxprint", "1",
126                 "Allow notifications to be printed to chat box by setting notification cvar to 2 "
127                 "(You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)"
128         );
129
130         NOTIF_WRITE(sprintf(
131                 strcat(
132                         "\n// Notification counts (total = %d): ",
133                         "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d\n"
134                 ),
135                 (
136                         NOTIF_ANNCE_COUNT +
137                         NOTIF_INFO_COUNT +
138                         NOTIF_CENTER_COUNT +
139                         NOTIF_MULTI_COUNT
140                 ),
141                 NOTIF_ANNCE_COUNT,
142                 NOTIF_INFO_COUNT,
143                 NOTIF_CENTER_COUNT,
144                 NOTIF_MULTI_COUNT
145         ));
146         
147         return;
148         #undef NOTIF_WRITE_HARDCODED
149         #undef NOTIF_WRITE_ENTITY
150         #undef NOTIF_WRITE
151 }*/