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