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