]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/miscfunctions.qc
particles: volume weighting = negative count, absolute weighting = positive count
[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 float RegisterPlayer(entity player)
7 {
8         entity pl;
9         for(pl = players.sort_next; pl; pl = pl.sort_next)
10                 if(pl == player)
11                         error("Player already registered!");
12         player.sort_next = players.sort_next;
13         player.sort_prev = players;
14         if(players.sort_next)
15                 players.sort_next.sort_prev = player;
16         players.sort_next = player;
17         return true;
18 }
19
20 void RemovePlayer(entity player)
21 {
22         entity pl, parent;
23         parent = players;
24         for(pl = players.sort_next; pl && pl != player; pl = pl.sort_next)
25                 parent = pl;
26
27         if(!pl)
28         {
29                 error("Trying to remove a player which is not in the playerlist!");
30                 return;
31         }
32         parent.sort_next = player.sort_next;
33         if(player.sort_next)
34                 player.sort_next.sort_prev = parent;
35 }
36
37 void MoveToLast(entity e)
38 {
39         other = e.sort_next;
40         while(other)
41         {
42                 SORT_SWAP(other, e);
43                 other = e.sort_next;
44         }
45 }
46
47 // warning: Local "team" defined with name of a global
48 // FU FTEQCC, .float team is a ENTVAR shitty piece of crap!!!
49 float RegisterTeam(entity Team)
50 {
51         entity tm;
52         for(tm = teams.sort_next; tm; tm = tm.sort_next)
53                 if(tm == Team)
54                         error("Team already registered!");
55         Team.sort_next = teams.sort_next;
56         Team.sort_prev = teams;
57         if(teams.sort_next)
58                 teams.sort_next.sort_prev = Team;
59         teams.sort_next = Team;
60         return true;
61 }
62
63 void RemoveTeam(entity Team)
64 {
65         entity tm, parent;
66         parent = teams;
67         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
68                 parent = tm;
69
70         if(!tm)
71         {
72                 print("Trying to remove a team which is not in the teamlist!");
73                 return;
74         }
75         parent.sort_next = Team.sort_next;
76         if(Team.sort_next)
77                 Team.sort_next.sort_prev = parent;
78 }
79
80 entity GetTeam(float Team, float add)
81 {
82         float num;
83         entity tm;
84         num = (Team == COLOR_SPECTATOR) ? 16 : Team;
85         if(teamslots[num])
86                 return teamslots[num];
87         if not(add)
88                 return NULL;
89         tm = spawn();
90         tm.team = Team;
91         teamslots[num] = tm;
92         RegisterTeam(tm);
93         return tm;
94 }
95
96 float stringwidth_oldfont(string text, float handleColors)
97 {
98         float i, len, ch, width;
99         len = strlen(text);
100         if(!handleColors)
101                 return len;
102         width = 0;
103         for(i = 0; i < len; ++i)
104         {
105                 if(substring(text, i, 1) == "^")
106                 {
107                         ch = str2chr(text, i+1);
108                         if(ch >= '0' && ch <= '9')
109                                 ++i;
110                         else
111                                 ++width;
112                 }
113                 else
114                         ++width;
115         }
116         return width;
117 }
118
119 void CSQC_CheckEngine()
120 {
121         /*
122         registercvar("csqc_flags", "0");
123         csqc_flags = cvar("csqc_flags");
124         */
125
126         csqc_flags = 0;
127         
128         if(checkextension("DP_SV_WRITEPICTURE"))
129         {
130                 stringwidth = stringwidth_engine;
131                 sbar_font = FONT_USER+1;
132                 sbar_bigfont = FONT_USER+2;
133                 csqc_flags |= CSQC_FLAG_READPICTURE;
134         } else {
135                 stringwidth = stringwidth_oldfont;
136                 sbar_font = FONT_DEFAULT;
137                 sbar_bigfont = FONT_DEFAULT;
138         }
139 }
140
141 vector Sbar_GetFontsize()
142 {
143         if(csqc_flags & CSQC_FLAG_READPICTURE)
144         {
145                 vector v;
146                 v = stov(cvar_string("sbar_fontsize"));
147                 if(v_x == 0)
148                         v = '8 8 0';
149                 if(v_y == 0)
150                         v_y = v_x;
151                 v_z = 0;
152                 return v;
153         }
154         return '8 8 0' ;
155 }
156
157 float PreviewExists(string name)
158 {
159         float f;
160         string file;
161
162         if(cvar("cl_readpicture_force"))
163                 return false;
164
165         file = strcat(name, ".tga");
166         f = fopen(file, FILE_READ);
167         if(f >= 0)
168         {
169                 fclose(f);
170                 return true;
171         }
172         file = strcat(name, ".png");
173         f = fopen(file, FILE_READ);
174         if(f >= 0)
175         {
176                 fclose(f);
177                 return true;
178         }
179         file = strcat(name, ".jpg");
180         f = fopen(file, FILE_READ);
181         if(f >= 0)
182         {
183                 fclose(f);
184                 return true;
185         }
186         file = strcat(name, ".pcx");
187         f = fopen(file, FILE_READ);
188         if(f >= 0)
189         {
190                 fclose(f);
191                 return true;
192         }
193         return false;
194 }