]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/miscfunctions.qc
remove unuseds (except for the fteqcc bug ones)
[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                 return stov(cvar_string("sbar_fontsize"));
145         return '8 8 0' ;
146 }
147
148 float PreviewExists(string name)
149 {
150         float f;
151         string file;
152
153         if(cvar("cl_readpicture_force"))
154                 return false;
155
156         file = strcat(name, ".tga");
157         f = fopen(file, FILE_READ);
158         if(f >= 0)
159         {
160                 fclose(f);
161                 return true;
162         }
163         file = strcat(name, ".png");
164         f = fopen(file, FILE_READ);
165         if(f >= 0)
166         {
167                 fclose(f);
168                 return true;
169         }
170         file = strcat(name, ".jpg");
171         f = fopen(file, FILE_READ);
172         if(f >= 0)
173         {
174                 fclose(f);
175                 return true;
176         }
177         file = strcat(name, ".pcx");
178         f = fopen(file, FILE_READ);
179         if(f >= 0)
180         {
181                 fclose(f);
182                 return true;
183         }
184         return false;
185 }