]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/miscfunctions.qh
Make things slightly less broken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qh
1 #ifndef MISCFUNCTIONS_H
2 #define MISCFUNCTIONS_H
3
4 entity players;
5 entity teams;
6 float team_count; // real teams
7
8 void AuditLists();
9
10 float RegisterPlayer(entity player);
11
12 void RemovePlayer(entity player);
13
14 void MoveToLast(entity e);
15
16 float RegisterTeam(entity Team);
17
18 void RemoveTeam(entity Team);
19
20 entity GetTeam(int Team, bool add);
21
22 vector HUD_GetFontsize(string cvarname);
23
24 float PreviewExists(string name);
25
26 vector rotate(vector v, float a);
27
28 int ColorTranslateMode;
29
30 string ColorTranslateRGB(string s);
31
32 // decolorizes and team colors the player name when needed
33 string playername(string thename, float teamid);
34
35 float cvar_or(string cv, float v);
36
37 vector project_3d_to_2d(vector vec);
38
39 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8);
40
41 float expandingbox_sizefactor_from_fadelerp(float fadelerp);
42
43 vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor);
44
45 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag);
46
47 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag);
48
49 void defer(float fdelay, void() func);
50
51 void defer_clear(entity ent);
52
53 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
54 float _drawpic_imgaspect;
55 vector _drawpic_imgsize;
56 vector _drawpic_sz;
57 float _drawpic_oldsz;
58 string _drawpic_picpath;
59 #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\
60         do {\
61                 _drawpic_imgsize = draw_getimagesize(pic);\
62                 if(_drawpic_imgsize != '0 0 0') {\
63                         _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\
64                         _drawpic_sz = mySize;\
65                         if(_drawpic_sz.x/_drawpic_sz.y > _drawpic_imgaspect) {\
66                                 _drawpic_oldsz = _drawpic_sz.x;\
67                                 _drawpic_sz.x = _drawpic_sz.y * _drawpic_imgaspect;\
68                                 if(_drawpic_sz.x)\
69                                         drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
70                         } else {\
71                                 _drawpic_oldsz = _drawpic_sz.y;\
72                                 _drawpic_sz.y = _drawpic_sz.x / _drawpic_imgaspect;\
73                                 if(_drawpic_sz.y)\
74                                         drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\
75                         }\
76                 }\
77         } while(0)
78
79 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
80 #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\
81         do{\
82                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
83                 if(precache_pic(_drawpic_picpath) == "") {\
84                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
85                 }\
86                 drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
87                 _drawpic_picpath = string_null;\
88         } while(0)
89
90 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
91 #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\
92         do{\
93                 _drawpic_picpath = strcat(hud_skin_path, "/", pic);\
94                 if(precache_pic(_drawpic_picpath) == "") {\
95                         _drawpic_picpath = strcat("gfx/hud/default/", pic);\
96                 }\
97                 drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\
98                 _drawpic_picpath = string_null;\
99         } while(0)
100
101 void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
102
103 void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
104
105 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do {                                                                                                                                      \
106         float textaspect, oldsz;                                                                                                                                                                                \
107         textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
108         if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
109                 oldsz = sz.x;                                                                                                                                                                                           \
110                 sz.x = sz.y * textaspect;                                                                                                                                                                       \
111                 pos.x += (oldsz - sz.x) * 0.5;                                                                                                                                                          \
112         } else {                                                                                                                                                                                                                \
113                 oldsz = sz.y;                                                                                                                                                                                           \
114                 sz.y = sz.x / textaspect;                                                                                                                                                                       \
115                 pos.y += (oldsz - sz.y) * 0.5;                                                                                                                                                          \
116         }                                                                                                                                                                                                                               \
117 } while(0)
118
119 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
120 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag);
121
122 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
123 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag);
124
125 vector drawfontscale;
126 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
127
128 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
129 void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp);
130
131 void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp);
132
133 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp);
134
135 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...
136 float PolyDrawModelSurface(entity e, float i_s);
137 void PolyDrawModel(entity e);
138
139 void DrawCircleClippedPic(vector centre, float radius, string pic, float f, vector rgb, float a, float drawflag);
140
141 const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map
142 vector getplayerorigin(int pl);
143
144 float getplayeralpha(float pl);
145
146 vector getcsqcplayercolor(float pl);
147
148 float getplayerisdead(float pl);
149
150 void URI_Get_Callback(int id, float status, string data);
151
152 void draw_beginBoldFont();
153
154 void draw_endBoldFont();
155
156
157 const int MAX_ACCURACY_LEVELS = 10;
158 float acc_lev[MAX_ACCURACY_LEVELS];
159 vector acc_col[MAX_ACCURACY_LEVELS];
160 float acc_col_loadtime;
161 int acc_levels;
162 string acc_color_levels;
163 void Accuracy_LoadLevels();
164
165 void Accuracy_LoadColors();
166
167 vector Accuracy_GetColor(float accuracy);
168
169 #endif