]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/miscfunctions.qh
Merge branch 'master' into Mario/qcphysics
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qh
1 #pragma once
2
3 #include <server/defs.qh>
4 #include <server/g_world.qh>
5
6 #include <common/t_items.qh>
7
8 #include <server/mutators/_mod.qh>
9
10 #include <common/constants.qh>
11 #include <common/mapinfo.qh>
12 #include <common/turrets/all.qh>
13
14 #if 1
15 #define cvar_string_normal builtin_cvar_string
16 #define cvar_normal builtin_cvar
17 #else
18 string cvar_string_normal(string n)
19 {
20         if (!(cvar_type(n) & CVAR_TYPEFLAG_EXISTS))
21                 backtrace(strcat("Attempt to access undefined cvar: ", n));
22         return builtin_cvar_string(n);
23 }
24
25 float cvar_normal(string n)
26 {
27         return stof(cvar_string_normal(n));
28 }
29 #endif
30 #define cvar_set_normal builtin_cvar_set
31
32 .vector dropped_origin;
33
34 entity eliminatedPlayers;
35 void EliminatedPlayers_Init(float(entity) isEliminated_func);
36
37 void write_recordmarker(entity pl, float tstart, float dt);
38
39 void play2all(string samp);
40
41 void play2team(float t, string filename);
42
43 void GetCvars_handleFloat(entity this, entity store, string thisname, float f, .float field, string name);
44
45 float spamsound(entity e, float chan, Sound samp, float vol, float _atten);
46
47 void GetCvars_handleString(entity this, entity store, string thisname, float f, .string field, string name);
48
49 void precache_all_playermodels(string pattern);
50
51 void soundat(entity e, vector o, float chan, string samp, float vol, float _atten);
52
53 void InitializeEntitiesRun();
54
55 void stopsoundto(float _dest, entity e, float chan);
56 void soundtoat(float _dest, entity e, vector o, float chan, string samp, float vol, float _atten);
57
58 void droptofloor(entity this);
59
60 void attach_sameorigin(entity e, entity to, string tag);
61
62 void crosshair_trace(entity pl);
63
64 void crosshair_trace_plusvisibletriggers(entity pl);
65 void WarpZone_crosshair_trace_plusvisibletriggers(entity pl);
66 void crosshair_trace_plusvisibletriggers__is_wz(entity pl, bool is_wz);
67
68 void detach_sameorigin(entity e);
69
70 void follow_sameorigin(entity e, entity to);
71
72 string formatmessage(entity this, string msg);
73
74 /** print(), but only print if the server is not local */
75 void dedicated_print(string input);
76
77 string GameLog_ProcessIP(string s);
78
79 void GameLogEcho(string s);
80
81 void GameLogInit();
82
83 void GameLogClose();
84
85 void GetCvars(entity this, entity store, int f);
86
87 string GetMapname();
88
89 float isPushable(entity e);
90
91 float LostMovetypeFollow(entity ent);
92
93 string uid2name(string myuid);
94
95 bool MoveToRandomLocationWithinBounds(entity e, vector boundmin, vector boundmax, float goodcontents, float badcontents, float badsurfaceflags, int attempts, float maxaboveground, float minviewdistance);
96
97 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance);
98
99 string NearestLocation(vector p);
100
101 void play2(entity e, string filename);
102
103 string playername(entity p, bool team_colorize);
104
105 void precache();
106
107 void remove_safely(entity e);
108
109 void remove_unsafely(entity e);
110
111 void SetMovetypeFollow(entity ent, entity e);
112
113 void soundto(float dest, entity e, float chan, string samp, float vol, float atten);
114
115 void stopsound(entity e, float chan);
116
117 float tracebox_hits_box(vector start, vector mi, vector ma, vector end, vector thmi, vector thma);
118
119 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
120
121 void WarpZone_crosshair_trace(entity pl);
122
123 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag);
124
125 #define IS_DEAD(s) ((s).deadflag != DEAD_NO)
126
127
128 #define ITEM_TOUCH_NEEDKILL() (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
129 #define ITEM_DAMAGE_NEEDKILL(dt) (((dt) == DEATH_HURTTRIGGER.m_id) || ((dt) == DEATH_SLIME.m_id) || ((dt) == DEATH_LAVA.m_id) || ((dt) == DEATH_SWAMP.m_id))
130
131 #define PROJECTILE_TOUCH(e,t) MACRO_BEGIN if (WarpZone_Projectile_Touch(e,t)) return; MACRO_END
132
133 #define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
134
135 // copies a string to a tempstring (so one can strunzone it)
136 string strcat1(string s) = #115; // FRIK_FILE
137
138 float logfile_open;
139 float logfile;
140
141 /*
142 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
143 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
144 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
145 // BE CONSTANT OR strzoneD!
146 float strstrofs(string haystack, string needle, float offset)
147 {
148         float len, endpos;
149         string found;
150         len = strlen(needle);
151         endpos = strlen(haystack) - len;
152         while(offset <= endpos)
153         {
154                 found = substring(haystack, offset, len);
155                 if(found == needle)
156                         return offset;
157                 offset = offset + 1;
158         }
159         return -1;
160 }
161 */
162
163 const float NUM_NEAREST_ENTITIES = 4;
164 entity nearest_entity[NUM_NEAREST_ENTITIES];
165 float nearest_length[NUM_NEAREST_ENTITIES];
166
167
168 //#NO AUTOCVARS START
169
170 float g_pickup_shells_max;
171 float g_pickup_nails_max;
172 float g_pickup_rockets_max;
173 float g_pickup_cells_max;
174 float g_pickup_plasma_max;
175 float g_pickup_fuel_max;
176 float g_pickup_weapons_anyway;
177 float g_weaponarena;
178 WepSet g_weaponarena_weapons;
179 float g_weaponarena_random; // TODO
180 string g_weaponarena_list;
181 float g_weaponspeedfactor;
182 float g_weaponratefactor;
183 float g_weapondamagefactor;
184 float g_weaponforcefactor;
185 float g_weaponspreadfactor;
186
187 WepSet start_weapons;
188 WepSet start_weapons_default;
189 WepSet start_weapons_defaultmask;
190 int start_items;
191 float start_ammo_shells;
192 float start_ammo_nails;
193 float start_ammo_rockets;
194 float start_ammo_cells;
195 float start_ammo_plasma;
196 float start_ammo_fuel;
197 /// \brief Number of random start weapons to give to players.
198 int random_start_weapons_count;
199 /// \brief Holds a list of possible random start weapons.
200 string autocvar_g_random_start_weapons;
201 /// \brief Entity that contains amount of ammo to give with random start
202 /// weapons.
203 entity random_start_ammo;
204 float start_health;
205 float start_armorvalue;
206 WepSet warmup_start_weapons;
207 WepSet warmup_start_weapons_default;
208 WepSet warmup_start_weapons_defaultmask;
209 #define WARMUP_START_WEAPONS ((g_warmup_allguns == 1) ? (warmup_start_weapons & (weaponsInMap | start_weapons)) : warmup_start_weapons)
210 float warmup_start_ammo_shells;
211 float warmup_start_ammo_nails;
212 float warmup_start_ammo_rockets;
213 float warmup_start_ammo_cells;
214 float warmup_start_ammo_plasma;
215 float warmup_start_ammo_fuel;
216 float warmup_start_health;
217 float warmup_start_armorvalue;
218 float g_weapon_stay;
219
220 float want_weapon(entity weaponinfo, float allguns); // WEAPONTODO: what still needs done?
221 void readplayerstartcvars();
222
223 float sv_autotaunt;
224 float sv_taunt;
225
226 void readlevelcvars()
227 {
228         if(cvar("sv_allow_fullbright"))
229                 serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT;
230
231         sv_clones = cvar("sv_clones");
232         sv_foginterval = cvar("sv_foginterval");
233         g_footsteps = cvar("g_footsteps");
234         g_jetpack = cvar("g_jetpack");
235         sv_maxidle = cvar("sv_maxidle");
236         sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle");
237         sv_maxidle_slots = cvar("sv_maxidle_slots");
238         sv_maxidle_slots_countbots = cvar("sv_maxidle_slots_countbots");
239         sv_autotaunt = cvar("sv_autotaunt");
240         sv_taunt = cvar("sv_taunt");
241         sv_ready_restart = cvar("sv_ready_restart");
242         sv_ready_restart_after_countdown = cvar("sv_ready_restart_after_countdown");
243         sv_ready_restart_repeatable = cvar("sv_ready_restart_repeatable");
244
245         warmup_stage = cvar("g_warmup");
246         warmup_limit = cvar("g_warmup_limit");
247         g_warmup_allguns = cvar("g_warmup_allguns");
248         g_warmup_allow_timeout = cvar("g_warmup_allow_timeout");
249
250         if(cvar("g_campaign"))
251                 warmup_stage = 0; // no warmup during campaign
252
253         g_pickup_respawntime_weapon = cvar("g_pickup_respawntime_weapon");
254         g_pickup_respawntime_superweapon = cvar("g_pickup_respawntime_superweapon");
255         g_pickup_respawntime_ammo = cvar("g_pickup_respawntime_ammo");
256         g_pickup_respawntime_short = cvar("g_pickup_respawntime_short");
257         g_pickup_respawntime_medium = cvar("g_pickup_respawntime_medium");
258         g_pickup_respawntime_long = cvar("g_pickup_respawntime_long");
259         g_pickup_respawntime_powerup = cvar("g_pickup_respawntime_powerup");
260         g_pickup_respawntimejitter_weapon = cvar("g_pickup_respawntimejitter_weapon");
261         g_pickup_respawntimejitter_superweapon = cvar("g_pickup_respawntimejitter_superweapon");
262         g_pickup_respawntimejitter_ammo = cvar("g_pickup_respawntimejitter_ammo");
263         g_pickup_respawntimejitter_short = cvar("g_pickup_respawntimejitter_short");
264         g_pickup_respawntimejitter_medium = cvar("g_pickup_respawntimejitter_medium");
265         g_pickup_respawntimejitter_long = cvar("g_pickup_respawntimejitter_long");
266         g_pickup_respawntimejitter_powerup = cvar("g_pickup_respawntimejitter_powerup");
267
268         g_weaponspeedfactor = cvar("g_weaponspeedfactor");
269         g_weaponratefactor = cvar("g_weaponratefactor");
270         g_weapondamagefactor = cvar("g_weapondamagefactor");
271         g_weaponforcefactor = cvar("g_weaponforcefactor");
272         g_weaponspreadfactor = cvar("g_weaponspreadfactor");
273
274         g_pickup_shells = cvar("g_pickup_shells");
275         g_pickup_shells_max = cvar("g_pickup_shells_max");
276         g_pickup_nails = cvar("g_pickup_nails");
277         g_pickup_nails_max = cvar("g_pickup_nails_max");
278         g_pickup_rockets = cvar("g_pickup_rockets");
279         g_pickup_rockets_max = cvar("g_pickup_rockets_max");
280         g_pickup_cells = cvar("g_pickup_cells");
281         g_pickup_cells_max = cvar("g_pickup_cells_max");
282         g_pickup_plasma = cvar("g_pickup_plasma");
283         g_pickup_plasma_max = cvar("g_pickup_plasma_max");
284         g_pickup_fuel = cvar("g_pickup_fuel");
285         g_pickup_fuel_jetpack = cvar("g_pickup_fuel_jetpack");
286         g_pickup_fuel_max = cvar("g_pickup_fuel_max");
287         g_pickup_armorsmall = cvar("g_pickup_armorsmall");
288         g_pickup_armorsmall_max = cvar("g_pickup_armorsmall_max");
289         g_pickup_armorsmall_anyway = cvar("g_pickup_armorsmall_anyway");
290         g_pickup_armormedium = cvar("g_pickup_armormedium");
291         g_pickup_armormedium_max = cvar("g_pickup_armormedium_max");
292         g_pickup_armormedium_anyway = cvar("g_pickup_armormedium_anyway");
293         g_pickup_armorbig = cvar("g_pickup_armorbig");
294         g_pickup_armorbig_max = cvar("g_pickup_armorbig_max");
295         g_pickup_armorbig_anyway = cvar("g_pickup_armorbig_anyway");
296         g_pickup_armormega = cvar("g_pickup_armormega");
297         g_pickup_armormega_max = cvar("g_pickup_armormega_max");
298         g_pickup_armormega_anyway = cvar("g_pickup_armormega_anyway");
299         g_pickup_healthsmall = cvar("g_pickup_healthsmall");
300         g_pickup_healthsmall_max = cvar("g_pickup_healthsmall_max");
301         g_pickup_healthsmall_anyway = cvar("g_pickup_healthsmall_anyway");
302         g_pickup_healthmedium = cvar("g_pickup_healthmedium");
303         g_pickup_healthmedium_max = cvar("g_pickup_healthmedium_max");
304         g_pickup_healthmedium_anyway = cvar("g_pickup_healthmedium_anyway");
305         g_pickup_healthbig = cvar("g_pickup_healthbig");
306         g_pickup_healthbig_max = cvar("g_pickup_healthbig_max");
307         g_pickup_healthbig_anyway = cvar("g_pickup_healthbig_anyway");
308         g_pickup_healthmega = cvar("g_pickup_healthmega");
309         g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
310         g_pickup_healthmega_anyway = cvar("g_pickup_healthmega_anyway");
311
312         g_pickup_ammo_anyway = cvar("g_pickup_ammo_anyway");
313         g_pickup_weapons_anyway = cvar("g_pickup_weapons_anyway");
314
315     g_weapon_stay = cvar(strcat("g_", GetGametype(), "_weapon_stay"));
316     if(!g_weapon_stay)
317         g_weapon_stay = cvar("g_weapon_stay");
318
319     MUTATOR_CALLHOOK(ReadLevelCvars);
320
321         if (!warmup_stage)
322                 game_starttime = time + cvar("g_start_delay");
323
324         FOREACH(Weapons, it != WEP_Null, { it.wr_init(it); });
325
326         readplayerstartcvars();
327 }
328
329 //#NO AUTOCVARS END
330
331 const int INITPRIO_FIRST                = 0;
332 const int INITPRIO_GAMETYPE             = 0;
333 const int INITPRIO_GAMETYPE_FALLBACK    = 1;
334 const int INITPRIO_FINDTARGET           = 10;
335 const int INITPRIO_DROPTOFLOOR          = 20;
336 const int INITPRIO_SETLOCATION          = 90;
337 const int INITPRIO_LINKDOORS            = 91;
338 const int INITPRIO_LAST                 = 99;
339
340 .void(entity this) initialize_entity;
341 .int initialize_entity_order;
342 .entity initialize_entity_next;
343 entity initialize_entity_first;
344
345
346
347
348
349 bool sound_allowed(int dest, entity e);
350 void InitializeEntity(entity e, void(entity this) func, int order);
351
352 IntrusiveList g_ctrace_changed;
353 STATIC_INIT(g_ctrace_changed) { g_ctrace_changed = IL_NEW(); }