]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/miscfunctions.qc
add sbar_bigfont; use that for headlines
[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                         return false;
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                 print("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 entity AddTeam(float num)
39 {
40         entity tm;
41         tm = spawn();
42         tm.team = num;
43         tm.sort_next = teams.sort_next;
44         tm.sort_prev = teams;
45         if(teams.sort_next)
46                 teams.sort_next.sort_prev = tm;
47         teams.sort_next = tm;
48         return tm;
49 }
50
51 void MoveToLast(entity e)
52 {
53         other = e.sort_next;
54         while(other)
55         {
56                 SORT_SWAP(other, e);
57                 other = e.sort_next;
58         }
59 }
60
61 // warning: Local "team" defined with name of a global
62 // FU FTEQCC, .float team is a ENTVAR shitty piece of crap!!!
63 float RegisterTeam(entity Team)
64 {
65         entity tm;
66         for(tm = teams.sort_next; tm; tm = tm.sort_next)
67                 if(tm == Team)
68                         return false;
69         Team.sort_next = teams.sort_next;
70         Team.sort_prev = teams;
71         if(teams.sort_next)
72                 teams.sort_next.sort_prev = Team;
73         teams.sort_next = Team;
74         return true;
75 }
76
77 void RemoveTeam(entity Team)
78 {
79         entity tm, parent;
80         parent = teams;
81         for(tm = teams.sort_next; tm && tm != Team; tm = tm.sort_next)
82                 parent = tm;
83
84         if(!tm)
85         {
86                 print("Trying to remove a team which is not in the teamlist!");
87                 return;
88         }
89         parent.sort_next = Team.sort_next;
90         if(Team.sort_next)
91                 Team.sort_next.sort_prev = parent;
92 }
93
94 entity GetTeam(float num, float add)
95 {
96         entity tm;
97         for(tm = teams.sort_next; tm; tm = tm.sort_next)
98         {
99                 if(tm.team == num)
100                         return tm;
101         }
102         
103         if(add)
104                 return AddTeam(num);
105         
106         return NULL;
107 }
108
109 float stringwidth_oldfont(string text, float handleColors)
110 {
111         float i, len, ch, width;
112         len = strlen(text);
113         if(!handleColors)
114                 return len;
115         width = 0;
116         for(i = 0; i < len; ++i)
117         {
118                 if(substring(text, i, 1) == "^")
119                 {
120                         ch = str2chr(text, i+1);
121                         if(ch >= '0' && ch <= '9')
122                                 ++i;
123                         else
124                                 ++width;
125                 }
126                 else
127                         ++width;
128         }
129         return width;
130 }
131
132 void CSQC_CheckEngine()
133 {
134         /*
135         registercvar("csqc_flags", "0");
136         csqc_flags = cvar("csqc_flags");
137         */
138
139         csqc_flags = 0;
140         
141         if(checkextension("DP_SV_WRITEPICTURE"))
142         {
143                 stringwidth = stringwidth_engine;
144                 sbar_font = FONT_USER+1;
145                 sbar_bigfont = FONT_USER+2;
146                 csqc_flags |= CSQC_FLAG_READPICTURE;
147         } else {
148                 stringwidth = stringwidth_oldfont;
149                 sbar_font = FONT_DEFAULT;
150                 sbar_bigfont = FONT_DEFAULT;
151         }
152 }
153
154 vector Sbar_GetFontsize()
155 {
156         if(csqc_flags & CSQC_FLAG_READPICTURE)
157                 return stov(cvar_string("sbar_fontsize"));
158         return '8 8 0' ;
159 }
160
161 float PreviewExists(string name)
162 {
163         float f;
164         string file;
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 }