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