]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/miscfunctions.qc
de-linuxed the code base a bit
[divverent/nexuiz.git] / data / qcsrc / client / miscfunctions.qc
1 var float(string text, float handleColors) stringwidth;
2
3 entity players;
4 entity teams;
5
6 void AuditLists()
7 {
8         entity e;
9         entity prev;
10
11         prev = players;
12         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
13         {
14                 if(prev != e.sort_prev)
15                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
16         }
17
18         prev = teams;
19         for(e = prev.sort_next; e; prev = e, e = e.sort_next)
20         {
21                 if(prev != e.sort_prev)
22                         error(strcat("sort list chain error\nplease submit the output of 'prvm_edicts client' to the developers"));
23         }
24 }
25
26
27 float RegisterPlayer(entity player)
28 {
29         entity pl;
30         AuditLists();
31         for(pl = players.sort_next; pl; pl = pl.sort_next)
32                 if(pl == player)
33                         error("Player already registered!");
34         player.sort_next = players.sort_next;
35         player.sort_prev = players;
36         if(players.sort_next)
37                 players.sort_next.sort_prev = player;
38         players.sort_next = player;
39         AuditLists();
40         return true;
41 }
42
43 void RemovePlayer(entity player)
44 {
45         entity pl, parent;
46         AuditLists();
47         parent = players;
48         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
49                 parent = pl;
50
51         if(!pl)
52         {
53                 error("Trying to remove a player which is not in the playerlist!");
54                 return;
55         }
56         parent.sort_next = player.sort_next;
57         if(player.sort_next)
58                 player.sort_next.sort_prev = parent;
59         AuditLists();
60 }
61
62 void MoveToLast(entity e)
63 {
64         AuditLists();
65         other = e.sort_next;
66         while(other)
67         {
68                 SORT_SWAP(other, e);
69                 other = e.sort_next;
70         }
71         AuditLists();
72 }
73
74 float RegisterTeam(entity Team)
75 {
76         entity tm;
77         AuditLists();
78         for(tm = teams.sort_next; tm; tm = tm.sort_next)
79                 if(tm == Team)
80                         error("Team already registered!");
81         Team.sort_next = teams.sort_next;
82         Team.sort_prev = teams;
83         if(teams.sort_next)
84                 teams.sort_next.sort_prev = Team;
85         teams.sort_next = Team;
86         AuditLists();
87         return true;
88 }
89
90 void RemoveTeam(entity Team)
91 {
92         entity tm, parent;
93         AuditLists();
94         parent = teams;
95         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
96                 parent = tm;
97
98         if(!tm)
99         {
100                 print("Trying to remove a team which is not in the teamlist!");
101                 return;
102         }
103         parent.sort_next = Team.sort_next;
104         if(Team.sort_next)
105                 Team.sort_next.sort_prev = parent;
106         AuditLists();
107 }
108
109 entity GetTeam(float Team, float add)
110 {
111         float num;
112         entity tm;
113         num = (Team == COLOR_SPECTATOR) ? 16 : Team;
114         if(teamslots[num])
115                 return teamslots[num];
116         if not(add)
117                 return NULL;
118         tm = spawn();
119         tm.team = Team;
120         teamslots[num] = tm;
121         RegisterTeam(tm);
122         return tm;
123 }
124
125 float stringwidth_oldfont(string text, float handleColors)
126 {
127         float i, len, ch, width;
128         len = strlen(text);
129         if(!handleColors)
130                 return len;
131         width = 0;
132         for(i = 0; i < len; ++i)
133         {
134                 if(substring(text, i, 1) == "^")
135                 {
136                         ch = str2chr(text, i+1);
137                         if(ch >= '0' && ch <= '9')
138                                 ++i;
139                         else
140                                 ++width;
141                 }
142                 else
143                         ++width;
144         }
145         return width;
146 }
147
148 void CSQC_CheckEngine()
149 {
150         /*
151         registercvar("csqc_flags", "0");
152         csqc_flags = cvar("csqc_flags");
153         */
154
155         csqc_flags = 0;
156         
157         if(checkextension("DP_SV_WRITEPICTURE"))
158         {
159                 stringwidth = stringwidth_engine;
160                 sbar_font = FONT_USER+1;
161                 sbar_bigfont = FONT_USER+2;
162                 csqc_flags |= CSQC_FLAG_READPICTURE;
163         } else {
164                 stringwidth = stringwidth_oldfont;
165                 sbar_font = FONT_DEFAULT;
166                 sbar_bigfont = FONT_DEFAULT;
167         }
168 }
169
170 vector Sbar_GetFontsize()
171 {
172         if(csqc_flags & CSQC_FLAG_READPICTURE)
173         {
174                 vector v;
175                 v = stov(cvar_string("sbar_fontsize"));
176                 if(v_x == 0)
177                         v = '8 8 0';
178                 if(v_y == 0)
179                         v_y = v_x;
180                 v_z = 0;
181                 return v;
182         }
183         return '8 8 0' ;
184 }
185
186 float Sbar_GetWidth(float teamcolumnwidth)
187 {
188         if(csqc_flags & CSQC_FLAG_READPICTURE)
189         {
190                 float f;
191                 f = stof(cvar_string("sbar_width"));
192                 if(f == 0)
193                         f = 640;
194                 if(f < 320)
195                         f = 320;
196                 if(f > vid_conwidth - 2 * teamcolumnwidth)
197                         f = vid_conwidth - 2 * teamcolumnwidth;
198                 return f;
199         }
200         return 640;
201 }
202
203 float PreviewExists(string name)
204 {
205         float f;
206         string file;
207
208         if(cvar("cl_readpicture_force"))
209                 return false;
210
211         file = strcat(name, ".tga");
212         f = fopen(file, FILE_READ);
213         if(f >= 0)
214         {
215                 fclose(f);
216                 return true;
217         }
218         file = strcat(name, ".png");
219         f = fopen(file, FILE_READ);
220         if(f >= 0)
221         {
222                 fclose(f);
223                 return true;
224         }
225         file = strcat(name, ".jpg");
226         f = fopen(file, FILE_READ);
227         if(f >= 0)
228         {
229                 fclose(f);
230                 return true;
231         }
232         file = strcat(name, ".pcx");
233         f = fopen(file, FILE_READ);
234         if(f >= 0)
235         {
236                 fclose(f);
237                 return true;
238         }
239         return false;
240 }
241
242 float PI      = 3.14159265359;
243 float DEG2RAD = 0.01745329252;
244 vector rotate(vector v, float a)
245 {
246         vector w;
247         // FTEQCC SUCKS AGAIN
248         w_x =      v_x * cos(a) + v_y * sin(a);
249         w_y = -1 * v_x * sin(a) + v_y * cos(a);
250         return w;
251 }