]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qh
f92633a41221697b7c6cc6d24e2a175d0a9ab301
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qh
1 #pragma once
2
3 entity players;
4 entity teams;
5 float team_count; // real teams
6
7 const int INITPRIO_FIRST                                = 0;
8 const int INITPRIO_GAMETYPE                     = 0;
9 const int INITPRIO_GAMETYPE_FALLBACK    = 1;
10 const int INITPRIO_FINDTARGET                   = 10;
11 const int INITPRIO_DROPTOFLOOR                  = 20;
12 const int INITPRIO_SETLOCATION                  = 90;
13 const int INITPRIO_LINKDOORS                    = 91;
14 const int INITPRIO_LAST                                 = 99;
15
16 void AuditLists();
17
18 float RegisterPlayer(entity player);
19
20 void RemovePlayer(entity player);
21
22 void MoveToLast(entity e);
23
24 float RegisterTeam(entity Team);
25
26 void RemoveTeam(entity Team);
27
28 entity GetTeam(int Team, bool add);
29
30 vector HUD_GetFontsize(string cvarname);
31
32 float PreviewExists(string name);
33
34 vector Rotate(vector v, float a);
35
36
37 #define IS_DEAD(s) (((s).classname == "csqcmodel") ? (s).csqcmodel_isdead : (GetResource((s), RES_HEALTH) <= 0))
38
39 float cvar_or(string cv, float v);
40
41 vector project_3d_to_2d(vector vec);
42
43 vector drawfontscale;
44 #define draw_beginBoldFont() drawfont = FONT_USER + 2
45 #define draw_endBoldFont() drawfont = FONT_USER + 1
46
47 float expandingbox_sizefactor_from_fadelerp(float fadelerp);
48
49 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor);
50
51 float blink_synced(float base, float range, float freq, float start_time, int start_blink);
52 float blink(float base, float range, float freq);
53
54 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag);
55
56 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag);
57
58 void HUD_Scale_Disable();
59 void HUD_Scale_Enable();
60
61 #define HUD_ScaleX(f) (f * hud_scale.x)
62 #define HUD_ScaleY(f) (f * hud_scale.y)
63 #define HUD_ShiftX(f) (f + hud_shift.x + hud_shift.z * (f - hud_scale_center.x))
64 #define HUD_ShiftY(f) (f + hud_shift.y + hud_shift.z * (f - hud_scale_center.y))
65 vector HUD_Scale(vector v);
66 vector HUD_Shift(vector v);
67
68 // The following functions / macros must be called from within
69 // the panel HUD / scoreboard code so that pos and size are scaled
70 // when the hud_dynamic code is running.
71 // Make use of stringwidth_builtin and draw*_builtin everywhere else.
72
73 float stringwidth(string text, float handleColors, vector sz);
74
75 #define drawpic(position, pic, size, rgb, alpha, flag) \
76         drawpic_builtin(HUD_Shift(position), pic, HUD_Scale(size), rgb, alpha, flag)
77
78 #define drawcharacter(position, character, scale, rgb, alpha, flag) \
79         drawcharacter_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
80
81 #define drawstring(position, text, scale, rgb, alpha, flag) \
82         drawstring_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
83
84 #define drawcolorcodedstring(position, text, scale, alpha, flag) \
85         drawcolorcodedstring_builtin(HUD_Shift(position), text, scale, alpha, flag)
86
87 #define drawcolorcodedstring2(position, text, scale, rgb, alpha, flag) \
88         drawcolorcodedstring2_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
89
90 #define drawfill(position, size, rgb, alpha, flag) \
91         drawfill_builtin(HUD_Shift(position), HUD_Scale(size), rgb, alpha, flag)
92
93 #define drawsetcliparea(xposition, yposition, w, h) \
94         drawsetcliparea_builtin(HUD_ShiftX(xposition), HUD_ShiftY(yposition), HUD_ScaleX(w), HUD_ScaleY(h))
95
96 // Since drawsubpic usually gets called multiple times from within an
97 // utility function, instead of scaling pos and size in every call
98 // we scale them once for all in the beginning of that utility function.
99 // That's why drawsubpic isn't remapped.
100 /*
101 #define drawsubpic(position, size, pic, srcPosition, srcSize, rgb, alpha, flag) \
102         drawsubpic_builtin(HUD_Shift(position), HUD_Scale(size), pic, HUD_Shift(srcPosition), HUD_Scale(srcSize), rgb, alpha, flag)
103 */
104
105 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
106 float _drawpic_imgaspect;
107 vector _drawpic_imgsize;
108 vector _drawpic_sz;
109 float _drawpic_oldsz;
110 string _drawpic_picpath;
111 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
112         MACRO_BEGIN \
113                 _drawpic_imgsize = draw_getimagesize(pic);\
114                 if(_drawpic_imgsize != '0 0 0') {\
115                         _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
116                         _drawpic_sz = mySize;\
117                         if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
118                                 _drawpic_oldsz = _drawpic_sz.x;\
119                                 _drawpic_sz.x = _drawpic_sz.y * _drawpic_imgaspect;\
120                                 if(_drawpic_sz.x)\
121                                         drawpic(pos + eX * 0.5 * (_drawpic_oldsz - _drawpic_sz.x), pic, _drawpic_sz, color, theAlpha, drawflag);\
122                         } else {\
123                                 _drawpic_oldsz = _drawpic_sz.y;\
124                                 _drawpic_sz.y = _drawpic_sz.x / _drawpic_imgaspect;\
125                                 if(_drawpic_sz.y)\
126                                         drawpic(pos + eY * 0.5 * (_drawpic_oldsz - _drawpic_sz.y), pic, _drawpic_sz, color, theAlpha, drawflag);\
127                         }\
128                 }\
129         MACRO_END
130
131 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
132 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
133         MACRO_BEGIN \
134                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
135                 if(precache_pic(_drawpic_picpath) == "") {\
136                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
137                 }\
138                 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
139                 _drawpic_picpath = string_null;\
140         MACRO_END
141
142 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
143 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
144         MACRO_BEGIN \
145                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
146                 if(precache_pic(_drawpic_picpath) == "") {\
147                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
148                 }\
149                 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
150                 _drawpic_picpath = string_null;\
151         MACRO_END
152
153 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
154
155 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
156
157 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
158 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag);
159
160 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
161 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag);
162
163 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
164
165 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
166 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp);
167
168 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp);
169
170 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp);
171
172 void update_mousepos();
173
174 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
175 float PolyDrawModelSurface(entity e, float i_s);
176 void PolyDrawModel(entity e);
177
178 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag);
179
180 const int MAX_ACCURACY_LEVELS = 10;
181 float acc_lev[MAX_ACCURACY_LEVELS];
182 vector acc_col[MAX_ACCURACY_LEVELS];
183 float acc_col_loadtime;
184 int acc_levels;
185 string acc_color_levels;
186 void Accuracy_LoadLevels();
187
188 void Accuracy_LoadColors();
189
190 vector Accuracy_GetColor(float accuracy);