]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qh
Merge branch 'master' into terencehill/hud_fixes
[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 #define draw_beginBoldFont()    MACRO_BEGIN { drawfont = FONT_USER + 2; } MACRO_END
48 #define draw_endBoldFont()      MACRO_BEGIN { drawfont = FONT_USER + 1; } MACRO_END
49
50 float expandingbox_sizefactor_from_fadelerp(float fadelerp);
51
52 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor);
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 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
59 float _drawpic_imgaspect;
60 vector _drawpic_imgsize;
61 vector _drawpic_sz;
62 float _drawpic_oldsz;
63 string _drawpic_picpath;
64 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
65         MACRO_BEGIN {\
66                 _drawpic_imgsize = draw_getimagesize(pic);\
67                 if(_drawpic_imgsize != '0 0 0') {\
68                         _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
69                         _drawpic_sz = mySize;\
70                         if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
71                                 _drawpic_oldsz = _drawpic_sz.x;\
72                                 _drawpic_sz.x = _drawpic_sz.y * _drawpic_imgaspect;\
73                                 if(_drawpic_sz.x)\
74                                         drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
75                         } else {\
76                                 _drawpic_oldsz = _drawpic_sz.y;\
77                                 _drawpic_sz.y = _drawpic_sz.x / _drawpic_imgaspect;\
78                                 if(_drawpic_sz.y)\
79                                         drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
80                         }\
81                 }\
82         } MACRO_END
83
84 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
85 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
86         MACRO_BEGIN {\
87                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
88                 if(precache_pic(_drawpic_picpath) == "") {\
89                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
90                 }\
91                 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
92                 _drawpic_picpath = string_null;\
93         } MACRO_END
94
95 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
96 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
97         MACRO_BEGIN {\
98                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
99                 if(precache_pic(_drawpic_picpath) == "") {\
100                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
101                 }\
102                 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
103                 _drawpic_picpath = string_null;\
104         } MACRO_END
105
106 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
107
108 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
109
110 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN {                                                                                                                     \
111         float textaspect, oldsz;                                                                                                                                                                                \
112         textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
113         if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
114                 oldsz = sz.x;                                                                                                                                                                                           \
115                 sz.x = sz.y * textaspect;                                                                                                                                                                       \
116                 pos.x += (oldsz - sz.x) * 0.5;                                                                                                                                                          \
117         } else {                                                                                                                                                                                                                \
118                 oldsz = sz.y;                                                                                                                                                                                           \
119                 sz.y = sz.x / textaspect;                                                                                                                                                                       \
120                 pos.y += (oldsz - sz.y) * 0.5;                                                                                                                                                          \
121         }                                                                                                                                                                                                                               \
122 } MACRO_END
123
124 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
125 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag);
126
127 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
128 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag);
129
130 vector drawfontscale;
131 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
132
133 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
134 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp);
135
136 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp);
137
138 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp);
139
140 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
141 float PolyDrawModelSurface(entity e, float i_s);
142 void PolyDrawModel(entity e);
143
144 void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag);
145
146 const int MAX_ACCURACY_LEVELS = 10;
147 float acc_lev[MAX_ACCURACY_LEVELS];
148 vector acc_col[MAX_ACCURACY_LEVELS];
149 float acc_col_loadtime;
150 int acc_levels;
151 string acc_color_levels;
152 void Accuracy_LoadLevels();
153
154 void Accuracy_LoadColors();
155
156 vector Accuracy_GetColor(float accuracy);