]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qh
Merge branch 'master' into terencehill/dynamic_hud
[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 : ((s).health <= 0))
38
39
40 // decolorizes and team colors the player name when needed
41 string playername(string thename, float teamid);
42
43 float cvar_or(string cv, float v);
44
45 vector project_3d_to_2d(vector vec);
46
47 vector drawfontscale;
48 #define draw_beginBoldFont()    MACRO_BEGIN { drawfont = FONT_USER + 2; } MACRO_END
49 #define draw_endBoldFont()      MACRO_BEGIN { drawfont = FONT_USER + 1; } MACRO_END
50
51 float expandingbox_sizefactor_from_fadelerp(float fadelerp);
52
53 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor);
54
55 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag);
56
57 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag);
58
59 void HUD_Scale_Disable();
60 void HUD_Scale_Enable();
61
62 #define HUD_ScaleX(f) (f * hud_scale.x)
63 #define HUD_ScaleY(f) (f * hud_scale.y)
64 #define HUD_ShiftX(f) (f + hud_shift.x + hud_shift.z * (f - hud_scale_center.x))
65 #define HUD_ShiftY(f) (f + hud_shift.y + hud_shift.z * (f - hud_scale_center.y))
66 vector HUD_Scale(vector v);
67 vector HUD_Shift(vector v);
68
69 // call draw*_builtin (and stringwidth_builtin) functions only when
70 // pos and size don't have to be scaled by the hud_dynamic code
71 // (typically outside the real HUD code)
72
73 // NOTE: drawsubpic usually gets called multiple times within an utility function
74 // so instead of remapping it, scaling pos and size in every call,
75 // we prefer to scale pos and size once for all in the utility function
76
77 float stringwidth(string text, float handleColors, vector sz);
78
79 #define drawpic(position, pic, size, rgb, alpha, flag) \
80         drawpic_builtin(HUD_Shift(position), pic, HUD_Scale(size), rgb, alpha, flag)
81
82 #define drawcharacter(position, character, scale, rgb, alpha, flag) \
83         drawcharacter_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
84
85 #define drawstring(position, text, scale, rgb, alpha, flag) \
86         drawstring_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
87
88 #define drawcolorcodedstring(position, text, scale, alpha, flag) \
89         drawcolorcodedstring_builtin(HUD_Shift(position), text, scale, alpha, flag)
90
91 #define drawcolorcodedstring2(position, text, scale, rgb, alpha, flag) \
92         drawcolorcodedstring2_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
93
94 #define drawfill(position, size, rgb, alpha, flag) \
95         drawfill_builtin(HUD_Shift(position), HUD_Scale(size), rgb, alpha, flag)
96
97 #define drawsetcliparea(xposition, yposition, w, h) \
98         drawsetcliparea_builtin(HUD_ShiftX(xposition), HUD_ShiftY(yposition), HUD_ScaleX(w), HUD_ScaleY(h))
99
100 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
101 float _drawpic_imgaspect;
102 vector _drawpic_imgsize;
103 vector _drawpic_sz;
104 float _drawpic_oldsz;
105 string _drawpic_picpath;
106 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
107         MACRO_BEGIN {\
108                 _drawpic_imgsize = draw_getimagesize(pic);\
109                 if(_drawpic_imgsize != '0 0 0') {\
110                         _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
111                         _drawpic_sz = mySize;\
112                         if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
113                                 _drawpic_oldsz = _drawpic_sz.x;\
114                                 _drawpic_sz.x = _drawpic_sz.y * _drawpic_imgaspect;\
115                                 if(_drawpic_sz.x)\
116                                         drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
117                         } else {\
118                                 _drawpic_oldsz = _drawpic_sz.y;\
119                                 _drawpic_sz.y = _drawpic_sz.x / _drawpic_imgaspect;\
120                                 if(_drawpic_sz.y)\
121                                         drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
122                         }\
123                 }\
124         } MACRO_END
125
126 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
127 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
128         MACRO_BEGIN {\
129                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
130                 if(precache_pic(_drawpic_picpath) == "") {\
131                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
132                 }\
133                 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
134                 _drawpic_picpath = string_null;\
135         } MACRO_END
136
137 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
138 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
139         MACRO_BEGIN {\
140                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
141                 if(precache_pic(_drawpic_picpath) == "") {\
142                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
143                 }\
144                 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
145                 _drawpic_picpath = string_null;\
146         } MACRO_END
147
148 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
149
150 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
151
152 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN {                                                                                                                     \
153         float textaspect, oldsz;                                                                                                                                                                                \
154         vector dfs = drawfontscale; \
155         drawfontscale = '1 1 0'; \
156         textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
157         drawfontscale = dfs; \
158         if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
159                 oldsz = sz.x;                                                                                                                                                                                           \
160                 sz.x = sz.y * textaspect;                                                                                                                                                                       \
161                 pos.x += (oldsz - sz.x) * 0.5;                                                                                                                                                          \
162         } else {                                                                                                                                                                                                                \
163                 oldsz = sz.y;                                                                                                                                                                                           \
164                 sz.y = sz.x / textaspect;                                                                                                                                                                       \
165                 pos.y += (oldsz - sz.y) * 0.5;                                                                                                                                                          \
166         }                                                                                                                                                                                                                               \
167 } MACRO_END
168
169 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
170 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag);
171
172 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
173 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag);
174
175 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
176
177 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
178 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp);
179
180 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp);
181
182 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp);
183
184 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
185 float PolyDrawModelSurface(entity e, float i_s);
186 void PolyDrawModel(entity e);
187
188 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag);
189
190 const int MAX_ACCURACY_LEVELS = 10;
191 float acc_lev[MAX_ACCURACY_LEVELS];
192 vector acc_col[MAX_ACCURACY_LEVELS];
193 float acc_col_loadtime;
194 int acc_levels;
195 string acc_color_levels;
196 void Accuracy_LoadLevels();
197
198 void Accuracy_LoadColors();
199
200 vector Accuracy_GetColor(float accuracy);